HomeНаука и техникаRelated VideosMore From: Macgyver

Train an Image Classifier in 3 Minutes

49 ratings | 3878 views
Using Tensor Flow and Docker, this tutorial will show you how to create an image classifier that can accurately identify any object in an image. Step 1 Stand Up a Tensor Flow Docker Container for Development Step 2 Download Training Data Step 3 Train the Neural Network Step 4 Make a Prediction of Novel Data GitHub Code https://github.com/MacgyverCode/Image-Classification-Example Tutorial Blog Post https://askmacgyver.com/blog/tutorial/create-image-classifier Install Docker https://askmacgyver.com/blog/tutorials/how-to-install-docker-on-ubuntu-14.04.4-x64 Wayixia Batch Image Chrome Extension https://chrome.google.com/webstore/detail/batch-image-downloadfull/ahajhopfbfpekcljjjppolcmapaidldc?hl=en #tensorflow #machinelearning
Html code for embedding videos on your blog
Text Comments (31)
Fadil Rahadiansyah (20 days ago)
i didnt found retrain.py in image_retrain folder, how is it there?
Fadil Rahadiansyah (14 days ago)
+Macgyver oh maybe I was wrong when I run it, I run docker -it -d tensorflow/tensorflow okay thanks mate
Macgyver (14 days ago)
I just double check and saw the file there. Did you use this docker image? docker run -it -d macgyvertechnology/tensorflow Within the container the the retrain.py file is located here - /tensorflow/tensorflow/examples/image_retraining/retrain.py
yabi oumayma (1 month ago)
hello everyone, executing the following command on the Powershell python tensorflow/examples/image_retraining/retrain.py --bottleneck_dir=/bottlenecks --model_dir=/inception --output_labels=/retrained_labels.txt --output_graph=/retrained_graph.pb --image_dir=/data/db/ I have the following error " C:\Python36\python.exe: can't open file 'tensorflow/examples/image_retraining/retrain.py': [Errno 2] No such file or directory"
Macgyver (1 month ago)
You probably ran it from the wrong directory. Use an absolute path with python /tensorflow/[...]
Robert Solano (2 months ago)
Robert Solano 1 day ago (edited) Here is my code: I've watched at least 30 tutorials on this subject all. This was the first tutorial that actually worked! Here is exactly everything I did. I had already installed Anaconda, Tensorflow, PyCharm, and Docker. I wasn't' sure what I actually needed, so I installed all of them. I spent a few hours trying to run it from Docker, PyCharm, and Anaconda prompt without success, before realizing that the bash window in the video is the same thing as a CMD prompt in Windows. ## Comments (non-code) are marked with two hashtags. ## I'm running a Dell XPS Laptop with Windows 10 ## Step 1) Install Anaconda #I'm actually not sure if this is necessary, but I did it anyway. I have v 3.6 and 2.7 ## Step 2) Install Docker Desktop for Windows (https://www.docker.com/products/docker-desktop) ## Step 3) Download about 100 images each for two separate items. ## The Chrome browser Wayixia plugin can help 'dig' images in batches. I had to limit batched to about 15 at a time. ## Place images in two separate folders within a 'training_data' folder under your username folder. ## You can use your own folder names, for example mine was 'C:\Users\Robert\training_data\type_1\' and '...training_data\type_2\'. ## Step 4) Download at least two test photos and save in a test_data folder, for example 'C:\Users\Robert\test_data\test1.jpg' and '...test2.jpg' ## Step 5) Run Docker ## Step 6) Open CMD Prompt (not Docker or Anaconda prompts). You can open by typing CMD into the Windows start menu ## Step 7) In CMD Prompt type the following code or paste from each line here using right click docker pull macgyvertechnology/tensorflow ##This pulls a docker repository from 'https://hub.docker.com/r/macgyvertechnology/tensorflow/' docker run -it -d macgyvertechnology/tensorflow docker ps -a docker cp training_data/ 84c75cfc6dc8:/ ##replace the funky numbers with your own shown in the CMD prompt under CONTAIER ID for macgyvertechnology/tensorflow docker cp test_data/test1.jpg 84c75cfc6dc8:/ ##replace test1.jpg and test2.jpg with the file names of your test images docker cp test_data/test2.jpg 84c75cfc6dc8:/ docker exec -it 84c75cfc6dc8 bash ##at this point, 'C:\Users\Robert>' should instead display something like '[email protected]:~# ' cd / ##below is the inspection process, you can repeat for both training_data folders and the test_data folder. ls ##verify that your training_data and test_data folders are shown cd training_data ls ##verify that you your two subfolders for 'type_1' and 'type_2' are listed. cd type_1 ls ##verify that your training JPGs are listed, you can drepeat this process to inspect type_2 and test_data cd .. cd .. ##end inspection, enter 'cd ..' until you get to top level folder prompt '[email protected]:/#' ##now run the training, each line is a separate entry. python tensorflow/tensorflow/examples/image_retraining/retrain.py \ --bottleneck_dir=/bottlenecks \ --model_dir=/inception \ --output_labels=/retrained_labels.txt \ --output_graph=/retrained_graph.pb \ --image_dir=/training_data/ ##again, training_data is my folder name, replace it with your own location if different ##now run a test for each test image python tensorflow/tensorflow/examples/image_retraining/label_image.py \ --graph=/retrained_graph.pb \ --labels=/retrained_labels.txt \ --image=/test1.jpg ##replace test1.jpg with your file name
Endless Void Studios (12 days ago)
thanks quick note fatkun can be used to grab images from google faster
Md Saiful Islam (1 month ago)
Dear Sir, I am getting this error after last command > python tensorflow/tensorflow/examples/image_retraining/label_image.py \ >graph=/retrained_graph.pb \ >labels=/retrained_labels.txt \ > image=/test1.jpg usage: label_image.py [-h] --image IMAGE [--num_top_predictions NUM_TOP_PREDICTIONS] --graph GRAPH --labels LABELS [--output_layer OUTPUT_LAYER] [--input_layer INPUT_LAYER] label_image.py: error: argument --image is required
Macgyver (1 month ago)
+Md Saiful Islam What is your exact error message?
Md Saiful Islam (1 month ago)
Did you worked on Windows 10. I am getting an error that folder directory not founded locally.
Macgyver (2 months ago)
Awesome nice job, windows 10 can be tough.. but sounds like you got it working.
ali Seven (5 months ago)
It does not work for me... permission denied when trying the learning part using python 3.6 64 bit
ali Seven (5 months ago)
Thank you so much!Check your E-Mails .Peace
Macgyver (5 months ago)
The most feasible approach is first you need to host your model as an API. Then your webpage will interface with your API by passing it a URL to a users photo. You can upload your model to macgyver and add a wrapper such that a user passes a URL the container downloads the image and runs an prediction using your model. I have some examples that do exactly this. I can share/help you with the project if you want. Email me more details [email protected]
ali Seven (5 months ago)
Thx for your answer, I manage to handle it and its working now! How can I put this into a webpage with a user interface to upload images and make predictions on that do you have an idea? Best regards! Super video
Macgyver (5 months ago)
What command leads to permission denied?
Y J (6 months ago)
python tensorflow/tensorflow/examples/label_image/label_image.py \ that is how the last step should look according to the new container setup
yabi oumayma (1 month ago)
Hello +Macgyver , executing the following command on the Powershell python tensorflow/examples/image_retraining/retrain.py --bottleneck_dir=/bottlenecks --model_dir=/inception --output_labels=/retrained_labels.txt --output_graph=/retrained_graph.pb --image_dir=/data/db/ I have the following error " C:\Python36\python.exe: can't open file 'tensorflow/examples/image_retraining/retrain.py': [Errno 2] No such file or directory"
Macgyver (4 months ago)
Thanks
Kevin Fleischer (6 months ago)
Hi Macgyver, I followed your tutorial and it went as explained. I'm wondering, what I would have to do, to move the trained AI out of the container and onto a different system (i.e. my phone). Is this possible? And how?
Macgyver (5 months ago)
This process will generate a .pb file that represents the network, this can be leveraged by mobile tools like tensor flow mobile.
kim joug un (6 months ago)
thanks bro
Shreeshan Sadasivan (9 months ago)
i followed same steps in windows but after retraining i am not able to detect retrained_graph.pb retrained_labels.py
Macgyver (9 months ago)
Did you use my tensor flow image in the description? They’ve changed the docker image as of my making this video.
Shreeshan Sadasivan (9 months ago)
I same steps in windows but after retraining i am not able to detect retrained_graph.pb retrained_labels.py
Macgyver (1 month ago)
You may have supplied the wrong path to those files.
Dekkksllls (10 months ago)
Hello Macgyver, great video ! Could you please tell me where I can get label_image.py to run the test ( at the final step) ? Thank you!
Dekkksllls (10 months ago)
Thank you very much mate, it was helpful ! Good work, keep it up!
Timothy Moody (10 months ago)
They've updated the container to no longer support this exact process. I've duplicated the prior version with already has the label_image.py file ready to use. Downlod the container here - macgyvertechnology/tensorflow https://hub.docker.com/r/macgyvertechnology/tensorflow/
Barry Staes (10 months ago)
Nice tutorial. I found that Step 4 no longer works, the script was (re)moved and needs layer params now. See screenshot https://twitter.com/BarryStaes/status/959196832227262464
Macgyver (10 months ago)
Thanks! I’ve saved the old image where it works. macgyvertechnology/tensorflow

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.