Giter VIP home page Giter VIP logo

Comments (5)

Sergio-Badanin avatar Sergio-Badanin commented on June 27, 2024

Забыл сказать, что если запускаю просто код "Hello World", то все нормально проходит и распознавание отрабатывается.

from nomeroff-net.

GalymzhanAbdimanap avatar GalymzhanAbdimanap commented on June 27, 2024

@Sergio-Badanin
передавайте graph = tf.get_default_graph() когда вызываете функций распознавании, а в функциях распознавания добавьте
def function_recognition(): with graph.as_default(): #operations of function
попробуйте так и отпишитесь если работает

from nomeroff-net.

Sergio-Badanin avatar Sergio-Badanin commented on June 27, 2024

Поставил после img = mpimg.imread(imgPath):

@app.route("/", methods=["POST", "GET"])
def index():
    if request.method == "POST":
        file = request.files["file"]
        if file and (file.content_type.rsplit('/', 1)[1] in ALLOWED_EXTENSIONS).__bool__():
            filename = secure_filename(file.filename)
            file.save(NOMEROFF_NET_DIR + '/examples/images/' + filename)
            imgPath = (NOMEROFF_NET_DIR + '/examples/images/' +  filename)
            img = mpimg.imread(imgPath)
            graph = tf.get_default_graph()
            NP = nnet.detect([img])
            cv_img_masks = filters.cv_img_mask(NP)
            arrPoints = rectDetector.detect(cv_img_masks)
            zones = rectDetector.get_cv_zonesBGR(img, arrPoints)
            regionIds, stateIds, countLines = optionsDetector.predict(zones)
            regionNames = optionsDetector.getRegionLabels(regionIds)
            textArr = textDetector.predict(zones)
            textArr = textPostprocessing(textArr, regionNames)
            print(textArr)
    return render_template("index.html")

Выдает ошибку:

[2020-03-04 12:27:13,016] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/src/nomeroff-net/examples/py/site.py", line 52, in index
    graph = tf.get_default_graph()
NameError: name 'tf' is not defined

from nomeroff-net.

GalymzhanAbdimanap avatar GalymzhanAbdimanap commented on June 27, 2024

это на верху где импорты

import tensorflow as tf

graph = tf.get_default_graph()

`

и снизу где def index

`with graph.as_default():

   NP = nnet.detect([img])
   cv_img_masks = filters.cv_img_mask(NP)

.....`

from nomeroff-net.

Sergio-Badanin avatar Sergio-Badanin commented on June 27, 2024

@GalymzhanAbdimanap , премного благодарен!

Заработало в таком варианте:

import os
import numpy as np
import sys
import matplotlib.image as mpimg
import tensorflow as tf
import warnings

graph = tf.get_default_graph()

warnings.filterwarnings('ignore')
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
NOMEROFF_NET_DIR = os.path.abspath('../../')
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}

MASK_RCNN_DIR = os.path.join(NOMEROFF_NET_DIR, 'Mask_RCNN')
MASK_RCNN_LOG_DIR = os.path.join(NOMEROFF_NET_DIR, 'logs')

sys.path.append(NOMEROFF_NET_DIR)

from flask import Flask, render_template, request, url_for
from werkzeug.utils import secure_filename
from NomeroffNet import  filters, RectDetector, TextDetector, OptionsDetector, Detector, textPostprocessing, textPostprocessingAsync

nnet = Detector(MASK_RCNN_DIR, MASK_RCNN_LOG_DIR)
nnet.loadModel("latest")

rectDetector = RectDetector()
optionsDetector = OptionsDetector()
optionsDetector.load("latest")
textDetector = TextDetector.get_static_module("eu")()
textDetector.load("latest")


app = Flask(__name__)


@app.route("/", methods=["POST", "GET"])
def index():
    global graph
    if request.method == "POST":
        file = request.files["file"]
        if file and (file.content_type.rsplit('/', 1)[1] in ALLOWED_EXTENSIONS).__bool__():
            filename = secure_filename(file.filename)
            file.save(NOMEROFF_NET_DIR + '/examples/images/' + filename)
            imgPath = (NOMEROFF_NET_DIR + '/examples/images/' +  filename)
            img = mpimg.imread(imgPath)
            with graph.as_default():
                NP = nnet.detect([img])
                cv_img_masks = filters.cv_img_mask(NP)
                arrPoints = rectDetector.detect(cv_img_masks)
                zones = rectDetector.get_cv_zonesBGR(img, arrPoints)
                regionIds, stateIds, countLines = optionsDetector.predict(zones)
                regionNames = optionsDetector.getRegionLabels(regionIds)
                textArr = textDetector.predict(zones)
                textArr = textPostprocessing(textArr, regionNames)
                print(textArr)
    return render_template("index.html")


if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80)

from nomeroff-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.