Convolutional Neural Networks - Deep Learning basics with Python, TensorFlow and Keras p.3
Vložit
- čas přidán 18. 08. 2018
- Welcome to a tutorial where we'll be discussing Convolutional Neural Networks (Convnets and CNNs), using one to classify dogs and cats with the dataset we built in the previous tutorial.
Text tutorials and sample code: pythonprogramming.net/convolu...
Discord: / discord
Support the content: pythonprogramming.net/support...
Twitter: / sentdex
Facebook: / pythonprogramming.net
Twitch: / sentdex
G+: plus.google.com/+sentdex
As a programmer/amateur data scientist, I have wanted to understand and use neural networks to take my craft to the next level for years, and sentdex, you are the first researcher/teacher/hacker/genius that has enabled me to actually break that glass ceiling and use neural networks for real-life problems. Thank you so much!
Happy to share!
"I need more tea" cracks me up.....
Thanks for the vid
For anyone getting the following error "validation_split is only supported for Tensors or NumPy " add y = np.array(y) under X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE,1)
Thanks worked like charm!
thank u very much
thank you!
thank you
Thanks
You are the man, Sir! Thanks so much for making these vids...and looking forward to watching the machine learning lessons!
15:55 Found the solution: If you did everything exactly the same throughout the previous video, just add this " y = np.array(y) " after the " X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)" so it look like this:
X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
y = np.array(y)
It was giving me errors until adding that line too and reexecuting it
Thanks for this solution, I was stuck.
after doing what you suggested I got this error
File "", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: indices[194] = 194 is not in [0, 194) [Op:GatherV2]
ps: 194 is the size of my dataset
Thanks
Thanks, It worked!
I was getting some weird Tensorflow InvalidArgument errors and I was stuck..
thanks a lot, that solved it for me too
you have some of the strangest coffee cups I have ever seen
I wanna buy one
@@sungyoungkim4382 where to get the coffee cups
A tutorial on keras callbacks such as EarlyStopping and ModelCheckpoint would be nice.
Also, I would love if you could explain Image Augmentation in Keras for CNN.
You can add layer with Activation inside:
model.add(Dense(256, activation='relu'))
It allows you to choose activation function to each of them separately
dont know why he didn't do that
you should definitely do a video on transfer learning in this series.
looking forward to your transfer learning videos
Agreed ! Please do one. Badly waiting for that
You can add the "layers" as an array "model = Sequential ([ flatten(), Dense(10), Activation('relu') ])" instead of using the model.add() function every time.
Why not use dense layer with 2 nodes in the end, why one ? please help in explaining
@@curious_one1156 Because one node can be both on and off ,1 and 0, cat and dog
@@sklify1232 So what if you put your output layer as "2". Then would you technically have 3 output classes? Ex. "Cat", "Dog", and "Airplane"?
@@michaelschmidlin4274 I think it would still be cat and dog, so it's an equivalent alternative to one node for binary choice. You could say "airplane" when both of the 2 nodes are off , but it would depend on the activation threshold- too cumbersome.
was gonna say the same thing lol
Thank you for being so didactical. I also relate some much when it comes to the errors :) Keep rocking!
Your tutorials are sooo good!
Was waiting for this for so long
No more wait! ...til the next video :)
you're awesome man :D
hey sentdex, nice tutorial I've been binge watching your tutorial videos and compared to your previous convolutional neural network videos I noticed a few differences. For conv2D you didn't increase the number of features(for both layers you kept it at 64) whereas previously you increased it. Why is that? Moreover, why did we not use dropout and why did we use the 'sigmoid' activation function over 'softmax'? And also wanted to say thank you for the great content!
I like your enthusiastic explanations and fun videos
Just amazing! You are really helping me with my paper! 🙌
It was a headache but I finally installed tensorflow-gpu on my windows pc. now I can run the epoch in 20 seconds!
Can you tell me the steps to install tensorflow-gpu and my epoch is running very slowly @MRH
@@rizwanrehman6833 use google collab instead
I know the feeling
Love the collection of mugs. I know you like to send hidden messages. Hahaha.
Dude literally saved my dissertation, what a legend 🙌
Bro Thank you so much for this tutorial. This helped me in doing my academic project. Thank you so much bro.
It can work on tf2 just by adjusting the below
X = np.array(pickle.load(open("X.pickle", "rb")))
y = np.array(pickle.load(open("y.pickle", "rb")))
# now you have to reshape (col, rows, channel)
X = np.reshape(X, (X.shape[0],*X.shape[1:],1))
bless you
Thank you Ramzy.. Your solution solve my problem..
Bro you are awesome.I have watched each one of your video series.Great content brother.
Hello Dear I am facing following error. I am using same syntax as you did....
FileNotFoundError Traceback (most recent call last)
in
----> 1 X = pickle.load(open("x.pickle","rb"))
2 y = pickle.load(open("y.pickle","rb"))
3 X = X/255.0
I can not wait to the next the next great tutorial !!! Very Nice Vedios
Hi Harrison, doesn´t the Dense(64) layer at 11:30 need an activation function? I added another "relu" there and got better accuracy.
Whoops. yep, that's a mistake lol.
for some reason i got better accuracy in the same amount of epochs when i didn't add an activation function for that layer
King Neptune whatever that reason might be but a layer without an activation makes no sense
Brother Lui yeah I agree it'd be useless
There has been some study of "all Conv" models where only the output layer is fully connected, generally results in greater accuracy.
Will you do a tutorial on using RNN in Tensorflow and GANs and stuff.
Thanks man. thank you for your help and great teaching
THANK YOU SO MUCH FOR THIS TUTORIAL
For anyone who had a negative loss by following this tutorial with your own dataset which had more than 2 categories of labels, don't forget to normalize your label array as well!! So y_normalized = y/ y_.max(). it will make your labels to be between 0-1 and then the whole thing works just fine
can you elaborate more where do you put that code?
Why are the first two layers conv2d and the third one is dense? I tried switching the second conv2d layer to dense and it had better accuracy but took a few seconds more to train. is it for balance between time and accuracy? Great videos and thank you for making these
Thanks for your CNN videos, sir.
Bro, your coffee mugs are just the cherry on the cake
for anyone coming across this as of 03/03/2021, i had to do a bit of fiddling to get it running properly.
X = []
y = []
for features, label in training_data:
X.append(features)
y.append(label)
X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
y = np.array(y)
convert y to a numpy array after you've filled it with the targets/labels
X.shape = (24946, 150, 150, 1)
y.shape = (24946,)
just need to get it running on the GPU now as it takes an age to run an epoch lol!
savior
Hey,
Could you maybe expand a bit on the exact purpose of the ‘Dropout’ function? We imported ‘Dropout’ but I don’t think we used it anywhere in the code. Did you decide on the fly to not include a dropout function or was it perhaps just simply an oversight?
usually you implement a dropout if your model has overtrained. So you randomly "drop out" certain connections in hopes to make your model more generalizable. Of course, it will probably also reduce accuracy for validation purposes.
Harrison, the product placement master!
Thank you for this awesome video
how would i go about running this on the GPU instead of my CPU? it is taking ages to run a singular epoch
X=X/255.0 is giving me error unsupported operand type(s) for /: 'NoneType' and 'float'. How will I rectify the error ?
In tutorial #2 Harrison converted X to a numpy array, and it's possible that definition is still hanging around here. Before the division, add the following lines and you should be good to go:
import numpy as np
X = np.array(X)
@@markd5928 I know it's been three years for you lol, but THANK YOU for this. I was pulling my hair trying to figure this error out.
THANK YOUUUUUU !!!! It is really helpful 😘🖤
Series on data preprocessing and feature engineering will be really helpful.
I am getting an error at validation split ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found: (array([[[[ 36],
import numpy again and reconvert to nparrays after loading
X = np.array(X)
y = np.array(y)
How can I test this model for a new image ?!
I dont know if you still need this but what I did was:
Image_size = (your image size)
CatDogModel = tf.keras.models.load_model('(put the name of your model save file here)')
ImagePath = "(Path to your image)"
Image = cv2.imread(ImagePath, cv2.IMREAD_GRAYSCALE)
NewImage = cv2.resize(Image, (Image_size, Image_size))
NewImage = np.array(NewImage).reshape(-1, Image_size, Image_size, 1)
prediction = CatDogModel.predict([NewImage])
a = prediction[0]
print(a)
0 is dog and 1 is cat.
(I did all of this in a separate python script.)
I dont know if I did it in the best way but that's what I did.
re:layer, I think the origin is from the data graph that is formed. It's another layer/processing step that gets applied, and the order of the operations is somewhat tunable (e.g., activate before normalization or vice versa).
You are a amazing teacher ❤️
I'm getting this error:
ValueError: Negative dimension size caused by subtracting 3 from 1 for 'conv2d/Conv2D' (op: 'Conv2D') with input shapes: [?,50,50,1], [3,3,50,256].
Can anyone help!!
yes, the solution lies within the 2nd video, a slight edit should be made in 2nd video in order for the 3rd video code to run.
In the section wher the x has been made into an array, y should also be made into an array. The line goes something like this : X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
y=np.array(y)
This would solve the value error problem, as they both are fitted into two individual arrays.
Seems u need someone to draw for this project😂😂
Anyway nice tutorial
Thank You, Good explanation 👍🔥
Great video. Thank you very much.
16:00 how did you computer do that so fast?! i have a really good computer and it took 69 seconds
edit: I installed tensorflow-gpu and now it takes 4 seconds oh yeah
thanks! helped a lot
How to install tensorflow-gpu ?
@@rizwanrehman6833 www.tensorflow.org/install/pip this should help :D
@@paulroberto2286 No mac support sadly :-(
10 epochs :o ?
getting error
ValueError: Input arrays should have the same number of samples as target arrays. Found 74838 input samples and 24946 target samples.
same problem, any fix?
That means that your reshaping didn't go well, you could try to check the image size you constructed the data with and run it again
Hi Harrison, At 12:26, in my opinion activation function is present at every layer that is why keras added it to the keras.layers !
Thank you so much for the video..
i am using for different dataset but i am caught at this error. Help me.
My dataset has total 4000 images in 4 classes, 1000 images in each class.
ValueError: Input arrays should have the same number of samples as target arrays. Found 40 input samples and 4000 target samples.
My computer is too slow. Thanks for your tutorial
USE gpu of ur computer, perhaps u have figured that out already
Nice hands on explanation of CNN
thank you for such good videos!!!
How many tea cups do you have???
9:05 Genuine question, what does the colon do?
X.shape[ 1 ] returns an int e.g. 7
X.shape[ 1 : ] returns a tuple e.g. (7, )
so the colon would return a tuple instead of an integer, not sure if that helps?
Hamish Okay, thanks!
Actually its for slicing. X.shape[1:] means he is getting the tuple X.shape, but without the first element.
Example: X.shape returns (a, b, c, d) X.shape[1:] returns (b, c, d)
Awesome video ! keep going ...
Very good content bro........ It's really helpful
I am getting this error
ValueError: Failed to find data adapter that can handle input: , ( containing values of types {""})
The problem is that X is a numpy array and y is just a list.
What I did is:
X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
y = np.array(y)
@@vaizerdgrey thanks this worked!
@@@vaizerdgrey it worked thanks buddy
Coffee mug level: 100
great tutorials thanks
Hey! Very useful and comprehensive series so far! You got my sub!
Question - how would you go about implementing multispectral imagery (i.e. - more than 3 bands) ?
Failed to find data adapter that can handle input: , ( containing values of types {""})
getting this error , how to resolve ??
I am getting the same error.
Solved the problem:
The problem is that X is a numpy array and y is just a list.
put
from numpy import array
in the import statements
and change the y assignment to
y = array(pickle.load(open("Y.pickle","rb")))
@@rubenuribe love u
@@rubenuribe gracies maquina
@@rubenuribe Freaking love you man !
I am getting a "ValueError: Input 0 is incompatible with layer conv2d_1: expected ndim=4, found ndim=3" can someone help?
try creating a new variable that stores a resized X with an additional dummy dimension, something like "resizedX = numpy.resize(X, (1,X.shape))" and put that resized X into your fit function instead of the normal X
@@x3epic763 What Do you mean? Could you explain more? I'm getting the same error, but I don't know what you're saying
@@jordenquast2655 well the error kinda says that the function expected a 4 dimensional input but received a 3 dimensional one. Therefore you can try adding a 4th "dummy" dimension as the first dimension to the input. So say your input has the shape (200,5,5) then the new input should be (1,200,5,5).This can be done with the resize function: you make a new variable and store the result of the function as the input. This new variable can then be used as input for the training function. It depends on the overall setup if this will work, but ive seen the problem solved like this a couple of times
@@x3epic763 I solved it, there error was in the last line of the data transformation code, where it took some dimensions away. This left it with too few dimensions to be able to run. I believe the line of code was X = np.array(X).reshape(-1, imgSize). Hope this helps someone!
@@jordenquast2655 specifically this is the correct line: X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1)
A target array with shape (2400, 64, 64, 1) was passed for an output of shape (None, 1) while using as loss `binary_crossentropy`. This loss expects targets to have the same shape as the output.
I changed the output layer to be 2 neurons with softmax activation and sparse categorical crossentropy. Makes more sense to me, since we want to know the probabilities of the input image being either a cat or a dog.
my god man, why your computer so fast.
mine takes forever to train
it's most likely a server
he has a high-end gpu. if you're on a budget I picked up a 1060 6gb on ebay for like $130 and it trains models really fast for the $$
@@waynefilkins8394 yes but i think he uses paperspace and does his development on their servers.
is it just me, or does he look a bit like Edward Snowden?
You can estimate the largest batch size using:
Max batch size= available GPU memory bytes / 4 / (size of tensors + trainable parameters)
Awesome as always, will wait patiently for the next video and I hope to hit "Join" button too when i am less busy to get the max out of your brain :D
yo i got the entire project on github check it out
what is your link?
Thanks for the tutorial. One question though:
What further steps we should take in order to construct a model which returns the bounding box (position information)?
Do we need to do labeling (with for example labelImg)? Tfrecord? ...
If you want to see a flowchart of your model, use:
from keras.utils import plot_model
plot_model( model, 'Chart.png' )
Love that mug 🙂
Nice video dude
That is it, you are better than my professor!
How do you decide how many hidden layers you are going to use and how many nodes per layer you will use?
i have an assignment due in 2 days, now im here :P
You can either pass Activation as a layer or as an argument for a layer.
"Activations can either be used through an Activation layer, or through the activation argument supported by all forward layers:"
keras.io/activations/
Nice video. Will you consider making a series on Signal processing with Python?
Hi,
First of all, thanks for this tutorial, it covered most of my doubts! But I have a question, will it work for multiclass classification? I mean I am trying to apply the same exact algorithm to a lego dataset (6 classes), but I am getting pretty bad results accuracy is about 0.17. Any advice?
9:48 5 sentences... i love it! :D
wonderful content
this man should hv more than 10 million subscribers
ys ur correct
ys
Bobby Fisher's 21 move brilliancy is a video I watched at least 10 times. Apparently we are in the same team, since CZcams's ML algorithms tell you to watch it ^^
This is such a great intro to the subject. I am interested in creating my own data for which I would train a network instead of downloading something rom the internet----aka, recording a video of something for which I can extract alot of image frame from (at least 30 frames per second) and use these images as training/test data. I plan to reshape images and the like before feeding to a CNN--but do you have any pointers on pitfalls I might face when creating my own data sets (other than the fact I would need a lot of training data)? Thanks again for these tutorials, you make this subject incredibly fun.
Great tutorial !
I think it's better that you use Jupyter notebook in your tutorials. It makes things much easier to follow.
I think best way to define a layer is to define all the parameters like activation='relu' ,optimizer='adam' in a single line like model.add(Dense(34,activation='relu',optimizer='Adam'))
thanks for the great video where i can find the dataset?
thanks dude
Help me a lot! By the way, your cup is soooooooo cute!
valuable content
Thank you for your video. I have followed the same way of designing the CNN model but unfortunately the model gets overfitted. How can I overcome overfitting on this similar kind of CNN models.
Thanks a lot for your great courses, is it possible for you to explain my question? How should we add non-image features to our CNN model (features like cat and dog prices) to our flatten layer? Does the CNN model new added features belong to which input image?
python are just so amazing! i mean its just so friendly to use,u can just grab some tool and go ahead,play with it,and its fun!
Great video, I have a database with 2 folders: ships and other (waves, bridges, coasts, and similar). How should I modify this to recognize what is a ship and what is not, instead of classifying because the folder 'Other' has many different images?
when compiling with pycharm, "OpenCV(3.4.1) Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in resize" errors happen by 60 or much more times, do you know what is the error.
Also , a tutorial on pose estimation applications!
thank you!
Awesome!!!!