Deep Learning in Django || (Image Classification) || Complete tutorial 2020
ฝัง
- เผยแพร่เมื่อ 20 ก.ย. 2024
- #django #deeplearning #imageclassification
In this video I will show how to support deep learning models in Django, very specific image classification keras based model.
00:05 Description of the Problem statement
01:38 Demo of the sample web app
02:28 Pre-trained model from Keras using the notebook
05:10 Scoring an image in notebook
06:40 Creating the Django project
11:56 Form for the Image upload in django
15:47 Saving the file uploaded in Django
18:56 Setting Media folder in Django app
23:54 Hosting images in Django app
26:34 Deploying Deep learning model in Django app
30:11 Scoring an image in Django app
34:53 For loop in Django Template
37:35 FileSTorageSystem in Django
38:00 Summary of the video
The course material is in github repo:
github.com/sha...
Req.txt file available at same repo now:
github.com/sha...
Please subscribe to my channel by clicking on the link: / @technologyfornoobs
This video was really useful for me, I successfully made my first web application for my neural network, not sure how accurate it is but I am happy I made something myself, I used your code and edited it according to my requirements. I am really glad I found this channel. Thank you for posting such valuable content for free.
Glad it helped!
what a heck tutorial i had been looking!!!! thanks so much for this best tutorial
Glad it was helpful!
@@technologyfornoobs my project can't read file .h5
Your video really helped me to integrate my project with Django!!! Thanks dude...!!!
Glad it was helpful for you!
Realy this video was very useful for me thank you so much.
Glad it was helpful!
I like the tutorial, help me a lot, thanks!
You're welcome!
Tensor Tensor("act_softmax/Softmax:0", shape=(None, 1000), dtype=float32) is not an element of this graph. why it's showing me
Amazing job! eres team dandy de corazón. Gracias
Thanks!
Excellent,
Awesome. thank u so much.
Most welcome 😊
Thank you so much!
You're welcome!
I m having some error can you help me out i am having FILE NOT FOUND ERROR
File not found, you just need to check the path of the file.
urlpatterns+=static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
hey you said we use this only in development right, then what to do incase of deploying to heroku ???
if trial purpose then stick to it, if heavy lifting it will be done via webserver like nginx
Thanks
Welcome
great job
Thanks!
sir can you create one more video on deployment of image based Machine Learning/Deep Learning Model without label/Json File using Django.... if any link please share sir
you have little confusion here, without label you cannot train supervised model.
@@technologyfornoobs Sir can you execute and upload one more video on deep learning on below topic, you video really help us alot
Dataset : www.kaggle.com/paultimothymooney/chest-xray-pneumonia
Hi. I already have my cnn model created from scratch and saved in a .h5 file. Can I use this tutorial with my model file instead? Will it work the same way?
Yes, you can, would be exactly same
FailedPreconditionError at /predict
Error while reading resource variable dense_1/bias from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/dense_1/bias)
[[{{node dense_1/BiasAdd/ReadVariableOp}}]]
why this error happens, when i called predict function
are you following the same or you are using your own model? and also confirm you are using same version of packages as I am using,
@@technologyfornoobs bro i am in different project, but the steps are almost same so i referred your project, anyway that problem is resolved
your video was really helpful, can you tell how do I deploy this project?
check about Gunicorn and Nginx with Django
im doing a similar web app but couldn't figure out how to upload multiple images for classification and then display them as a set of result using django. is it possible to do this without implementing a database? can you point me to some resources
actually, this is just a JS functionality which you need to implement in UI, upload multiple files, and UI will call the function individually for each file.
why are you using tensorflow 1 :(
I just used it that time.
your video is very much helpful! i have one question regarding this project. Are you doing anything for the async functionality? I mean, for your predicting process to run each time you get a new input image from the web site, how is the views.py dealing with that? Thanks!
Nothing for the async, simple request response
@@technologyfornoobs ohhh i get it. Can i also implement it with the class type views?
@@technologyfornoobs i mean the immediate response. I am running a function within a class but the function only runs once
@@ophelie3147 yes, there is a video in my channel which shows how to use functions defined within class as well
@@technologyfornoobs thanks ill look up for it :)
Sir using this code can we make the image captioning project? By changing the model?
yes, but you need to adjust the response from the model
@@technologyfornoobs ty sir
fileObj=request.FILES['filePath']
fs=FileSystemStorage()
filePathName=fs.save(fileObj.name,fileObj)
filePathName=fs.url(filePathName)
this is not working i don't know why I have written it same but none type object is retuned ...please help
1. There must be some mistake in the form, could you check if your has "name"=filePath in input field.
2. or if you can git clone the repo you can match the error.
3. or better use debugger and identify the error, this could be good way of learning
What tensorflow and keras version are you using?
Keras 2.2.4
Tensorflow 1.13.1
@@technologyfornoobs It would be much better if you could provide us the `requirements.txt` file.
@@technologyfornoobs How do I install tensor flow?? Through pip ?? I got keras through that but it doesnt have tensor flow!!!
@@luffysatoru106 as it is for now, tensorflow doesn't support python 3.9. However, you can install tensorflow nightly, it will work the same way
@@AlenaShomanova thank you
hello sir,
at 30:50, when i run manage.py, I get an import error saying "ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context'".
please help me with this error. I googled, but didnt get any solution.
Which version of tensorflow you have installed?
I am gettin the error nonetype object has no attribute name
i am doing a project that takes a picture on android mobile app (written in kotlin) and send the image to the server (db) -> then the deep learning model does the image processing -> sends the processed image back to db -> show it on the android app again. do u know if it is plausible? and if so can i use django with the jupyter notebook? i dont have much knowledge with this, so i donno where to start. thanks for reading my comment!
also, if it is implementable, can u please tell me what to use for each steps? i was told to 1) connect django with android 2) connect to mysql 3) try the deep learning model on django (see if it works with django) but coz im a beginner and will take such a long time to see if it even works. It would be a lot of help if u can give me some advice! Thanks a lot :)
I would suggest keep is simple to begin with,
1. Create mobile app
2. create django rest apis which will take an image and returns what you expect, no mysql
your mobile app will call rest api of the django and will get the results.
@@technologyfornoobs yea but i thought i would need a database coz im making a image memo app so there has to be accumulated results of images like a camera gallery? Thanks for ur comment btw!!
Can you tell me How can i do this if I've Pytorch Model
replace the function with pytorch code, I have created an another video with onnx support
@@technologyfornoobs plsss can you share link plsss
No model config found in the file at '.models/resnet50.h5'
why this error showing me ? how can I fix
I think some version mismatch
Sir, What does it means "using tensorflow backend " , when run the server.
keras is using tensorflow backend. ITS BUILT OFF OF TENSORFLOW SO IT SHOWS THAT
@@ShaikAsad Sir, When I run the server, I get the "using tensorflow backend" message only. Didn't get the localhost link. Could you please tell me why it shows so ?
How do i make the set up to use only 2 classes of image from the model?
you either can filter your result from the model or train a new model as usual approach.
@@technologyfornoobs i did the first one :) thank you. But.. i am having some issues with keras and tensorflow like these:
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
I dont know how but i fixxed it at my notebook, but when i am trying to run the projeckt in another machine, installing all packages in a fresh venv, i got this error again, could you help me with that?
I am using older version of tensorflow, you have installed the latest version, if you check the req.txt file you will get the version which I used.
how do i create imagenet_classes.json file for my own dataset?
there are many opensource tools for the same, one app you can find on the imagenet website itself, it can be customized as well you just need to write the code for reading the custom file
Frist we need to see finle project before Start bucouse understand whats you work
That's the flow I have used, showed the demo, its in continuation with my previous Django project of machine learning model
How can i deploy this application on heroku
follow the heroku documentation.
bro i cant open my image, file not found eror ,No such file or directory: '/media/doctor_c9c8PlK.jpg', how to resolve this. but i have the uploaded image in media folder
you are missing "." in your path
@@technologyfornoobs i follwed django docs, u mean./media
@@ronyjoseph7868 yes
@@technologyfornoobs k i will check
@@technologyfornoobs bro again its error, can u share your whatsapp number, i completed my project 90%, i am stuck here,
Hello sir, I have created image classification code in matlab can we use that in django? If yes how can we run that code from django
Not sure if there is any library which has exporter and load back model feature for python
@@technologyfornoobs ok thanks for replying ☺
can we use the same code in a bert model for sentiment analysis? and the model will also be .h5 or .pb ?
Nope, yo would need to edit the processing of data part in the code.
@@technologyfornoobs any idea how ?
The same way you process it in any development env like notebook or any ide, same way you need to process the data for your Bert model
Can we apply the css and bootstrap for the better UI?
yes
i have my model weights in h5 file.. using this video i was not able to load .. Any ideas??? i have tflite file also can u guide me to load that tflite file instead
line 181, in load_model_from_hdf5
raise ValueError('No model found in config file.')
ValueError: No model found in config file.
this was the error
I do not have much exp with tflite format files, and I cannot check it as well immediately. but you just have to use the function which helps in loading the tflite file.
Sir, When I run the server, I get the "using tensorflow backend" message only. Didn't get the localhost link. Could you please tell me why it shows so ?
Which python version you are using, my video was based on python version 3.6.8, if you are using latest version of python then you need to check the compatibility of all the packages, start from here and it might get solved as well.
@@technologyfornoobs I'm using python 3.7.3 and django - 3.0.7. The problem is that, Python3 manage.py runserver - shows the output as "using tensorflow backend" with no error messages.
understood the question, just try it in python 3.6.8 version instead 3.7.3, try creating a virtual env and use that env to run your django app.
from keras.models import load_model
ImportError: No module named keras.models
i got this error
im using keras 2.4.3
tensorflow 1.15
It must have moved somewhere else
Check it in their doc of keras
thank you sir..i am doing facial recognition with data mining in python django , for my research project for my undergraduate degree in software engineering. any help would be greatly appreciated
what kind of help?
@@technologyfornoobs Can I have your email so that I can communicate with you
@@allonstafadzwamazani1771 techfornoobs01@gmail.com
Please can you help in explaining what this line of code is doing
with open('imagenet_classes.json','r') as f:
labelInfo=f.read()
I'm trying to use other keras models, such as VGG19 but I can implement them... It's returning something else...
the line is reading a file which has all the classes of imagenet data, that is what I am using to give names as a ouptut in the app. if its a pretrained model you can still use it, if not its not helpful for you
@@technologyfornoobs how to do that with another dataset ?
I follow along your video but this "testimage='.'+filePathName" is not woking
it show me this error
"[Errno 2] No such file or directory: './media/image%20(1)_OFcUdOq.JPG'
"
please help
Can you try pulling the git app and run and check what's diff between the code, as i can see the file name is incorrect in your error message. %20 comes with the request but actually its a space in reality.
I am having same problem
No such file or directory
can i get the requirements.txt file, i am not able run this project
Added the req.txt file github.com/sharmasw/ImageClassification_DjangoApp.git
at 10.08 I am getting error serve not reached , can you tell me how I can resolve this?
Is your app running?
@@technologyfornoobsYes
İ created a ML model using Google Colab... İ want to deploy it in django.... Is that will be the same in the Video ???!
Yes download the model file in your system , and follow as in video
@@technologyfornoobs I downloaded the model with( ipynb) extension, will that work? Also I want the result of prediction to be saved, instead of saving the uploading file
that's the notebook file not the model file. It will not work.
You can save the predictions, that logic needs to be written
@@technologyfornoobs ok how can i get the model file and download it?
can you please guide me how can i make an API of my cnn model which is save in h5 format ?
That's what I have done in the demo project right, the code written in views.py is your logic and endpoint is the url which gets you to the function.
@@technologyfornoobs yup you mentioned in the video like host on nginx or any other web server can you please make a video how to deploy it will be really helpful
I am having this error, can you help me with TypeError: ('Keyword argument not understood:', 'groups')
you need to provide more details, this is not enough to understand the issue.
@@technologyfornoobs thank you, i solved my issue it was technical issue from tf 1 to tf 2.2.
can i do same with music genre classification??
Yes, you can, the same way, get audio as a input do your preprocessing pass it to model and send the classification as a output.
Sir can we do it for lstm also
yes you can.
Sir can we use this code on Google colab?
which code, model generation then yes!
At 26:04 where do I get the .ipynb file .h5 file and the similar .json file from??
It should be in the github repo.
@@technologyfornoobs how to do this file json with another dataset?
bro how do u learn these complex things
All things are easy, it just need some time to get comfortable with it. All the bests !
AttributeError: 'NoneType' object has no attribute 'name'
Check the model parameter, or if you have diff versions of library this could be one of such case.
If I am using faster RCNN how I can use it with this code??
Exactly the same way, you have to just have to adjust the input for the model and output of the model has to be adjusted in the response.
@@technologyfornoobs but it will be with .pb extension?
ImportError: cannot import name 'Session' from 'tensorflow' in the views.py - why is this happening?
import tensorflow; print(tensorflow.__version__)
Tensorflowv2 does not support Session, you must have the latest version, check with above command , I was using 1.13.1
@@technologyfornoobs yeah I had to update a bunch of things - I got it working thanks
How to implement Django in Android with our own model?
Django can be a rest service end point for you, and android app will make a rest call to your django server. It will not reside inside
Can you do a new tutorial but with TF 2.0?
Will do in some time, occupied with lot of work now a days. sorry!
@@technologyfornoobs mi friend, my i email you? O have errors and it’s for my tesis. It’s just a reshape issue but I really need your help. It’s for my tesis!:(
techfornoobs01@gmail.com
@@technologyfornoobs thanks, I send you an email.
Did you find the solution with tensorflow 2, how you are replace session in tensorflow 2, please help
i downloaded all the files from github how can i run app in pc just to test the app do i need to setup all the environment ??
yes, the environment needs to be set
@@technologyfornoobs Hey can you send me the requirements.txt file it will be really helpful for me setup the environment thanks
@@technologyfornoobs thanks its working
@@technologyfornoobs i trained my own model with two classes how can i target last layer which contains label ? TIA
keras.io/guides/transfer_learning/ this link would help you
Hi sir. When i upload the image it show this error:
KeyError at /ind/predictImage '1'
I believe something is wrong on how you are using the url on your form
@@technologyfornoobs i have button when click on it. İt goes to page that contains upload images button... How can i handle that?!
I do not have much clarity on how you are using the button, but to redirect to another page use "onclick=" in your button code
stackoverflow.com/questions/16562577/how-can-i-make-a-button-redirect-my-page-to-another-page
@@technologyfornoobs i'm working on breast cancer model ,,,i loaded the model path and follow the steps same as in video,,,it shows this error :
"list index out of range"
İ have two classes labeld as benign and malignant
you would need to debug as changing model meaning you have to change the logic as will in the code of preprocessing, forms and so on.
how to upload model also from web page
follow this tutorial th-cam.com/video/6q9Gf3VaHio/w-d-xo.html
how to add two different models?
To host multiple models (deep neural networks) you need to save them in a dictionary with each model will have its own graph and session, when you have to use any just load the graph and session again and use it accordingly.
Sir its showing Jsons decoder error
can you pull from the github repo and check if it works, you need to share the traceback
What model is used in training?
mobilenet pretrained model
@@technologyfornoobs Thanks, I have managed to get it working!! I think it would be useful to have a video explaining the code for tensorflow2 and also how to deploy maybe using s3 buckets as file storage.
Thanks again!! Great tutorial!
@@ethanconnelly8794 Surely Would do it when I get enough to afford an S3 bucket for few days :)
@@technologyfornoobs You could use a free trial
Already consumed!
What changes to do if I want to deploy app?
Actually you don't need to change much, but actually look for gunicorn and look for hosting your model with nginx webserver.
Somewhere in the video you say that, it is not applicable in production but only in development
@@RitikSingh-ub7kc It is at 21:10 where I said it, the media files support while deploying also needs to be checked with the webserver you will use, if you just look for serving media files in webserver using Django, you will find more details about it, if you are doing a PoC kind of work then you can use what was done in the tutorial and deploy your app.
Oh thanks bro! I'll look into it. One more thing, if you want to increase your performance, you can load your model only once per session in apps.py, and then important it in views every time you want to make a prediction
@@RitikSingh-ub7kc Exactly!
32:11
I’m having error while running , labelinfo not defined
img_height, img_width=224,224
with open('./models/imagenet_classes.json','r') as f:
labelInfo=f.read()
labelInfo=json.loads(labelInfo)
Check if this code is missing in your file? If error persist Can you pull from my git and check the code
Technology for Noobs thank you for the reply , i wanted to know that does trained model require this .json file.."?
@@abdullahahmadkhan3929 Nope, it is only for the label which I wanted to send as a result.