How to use your trained model – Deep Learning basics with Python, TensorFlow and Keras p.6

In this part, we’re going to cover how to actually use your model. We will us our cats vs dogs neural network that we’ve been perfecting.

Text tutorial and sample code: https://pythonprogramming.net/using-trained-model-deep-learning-python-tensorflow-keras/

Dog example: https://pythonprogramming.net/static/images/machine-learning/dog.jpg

Cat Example: https://pythonprogramming.net/static/images/machine-learning/cat.jpg

Discord: https://discord.gg/sentdex
Support the content: https://pythonprogramming.net/support-donate/
Twitter: https://twitter.com/sentdex
Facebook: https://www.facebook.com/pythonprogramming.net/
Twitch: https://www.twitch.tv/sentdex
G+: https://plus.google.com/+sentdex

115 comments

  1. Adam Gaskins on

    Recently discovered you, and I’m addicted! Going to start this from pt 1 this afternoon and work through. I’m also excited about your recurrent net tutorial, mentioned at the end! Maybe I’m mistaken, but would that be appropriate for equity market data (stocks, in particular)? I’ve been experimenting a little, but am very very very much still in the learning phase with all of this. That said, I want my programming skills to be more current, and why not see if I can make a few bucks while learning! haha. Thanks for taking the time to share so much great knowledge!

    Reply
  2. Sandeep kumar on

    Do you think increasing batch size has a positive effect on the model for generalizations or how do you think batch size contribute to a better model ? and thanks for making this video series ..it’s super helpful !!

    Reply
  3. Nikhil Panigrahi on

    If I want to do the same in real time video, i.e use my model, with obviously trained with many classes, how can I do it so that I get multiple predictions in a single frame?

    Reply
  4. Leo on

    It’s a new day, it’s a new mug. Yeh yeh what’s new? What I want to point out that the file name is literally “doggos vs animals that dgaf about you except around food” like I’m ded xD

    Reply
  5. Leo Camacho on

    It’s a new day, it’s a new mug. Yeh yeh what’s new? What I want to point out that the file name is literally “doggos vs animals that dgaf about you except around food” like I’m ded xD

    Reply
  6. atrumluminarium on

    For RNN maybe you can do music? You train it on a bunch of MIDI files (say of classical music) and then set it to generate something brand new?

    That being said, I never did this myself so I have no idea of how simple/complicated it would be but I guess having one instrument track per MIDI file should greatly reduce the complexity in contrast with say 10 instrument tracks.

    Reply
  7. Bartosz T......d on

    Are you planning to do a tutorial about semantic segmentation? I have the feeling it gets more and more popular, even outside the ML field. Also, it starts to be very popular in my field (advanced microscopy). One of my future goals is the use of semantic segmentation in image analysis.

    PS. The notbook title is great!

    Reply
  8. camden parsons on

    i see people using that shakespeare data set alot when demonstrating rnns. if you train it for a while, you wont get anything useful but you will start to see something that resembles a play script. I dont think youll get anything good out of training a rnn on pure stock data, but maybe im wrong,

    Reply
  9. Md. Manjurul Hussain Shourov on

    Thanks!! I think, time series weather data (rainfall, temperature) data is good for prediction using RNN. I am waiting for it.

    Reply
  10. Ashutosh Joshi on

    Bro can you make some lectures on Data Structure…like the linked list, Stack, and Queue, Trees something like that!!!!

    Reply
  11. matias trapani on

    Hey great job. Can you explain how could i do more trainning on a saved model? or how do i do transfer learning from a trained model

    Reply
  12. Shaun Kollannur on

    I tried CNN to train my handwriten phone number identification algorithm but need a way to reduce load on it by using something like a shape matching algorithm but it doesn’t seem to work; any way to get a better result?

    Reply
  13. SS K on

    I tried CNN to train my handwriten phone number identification algorithm but need a way to reduce load on it by using something like a shape matching algorithm but it doesn’t seem to work; any way to get a better result?

    Reply
  14. Dana Larson on

    Love the channel! You mentioned possibly doing time series with stocks – I would love to see that. Other things, maybe as one offs, to just show the basics of how to work with these 2 libraries because I think they have gotten more popular recently: Dask and numba. Also: Fuzzy’s, not Torchy’s?

    Reply
  15. Ruigang Ge on

    HI, BIG setdex! I’m your funs,could you make a video to help me to know that a data of the very bigger picture to process and how to resize items batch by batch。likes Quee not all in memory。😀

    Reply
  16. Kshitiz Rimal on

    for RNNs, may be text classification other than just sentiment analysis. something to do with more than 2 categories with custom classes?

    Reply
  17. Cineva in comentarii on

    u didnt bother to answer at least of my questions on last video , so i wont do anything but complain this time

    Reply
  18. THE BroGrammer on

    Don’t you need to normalize the input data before feed it into Neural Network? like img_array = img_array / 255

    Reply
  19. Vinicius Barbosa on

    ABOUT THE FIRST VIDEO OF THE PLAYLIST: I am recieving this error “ValueError: You are trying to load a weight file containing 3 layers into a model with 0 layers.” when i try to use this command”new_model = tf.keras.models.load_model(‘epic_num_reader.model’)” can someone help me?

    Reply
  20. Arman AmEdi on

    Hey sentdex, nice video, using cPickle would be 7 times faster for loading the data, and a question, how do we get the accuracy of the predicted output at test time.

    Reply
  21. Johan Kuster on

    Hi, great videos! Since everybody is talking about global warming and many “experts” predict higher temperatures, what about predicting this?

    Reply
  22. Ivan_G on

    Your vids are fun and easy to follow. Would love to see RNN and LSTM for stocks, and train for specific events such as intraday momentum to predict current momentum % move and confidence %.

    Reply
  23. Lucas on

    Can you make a video about the conv layers’ weights? Like a visualization or analysis of why it’s predicting a dog/cat. Btw you forgot to normalize img /= 255

    Reply
  24. Rutger on

    I have one more question Sentdex. When you use the predict function you get a binary integer output right?
    Can you also get a decimal value which gives you its “confidence” in the prediction? So a float instead of an integer. Thanks!

    Reply
  25. Sohaib Arif on

    non-stock RNN application: next frame prediction or object tracking. Might possibly be a new series.
    simpler: weather prediction

    Reply
  26. Daniel Piskorski on

    Great series!
    Maybe tutorial on how to use networks that come with keras like ResNet50 etc. How to train them to predict our categories or smth.

    Reply
  27. Joya Nisnisan on

    good day sir, I would like to ask is it possible usi g python and open cv, if you can detect clip art or word art in a microsoft document, we are having a problem differentiating clip arts with images. hope sir we could get a response from you. Thank you sir

    Reply
  28. Usama Ghufran on

    Hey Sentdex! Thanks a lot for the tutorials!

    I have 2 questions.
    1. Is normalizing the image not necessary: img/=255.0? How is it that you’re getting correct predictions without normalizing? I was getting correct predictions until I normalized and now all my predictions are Dog.

    2. When we rescale the image, the aspect gets squished. Doesn’t that distort the features? I scaled in a way that scales by the longest axis, preserving image aspect ratio and fills the rest with black pixels. However, now having black pixels might just become a feature the NN might learn. Should I fill with random/static noise instead of black?

    Reply
  29. Patrick Littlefield on

    You should definitely do stocks for the next video. In fact, you might want to do a separate ‘pre-tutorial’ on getting stock data in the current environment, which could be applied as a ‘patch’ to all your other tutorials that incorporate equity prices.

    Some potential ‘features’ you might consider (beyond closing price and volume):

    Dividend Yield
    Return on Assets
    EBITDA/Interest Expense
    Earnings Growth
    Total Debt/Shareholder Equity
    Industry sector

    I would love to see tensorflow used to predict stock prices. That’s my vote, fwiw.

    Reply
  30. Nagarajan S on

    In tensorflow, maybe save models as checkpoint:
    saver = tf.train.Saver()
    saver.save(sess, ‘models/hai.ckpt’)
    saver.restore(sess, ‘models/hai.ckpt’)

    Reply
  31. MrRikum on

    Does someone knows why it only ouputs 0 or 1 and not probabilities, even though we have a sigmoid function at the end ? I tried model.predict_proba but it does the same.

    Reply
  32. saicharan reddy on

    So yeah, I got all of my predictions as Cat when I normalized the data by a factor of 255(img_array/=255) .Did any one find out what was going on?

    Reply
  33. Bruno Belloni on

    Can I make a prediction with an R-CNN with that .model I trained by watching your previous videos? How do I do that? I want to see if I have two flowers in the same image. Thank you

    Reply
  34. Vreesie on

    Quick question: I use a RNN to predict stock prices, but when I feed the model a lot of data it makes multiple predictions (so, for each step). But what is the last prediction of the CSV file I provide the model. So what is the prediction of the last data line of the CSV file, the first value or the last?

    Reply
  35. Ross Heaton on

    Why didn’t you initially split your data in to train, test and validation sets? That way, you could have evaluated your trained model using model.evaluate() with the test data and determined the real accuracy of your model. I was surprised when I saw that you only created a train and validation sets.

    Reply
  36. Gianmarco Polotti on

    Nice video and tutorial.
    How do you manage a dataset with some missing values?
    Suggetion for example datasets: times series that come for experimental measures (es temperatures, pressures, flows, strenghts, powers, ets).
    Thanks.

    Reply
  37. Akhtar Shaikh on

    Hi sentdex,

    your tutorials are ossom..
    I have one doubt
    what about if I passed another image apart from cat and dog..let’s say if I passed my own image then , what model will predict.

    thnks

    Reply
  38. Jayson Balano on

    I got an error saying
    List has no attribute shape,
    I did exactly what you did, where did i go wrong? @sentdex

    Reply
  39. Li Qian on

    Can we download a copy of your trained “64×3-CNN.model”, would be easier for people just watch this video. thank you!

    Reply
  40. Allen De Jesus on

    I followed everything till now and got only this error
    OpenCV(4.0.0) C:projectsopencv-pythonopencvmodulesimgprocsrcresize.cpp:3784: error: (-215:Assertion failed) !ssize.empty() in function ‘cv::resize’
    What does it mean?

    Reply
  41. siddhant sangal on

    How do I use a detected object in my webcam feed as an input for generating a control signal at the GPIO pins of a raspberry pi? In this case, maybe detect a cat and run a motor clockwise and counter-clockwise for a dog?

    Reply
  42. KoShey Versus the Volcano on

    Hi, i’ve a question:
    You resized the training data before training the model using X = X/255
    Why did you skip this step in the test?

    Reply
  43. SOUMAM BANERJEE on

    +sentdex plz note that predict gives back the probability as a return… but when you give a cat and its 0.99 or rather 99% sure its cat then what it does is
    CATEGORIES [ int (0.99) ] == 0
    which then shows that DOG is the output…rest all is very good …learnt a lot …. LOVE FROM INDIA 🙂

    Reply
  44. Science Guy on

    I am a beginner and trying this algorithm and training with coral images. I have two sets of images and followed the procedure. However in the prediction, I get either of the prediction as “Hard Corals” (I am classifying hard and soft corals). BUT, when I change it from :

    CATEGORIES = [“soft corals”, “hard corals”]
    TO
    CATEGORIES = [“hard corals”, “soft corals”], All my prediction now becomes “Soft Corals”. Please help.
    I have balanced the training sets too.

    Reply
  45. Rahul Dass on

    Hi! Thanks for this updated series. Super helpful! Would you please do a tutorial(s) of doing transfer learning and/or fine tuning learning by using “off-the shelf” models to run with custom data? Models such as AlexNet, Caffe, Inception v3, ResNet etc.

    Reply
  46. Lorenzo LEON GUTIERREZ on

    dear friend, great lecture series really thankz for share!. On my case im an agronomist and looking to advance on plant seedlings discrimination. big hug and congrats! , Lore

    Reply
  47. Farhan Ali Shah on

    ############IMPORTANT#####################
    can we use run time video to detect cat and dogs and their position in the frame using the trained model???

    Reply
  48. Nikhith nkz on

    OpenCV(4.1.0) C:projectsopencv-pythonopencvmodulesimgprocsrcresize.cpp:3718: error: (-215:Assertion failed) !ssize.empty() in function ‘cv::resize’
    am getting this error can any help me out

    Reply
  49. Anh Kỷ Đào on

    Cho tôi hỏi: Tôi cần tải xuống tệp hình ảnh chó và mèo để so sánh nó, tôi nên lưu nó ở đâu để đọc 2 tệp

    Reply
  50. Rajat Patil on

    What would the model predict for images containing neither a dog nor a cat? Or for some thing that has half a cat and half a dog? Actually I’m using it for some other case where there is a possibility of a sample having half the characteristics of each label class. How do I work with this?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons