-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error on calling detector.detectObjectsFromImage from Flask API method without loading model in the method #531
Comments
this is a known issue, this is threading issue apparently. Even I have the same problem in Django |
thanks for your reponse @chettkulkarni but in another thread at #159, in Dec 2019, they have mentioned that we have a solution keeping threads safe. in the code given in above link, its working fine for them. Why come its not working with my above code.. ?? is it dependant on the libraries I use .. ?? I m just using basic sample example with keras, opencv n tensorflow libraries only.. Please let me know if you have any further info on this. |
Are you sure? It work fine in my computer. |
Thanks so much for quick response @xiluzi You can check above API response at this link http://95.217.62.99:5000/process And below is my PIP list libraries, I m using.. Please let me know if any library differences is there. If I put 5 or 10 predections in the same API method, it wont take much time to process those extra images. Response time is same as detecting one image. I couldnt understand where I m going wrong. Can you please help me in finding out the cause for this issue. Thanks for your time and effort to help me. |
absl-py==0.7.1 This‘s my lib.But I run it in windows. |
Thanks @xiluzi for your time and effort. I have tried running above code with its model and matching your library versions and on Ubuntu 16.04 OS and still got some errors. You can see the response @ http://95.217.62.99:5000/process. I dont have windows machine to test it on. Please let me know what might be the issue and ways to reduce the loading model duration. Thanks in advance |
Sorry. I don't know what's different between our code and env. The last suggestion I can give you is, maybe you can try to pip uninstall tensorflow-gpu and retry. |
No worries @xiluzi .. Thanks for your time so far.. Can you please do one favor to me to get some clue in this issue. If its still not working the same exact folder, then its issue on my server and I ll try on another server or windows machine. Please help me by sending ur env n other files where it is working for you. Thanks in advance. |
Try to disable threads in Flask app.run(host='0.0.0.0',threaded = False) and it will probably work. |
Hi,
Thanks for amazing library making it easy for image object detection. All works fine when i try to test the object detections.
But when I try to detect objects from Flask API method, it throws me error. I m trying to load the model globally once before starting the Flask server application and trying to get image name from POST data and by giving image name as input, i m trying to get detection,
but I m getting error when trying to detect the objects in image without loading the model again in the post method.
below is the code I m using, please look into it and let me know where is the issue.
import flask
from flask import request, abort, make_response, jsonify
from imageai.Detection.Custom import CustomObjectDetection
import logging
global detector
detector = CustomObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath("invoices/models/detection_model-ex-080--loss-0021.357.h5")
detector.setJsonPath("invoices/json/detection_config.json")
detector.loadModel()
app = flask.Flask(name)
app.config["DEBUG"] = True
logging.basicConfig(level=logging.DEBUG)
@app.route('/predict', methods=['POST'])
def predict():
global detector
if not request.json or not 'file' in request.json:
abort(400)
file = request.json['file']
if name == 'main':
app.run(host='0.0.0.0', threaded=True)
On calling this API, i m getting below error.

If I run the same code by uncommenting, detector.loadModel() just above the detectObjectsFromImage method, then it works fine but I dont want to load the model everytime an API is called.
Please help me in understanding the issue and clarify it.
Thanks in advance and thanks for your great effort so far..
The text was updated successfully, but these errors were encountered: