๐จโ๐ป Working on AI platform
Fun Facts
Fing
is my nickname- I used
mtobeiyf
as username which comes from The Hunger Games quote: "May The Odds Be Ever In Your Favor"
:smiley_cat: Pretty & simple image classifier app template. Deploy your own trained model or pre-trained model (VGG, ResNet, Densenet) to a web app using Flask in 10 minutes.
License: Apache License 2.0
Hi,
I want to deploy my object detection using the same approach. First I will upload the original image on click of predict, the model will process and gives me an annotated image. Then i need to upload it the webpage next to the original image.
I have all the required python code. Can you help me how/what changes i need to do in HTML or js file?
Hello. Thanks for great repository.
There is an issue when I containerized the Flask application. When I run docker build command, it simply builds and creates an image but when I run the docker image as a container it's stuck in the line which it tries to download default Keras ResNet50 model.
and so localhost:5000 is not answering. I have modified the docker file like follows:
FROM ubuntu:latest
RUN apt-get update -y && apt-get install -y python python-dev python-pip python-virtualenv build-essential && rm -rf /var/lib/apt/lists/
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]*
afshan@afshan-VirtualBox:~/keras-flask-deploy-webapp$ python3 app.py
/usr/local/lib/python3.5/dist-packages/h5py/init.py:36: FutureWarning: Conversion of the second argument of issubdtype from float
to np.floating
is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type
.
from ._conv import register_converters as _register_converters
Using TensorFlow backend.
Traceback (most recent call last):
File "app.py", line 27, in
model = load_model(MODEL_PATH)
File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 268, in load_model
raise ValueError('No model found in config file.')
ValueError: No model found in config file.
I am getting error ValueError: No model found in config file when I pass save.h5 file to FILE_PATH.
Any one can help??
Hi I tried your project and I liked it ;)
I tried also to change another .h5 file to create only a binary classification (dogs vs cats) but uncommenting the lines of the code to do it and putting my.h5 in the model folder, I have different problems. Can you explain me which should be the features to create a .h5 file to work on it ?
For example I tried to used this .h5 file (https://drive.google.com/open?id=19yICdtSbU_YkQBRxJ2if9KJwUL1oY5xs) from this tutorial (https://deeplizard.com/learn/video/XgzxH6G-ufA) to create only a binary classification.
Can you explain me how to re-edit it to work with this tutorial?
Thanks in advance and let me know.
I really appreciate your project ๐๐ป
Thank you for your quick responses and all the edits done today! I have tried new docker right now, but the problem is it quits just after the start. I tried building docker both with model in folder Models (exactly I used h5 model from teachable machine by google) and without it, but nevertheless - simply exits. As for local install:
Traceback (most recent call last):
File "app.py", line 5, in <module>
from flask import Flask, redirect, url_for, request, render_template, Response, jsonify, redirect
ImportError: No module named flask
Even though it is installed within requirements.txt
as python 2 will be depreciating in 2019 . Its good to have a updated system.
Hi @mtobeiyf ,
I wanted to ask, why was there a need to save images in the uploads folder?
Also, I think it would be better to specify the path to the model and categories file (with delimeter if needed) rather than changing in the source code file.
I would be happy to send a PR towards these issues if needed.
File "/home/anaconda3/envs/tf12/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 645, in load_weights_from_hdf5_group
original_keras_version = f.attrs['keras_version'].decode('utf8')
hi,
When I run the app, I got the error as below,
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\ProgramData\Anaconda3\lib\site-packages\flask_compat.py", line 35, in reraise
raise value
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\download\keras-flask-deploy-webapp-master\app.py", line 75, in upload
preds = model_predict(file_path, model)
File "C:\download\keras-flask-deploy-webapp-master\app.py", line 52, in model_predict
preds = model.predict(x)
File "C:\download\keras-flask-deploy-webapp-master\venv\lib\site-packages\keras\engine\training.py", line 1164, in predict
self._make_predict_function()
File "C:\download\keras-flask-deploy-webapp-master\venv\lib\site-packages\keras\engine\training.py", line 554, in _make_predict_function
**kwargs)
File "C:\download\keras-flask-deploy-webapp-master\venv\lib\site-packages\keras\backend\tensorflow_backend.py", line 2744, in function
return Function(inputs, outputs, updates=updates, **kwargs)
File "C:\download\keras-flask-deploy-webapp-master\venv\lib\site-packages\keras\backend\tensorflow_backend.py", line 2546, in init
with tf.control_dependencies(self.outputs):
File "C:\download\keras-flask-deploy-webapp-master\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 5004, in control_dependencies
return get_default_graph().control_dependencies(control_inputs)
File "C:\download\keras-flask-deploy-webapp-master\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 4543, in control_dependencies
c = self.as_graph_element(c)
File "C:\download\keras-flask-deploy-webapp-master\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 3490, in as_graph_element
return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
File "C:\download\keras-flask-deploy-webapp-master\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 3569, in _as_graph_element_locked
raise ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("fc1000/Softmax:0", shape=(?, 1000), dtype=float32) is not an element of this graph.
ValueError: decode_predictions
expects a batch of predictions (i.e. a 2D array of shape (samples, 1000)). Found array with shape: (1, 2)
172.17.0.1 - - [2020-10-05 15:30:02] "POST /predict HTTP/1.1" 500 411 0.227771
Please I need help, once I run the docker build with my model I just get a 500 error them the terminal trows back this error above.
Abandon support for Python 2
Switch the demo to TensorFlow 2.0
MODEL_PATH = '/home/ljs/keras-flask-deploy-webapp/models/densenet121.h5'
File "/home/ljs/anaconda3/envs/zk/lib/python3.7/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 175, in load_model_from_hdf5
raise ValueError('No model found in config file.')
when I plan to use a downloaded keras model, above problem occurred, please help me.
Hi,
FYI, after selected image and click predict, no prediction results after waiting for 1 minute, found error below.
raise ImportError('Could not import PIL.Image. '
ImportError: Could not import PIL.Image. The use of load_img requires PIL.
solution
apt-get install python-pillow
reference python-pillow/Pillow#3088
my env
ubuntu18.04
python 3.5 <- same error after "apt-get install python-pillow"
python 3.6 <- error solved after "apt-get install python-pillow"
test solution
test with Python 3.6.8 (default, Aug 20 2019, 17:12:48) [GCC 8.3.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> from PIL import Image as pil_image
Is there options to run DL with GPU here? I use docker run --rm --gpus all nvidia/cuda nvidia-smi from https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/user-guide.html but this does not seem to work: it does not use GPU at all, instead, it is using CPU and it is very slow.
Has anybody come an issue deploying a custom model (h5 or saved_model format) and receiving the following when trying to load the model using tf.keras.models.load_model:
radiographyml | 17:42:33 Traceback (most recent call last): radiographyml | 17:42:33 File "app.py", line 53, in <module> radiographyml | 17:42:33 model = load_model(MODEL_PATH) radiographyml | 17:42:33 File "/usr/local/lib/python3.7/site-packages/tensorflow/python/keras/saving/save.py", line 186, in load_model radiographyml | 17:42:33 loader_impl.parse_saved_model(filepath) radiographyml | 17:42:33 File "/usr/local/lib/python3.7/site-packages/tensorflow/python/saved_model/loader_impl.py", line 113, in parse_saved_model radiographyml | 17:42:33 constants.SAVED_MODEL_FILENAME_PB)) radiographyml | 17:42:33 OSError: SavedModel file does not exist at: ./models/my_model.h5/{saved_model.pbtxt|saved_model.pb}
The model is quite big, and I'm using git lfs to upload it to github. The repo is synced to Digital Ocean and refreshes each time a new commit is made. I've been stuck for a while here, trying different models, versions of TF, python, filepaths etc etc
Hello ,
Can you please make a tutorial of object detection problem ??
When I run my own model,which is not a ResNet or other classical model, I follow the comment code to change the model path and load my model, I get the error as follow,ValueError: decode_predictions
expects a batch of predictions (i.e. a 2D array of shape (samples, 1000)). Found array with shape: (1, 1)),what should I do to deal with this issue?
Hi @mtobeiyf ,
While using my own trained model, I am facing this issue:
runfile('C:/Users/Singhkri/Videos/keras-flask-deploy-webapp-master/app.py', wdir='C:/Users/Singhkri/Videos/keras-flask-deploy-webapp-master')
Using TensorFlow backend.
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/Singhkri/Videos/keras-flask-deploy-webapp-master/app.py', wdir='C:/Users/Singhkri/Videos/keras-flask-deploy-webapp-master')
File "C:\Users\Singhkri\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\Users\Singhkri\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Singhkri/Videos/keras-flask-deploy-webapp-master/app.py", line 17, in
model = load_model('models/model.h5')
File "C:\Users\Singhkri\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\engine\saving.py", line 419, in load_model
model = _deserialize_model(f, custom_objects, compile)
File "C:\Users\Singhkri\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\engine\saving.py", line 221, in _deserialize_model
model_config = f['model_config']
File "C:\Users\Singhkri\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\utils\io_utils.py", line 302, in getitem
raise ValueError('Cannot create group in read only mode.')
ValueError: Cannot create group in read only mode.
It would be helpful if you can help in sorting out this.
it is OK to load a trained model now, but another problem happens, I used the same conda environment to deploy the project. dont know how to solve..
File "/home/ljs/anaconda3/envs/zk/lib/python3.7/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 792, in validate_kwargs
raise TypeError(error_message, kwarg)
TypeError: ('Keyword argument not understood:', 'keep_dim')
I've been struggling for hours trying to get this sample to build and run.
Docker container works great, and let's me easily see what this program does. In fact I can shell into the running docker container and verify the python/pip setup, as well as the tooling listed in the requirements.txt. I can verify that the docker container is using python 3.6.12 and pip 21.0.1
I did a whole lot of testing, and unless I had python 3.6.12 AND pip 21.0.1 I could not get a pass on pip install -r requirements.txt
Consider this an issue raised. You absolutely have to have Python version 3.6.12 and pip version 21.0.1 to successfully reproduce this sample. Can I recommend that info be added to the coversheet README.md file? In fact, that might be a good action to take to close this open issue.
Note: I used pyenv for managing the python versions... After bringing Python to 3.6.12 I then had to $ pip install --upgrade pip
(which brought pip from 18.1 to 21.0.1)
Many thanks for sharing this repo. You've helped me a whole lot understand classification within python
Hello, thank you for your great job! The problem I have is I can't run this project. I use Docker but each time get this error:
Traceback (most recent call last):
File "app.py", line 7, in <module>
from gevent.pywsgi import WSGIServer
File "/usr/local/lib/python3.6/dist-packages/gevent/__init__.py", line 87, in <module>
from gevent._hub_local import get_hub
File "/usr/local/lib/python3.6/dist-packages/gevent/_hub_local.py", line 101, in <module>
import_c_accel(globals(), 'gevent.__hub_local')
File "/usr/local/lib/python3.6/dist-packages/gevent/_util.py", line 105, in import_c_accel
mod = importlib.import_module(cname)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "src/gevent/__greenlet_primitives.pxd", line 12, in init gevent.__hub_local
ValueError: greenlet.greenlet size changed, may indicate binary incompatibility. Expected 128 from C header, got 40 from PyObject
I was trying to update gevent, I have the latest version of greenlet.
I also tried local installm but seem to get the same problems at first, that's why switched to Docker as usually it is much easier to run.
What do I have to do? Thank you!
May be this is an issue with tensorflow version. Since requirements.txt does not define the tensorflow version, it's installing latest version and latest version needs -
from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2
Hi,
I'm using this repository for a segmentation based web-app and I was wondering if there was a way to display the output image from the neural network as opposed to json/text data?
Thanks!
I had loaded my own model as mentioned by you. While my training I had resized images with 28*28.
I have changed this img size in your app.py also but now I am getting error as mentioned below:
"ValueError: Error when checking input: expected conv2d_1_input to have shape (28, 28, 3) but got array with shape (28, 28, 4)"
Can you please tell me how can I convert 28,28,4 to 28,28,3 so that I could get predictions as per my model ?
I'm getting
ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (224, 224, 3)
after clicking 'Predict' using my own model trained with Keras.
Attached is the model.h5 if anyone is interested in trying it out.
Tensorflow: 1.12.0
Keras: 2.2.4
Python: 3.5.2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.