Neural Network For Handwritten Digits Classification | Deep Learning Tutorial 7 (Tensorflow2.0)
ฝัง
- เผยแพร่เมื่อ 29 ก.ย. 2024
- In this video we will build our first neural network in tensorflow and python for handwritten digits classification. We will first build a very simple neural network with only input and output layer. After that we will add a hidden layer and check how the performance of our model changes.
🔖 Hashtags 🔖
#handwrittendigitrecognition #tensorflowtutorial #handwritingrecognition #mnisttensorflowtutorial
Do you want to learn technology from me? Check codebasics.io/... for my affordable video courses.
Github link for code in this tutorial: github.com/cod...
Next video: • Activation Functions |...
Previous video: • Pytorch vs Tensorflow ...
Deep learning playlist: • Deep Learning With Ten...
Prerequisites for this series:
1: Python tutorials (first 16 videos): www.youtube.co...
2: Pandas tutorials(first 8 videos): • Pandas Tutorial (Data ...
3: Machine learning playlist (first 16 videos): www.youtube.co...
🌎 My Website For Video Courses: codebasics.io/...
Need help building software or data analytics and AI solutions? My company www.atliq.com/ can help. Click on the Contact button on that website.
#️⃣ Social Media #️⃣
🔗 Discord: / discord
📸 Dhaval's Personal Instagram: / dhavalsays
📸 Codebasics Instagram: / codebasicshub
🔊 Facebook: / codebasicshub
📱 Twitter: / codebasicshub
📝 Linkedin (Personal): / dhavalsays
📝 Linkedin (Codebasics): / codebasics
🔗 Patreon: www.patreon.co...
Check out our premium machine learning course with 2 Industry projects: codebasics.io/courses/machine-learning-for-data-science-beginners-to-advanced
Hello, why do we have 1875 steps in each epoch in 20:40 ? Where is this 1875 number coming from? It is not the 60000 training data size or nothing else we saw above that line?
Thank you so much by the way..,
Sir.. you deserve to teach the entire world machine learning.. you are an exceptional talent.
@@brad8122 good question bro same doubt?a brief information about epoch sir?
Excellent Video.. I always follow the philosophy: First have something working with as much little theory as possible...and then play with parameters that increase curiosity and then dissect the theory..Makes life easy.. than the other way around..
Phani, exactly. I am following exactly same principal. There are many things in this tutorial such as loss, optimizer etc which remains mystery but I wanted to use that first and than unveil the mystery step by step :)
If we use activation function 'softplus' and 'sigmoid' and optimizer is 'nadam' is also giving good result
model=keras.Sequential([
keras.layers.Flatten(input_shape=(28,28)),
keras.layers.Dense(300,activation='softplus'),
keras.layers.Dense(10,activation='sigmoid')
])
model.compile(
optimizer='nadam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
model.fit(X_train_flattend,y_train,epochs=10)
What accuracy did you get here?
98.47 percent 😊
thank you, sir can you make video for simple insurance problem from the start of video?
may I know what is 1875/1875 when we run model.fit()?
what if the output isn't binary? more than 2 classes. What should the model be like please suggest?
from the Optimizers ['SGD','RMSprop','Adam','Adadelta','Adagrad','Adamax','Nadam','Ftrl'] with 5 Ephocs, Adamax got the highest score on Test samples. Ftrl got the lowest score.
adafactor gives only 0.15. its worst
Sir, you are a born teacher. The way you represent complex topics in simpler way is truly amazing. I really admire your hard work for designing such wonderful courses. Thank you sir.
THANK YOU ,LOVE FROM INDIA .... GAYATRI , GAURAV (LOOSERS)
Using 1 hidden layer (1000) & relu (remaining parameters untouched), I reached 0.9908 accuracy. Thanks a lot for this course.
Is it a evaluation score or training score?
Training
This is the most elegant solution of Hand-Written digits MNIST problem in the whole Internet! Thank you. I've learned so much! You have my sub and much respect!
Glad it was helpful!
Just love the way you're making things pretty simple. A big shout-out to you.
Dear Sir... thanks a lot for your clever and robust teaching ... please can i get presentation of this course ...
student : What is tensor?
codebasics: in the general case, an array of numbers arranged on a regular grid with a variable number of axes is know as a tensor
Even though you have mentioned 3Blue1brown over here you have explained Neural Network with much concrete example here. Your examples are very easy to visualise and understand for beginners and in some cases it's even better than the great AndrewNG himself. Being from the field of education I see all the qualities of a great teacher in you, keep up the good work and thank you for such a good tutorial for free.
🙏🙏🙏 thanks and yes I am continuing it and even left my 9 to 6 job to do this full time
Since we have categorical predictions to be made, shouldn't we use softmax as an activation function in the output layer to get best possible performance?
i think it depends on your choice based on activation function
Thank you so much for the great explanation!
By using relu in the hidden layer and softmax in the output layer , was able to achieve an accuracy of 99%
can you explain a little more how to use it?? or refer me some videos
Well lectured..Have to listen twice to understand this session accordingto my perception..
This is phenomenal, thank you so much! Truly a brilliant teacher. Been looking for a while, and this video summed up so much. You sir earned yourself a subscriber, and perhaps many more as I share your channel. Thank you for taking the time to do this.
accuracy = 99.25% with code below,
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(100,activation='relu'),
keras.layers.Dense(10,activation='sigmoid')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train,y_train,epochs=10)
Sir can you please send me source codes files if available
accuracy= 99.92%
with code below
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(100,activation='relu'),
keras.layers.Dense(50,activation='sigmoid'),
keras.layers.Dense(10,activation='sigmoid')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(X_train,y_train,epochs=70)
I become fan of you as your style of explaining the things. You explained the complex topics in such a lucid manner that audience could not be distracted for a single while.
Thanks Dr Manish 😊👍
have you understood clearly?
Dhaval, does the trained model expect that after deploying it to real life situation, I should provide the images of handwritten text (say by myself) in a specific size of file, format of file , color of handwritten text etc ? Or can it be different from mnist database ?
Hello, I was implementing handwritten digit code in macOS. Every time I ran the model code, I was getting an error 'Kernel has died. It will restart automatically'. However, below snippet resolved my problem
import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
Can someone please explain this issue?
Hi,
For prediction of single image, you need to reshape to (1,784) i.e. X_test_flattened[0].reshape(1, 784).
i always get the score 0 could you explain that please
Hello sir, thanks for beautiful explanation and I just got one doubt, why haven't you used standard scaler or Minmax kind instead of scaling it down by dividing 255?
He used min max scaling only. Notice that x_min = 0 and x_max = 255. Just omit the 0s.
scaled_x = (x - 0)/(255 - 0) = x/255
love the have you figure out the issue of accuracy, That makes a huge difference.
God damn man you're amazing, every doubt that I had during my education degree you solved it. Keep up the good work man :D
Your course is more than explicit. Thank you so much for giving such efforts to share knowledge
This is awesome I got accuracy of 99.52%
Is it a evaluation score or training score?
What an amazing tutorial! Did a machine learning for the first time with so much clarity! Thank you so much sir
i got the accuracy of 98.37 on training data and 97.32 on the test data and on the graph of truth vs predicted (tha we made using sea born library) the highest value other than diagonals was 19
Best Deep Learning Course I found On TH-cam, I mean you the gave the content that I was looking for.
I have a question please
I don’t understand how output layer gives probabilities of lets say (handwritten 9) at 9th neuron, (handwritten 8) at 8th neuron and so on.
That's how it was created, remember(10 output values). It tries to fit to this case.
your videos are very helpful. It clears all doubts about machine learning and deep learning. can you please make a video on Deep learning using PyTorch?
Hi dhaval,
You have explained the concept in very simple manner. Could you please share all ppts of deep learning series? It will be a great help for all learners.
it needs time to develop, so wait for the time
how to predict for (X_test_flattened[0]) and not for (X_test_flattened) ? Please someone answer...
X_test_flattened[:1]
Great introductory video! Thanks a lot.
result of playing with various optimizers: 0.9912 : adam
0.9886 : rmsprop
0.9488: SGD
0.7354: adadelta
0.9208 : adagrad
0.9757: adamax
0.9921: nadam
0.7387 :Ftrl
I would begin the play with losses tomorrow. Looks like atleast CategoricalCrossentropy expects y in one hot representation.
After using dummies, got accuracy of 0.9309 for 10 epochs.
Poisson's class gave 0.9181.
binary_crossentropy gave 0.9212
this is the easiest and a must watch video to learn deep learning basics.
I will be always grateful to you sir
I got *0.995* training accuracy and *0.9811* test accuracy with following model. I think its overfitting but this is the best I could get.
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(200, activation='sigmoid'),
keras.layers.Dense(50, activation='sigmoid'),
keras.layers.Dense(10, activation='sigmoid')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10)
Wow.. that's a pretty good score Ashish. Good job 👍👏 looks like increasing hidden layer helps
Thank's a lot for making this wonderful playlist for Deep Learning.
you are SUPER , please continue ,also if you can explain deep reinforcement learning , i will be so grateful !!
What happens at each 'epoch' ?
Is it like K-Fold Cross validation.?
Each epoch is a training neural net for all images, collecting their combined loss and backpropogating it. Next video in this series will be explaining exactly that.
model=keras.Sequential([
keras.layers.Flatten(input_shape=(28,28),),
keras.layers.Dense(100,activation='tanh'),
keras.layers.Dense(10,activation='sigmoid')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train,y_train,epochs=5)
By using this activation function i found the accuracy 0.9840.
------------------------------------------------------------------
loss: 0.0145 - accuracy: 0.9985
------------------------------------------------------------------
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(100, activation='relu', kernel_initializer = 'he_uniform'),
keras.layers.Dense(50, activation='relu', kernel_initializer = 'glorot_uniform'),
keras.layers.Dense(10, activation='sigmoid')
])
model.compile(
optimizer = 'adam',
loss = 'sparse_categorical_crossentropy',
metrics = ['accuracy']
)
model.fit(X_test, y_test, epochs=10)
I have been following you from the ML Playlist , amazing content !! Thank you so much sir !
Its a great presentation !!! I appreciate your teaching method.
at 17:00, I came to know that sir also watches ' taarak mehta ka ulta chasma' :p
Hi Sir, your videos are so insightful and well managed.
Thanks for sharing this.
Glad you liked it Mayank
How come my training accuracy is much higher than yours when I have used the same dataset with the same neural network structure where everything is basically the same word-to-word.
My training accuracy for a simple two-layered neural network is 88%?
Sir, did you applied for H1B from India or from US itself via STEM( or OPT). And thank you for answering. 🤗
I applied from India in year 2006. At that time it was easy to come to USA on h1 directly. Nowadays that route is closed. So if you are planning to come to USA you have only two options (1) masters and than opt and h1b (2) you work in MNC and come here for client work on inter office transfer
@@codebasics thank you for sharing your experience. 😌😌
model = keras.Sequential(
[keras.layers.Flatten(input_shape=(28,28)),
keras.layers.Dense(300, activation='relu'),
keras.layers.Dense(10, activation='relu'),
keras.layers.Dense(10, activation='sigmoid')]
)
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(X_train, y_train, epochs=5)
model.evaluate(X_test, y_test)
got 0.9788 accuracy.
My suggestion to grasp this video concept is first to watch the whole video with patience then the second time watch again and apply the mentioned concepts line by line. Believe me, you are not going to forget what you have just learned.
That's a good tip Shamir
exhilarating to see the inner workings of deep learning! thank you sir
How can I build canvas allowing user to write digit on it and predict using our built model ?
It is possible. You need to use any UI framework for this which allows canvas drawing. Try researching that either in react ja, Vue Js or in general html, css
When we train the model, for each epoch, it shows 1/1875, 2/1875.....,1875/1875. what is the significance of 1875? Perhaps I missed it in the video :(
acuraccy 99.51% - epochs: 8, optimizer: Adam, loss: spacse-categorical_crossentropy, hidden layer neurons number: 300
There are several data science tutorials which are single-video of the entire series in one and really good to learn the entire data science (ML, DL etc) at once. I recommend you learn DS from those tutorials and then come back and start again with these videos. You will realize the remarkable depth covered in short videos which will strengthen your understanding of the subject in a great way. If you start with these as your first set of videos, you will still get all the learning but you will probably not pay attention to the details that these videos bring in. This is my personal opinion and your discretion is advised
Hi When I am trying to print confusion matrix it is not showing the matrix. Instead it is showing below details. Can you please tell me how I can print the confusion matrix like yours.
> cm
>
I got accuracy = 0.9807 for test, and accuracy for training = 0.9962 by changing optimizer to SGD and neoron n hidden layer = 99, and epoche = 6
Hi...Thank you so much for your video. It's very understandable and clear. I tried this and able to achieve what is explained. I need one suggestion regarding same. Can we do same to recognize date and time. For example 2023/05/16 06:40:50..Can we create similar model to detect this. To achieve this we need to create dataset each digit and two symbols ("/" and ":") and train them or full numbers(date and time including) as one. Please suggest how to recognize full date and time.
Sir , I got error when the model.fit(x_train_flattened, y_train, epochs=5) method , the error is value error,input arrays should have the same numbers as target arrays. Found 10000 input sample and 60000 target sample
check your code on X_train_flattened
Dhaval sir if you can guide us the 7 class classification of facial emotion using CNN VGG16 architecture by making a video lecture ,it will be very very helpful
Amazing, I am completely new in the field but you explain in such a good manner. 10+ out of 10 stars.
I have done exercise with a small dataset all the samples are about 1797:
from sklearn.datasets import load_digits
from sklearn.model_selection import train_test_split
digits = load_digits()
X_train, X_test, y_train, y_test = train_test_split(digits.data, digits.target, test_size=0.2, random_state=42)
and then:
model = keras.Sequential([
keras.layers.Dense(100, activation='relu'),
keras.layers.Dense(10, activation='sigmoid')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(X_train, y_train, epochs=20)
i have just increased number of epochs which given me a very good result of accuracy
once again thank you
from #Afghanistan
I got best scores (0.98) from
Optimizers- rmsprop, ndam, adam
Metrics- sparse categorical accuracy, accuracy
the error at 24:40
can be solved by reshaping the single input as X_train_scaled[0].reshape(1,784),
because it is having problems in matrix multiplication so reshaping helped :)
Mc
This is the only lecture where I got a really great idea about neural network. I have seen many lectures no one explain each thing like you did. They just make the neural network
Sir has subscription of choochoo's story and golgappa girl 😂😂...BTW awesome tutorial sir..many many thanks
Attribute Error: module 'keras.api._v2.keras' has no attribute 'compile'
I'm getting this error.
Anyone pls help
Hi Sir, thank you for your useful videos. I am getting this error "NameError: name 'Keras' is not defined" when I try to classify the datasets into training and test datasets. How can I solve it, please?
when I tried to visualize the cm following your code I got back this error, ValueError: Must pass 2-d input. shape=()
Any suggestions?
Hello sir,
I am doing same steps but after creating NN i am getting loss as 5.8,5.6,5.4 etc in epochs. And while evaluating xtest flattened its showing [0.0,0.0]
i am confused what the purpose of the training was for? becuase if you write the "y_test[0]", it already knows 7, could someone explain?
Thanks in advance
You are an absolutely amazing teacher! Thank you for the great content
Thank you Sir. İ would like to one question.How you train only 1875 samples. With the same codes ,I m train 60000 samples.
i have tried to copy your exact process but for my heat-map digits are only visible in first row and other rows are blank could you explain reason behind this unexpected behaviour?
Hello Sir, this is amazing code walk through with very very good explanation.
At 23:23 accuracy improved due to scaling. Is the accuracy improvement because our activation is sigmoid? Did Gradient descent algorithm found a local minima which was not low enough?
model.evaluate(X_test_flattened, y_test) when I run this command, I find out some error named ValueError
ValueError: Unknown metric function: accuary. Please ensure this object is passed to the `custom_objects` argument.
what is that? when i fit model @codebasics
my kernel gets dead while running this code even I have 12gb of ram, how much Ram is required to run this....anyone pls
Have increased number of Neurons for my hidden layer than accuracy is very much improved as 0.9915
Hloo sir when i do it it says that 'module 'keras.api._v2.keras' has no attribute 'sequrntial' i dont know y , i also imported from keras import sequential
I have run the same model code without scaling on the kaggle accuracy was 88%.how did it happen codebasics?.
Hi thanks for all; @codebasics
In my computer %matplotib inline dos'n working
what can i do ?
Sir, suppose we give a test image with 2 digits number then how to classify them as unknown class?
Please help with the code
Actually, I solved the kaggle question using this method but the accuracy was very low.
without scaling my model was giving accuracy aroung 83% and after scaling it got reduced to 9%😂
Sir, Create a video on hyperparameter tuning in deep learning like layers, activation function,etc.
Can someone help me to understand how output of neuron like .2, .4,.8,.9 compared with output which is no 4.
originally are those binary images or colored image, in the exmple you explained black and white images but when you show image in the note book images look like coloured
Hello sir,
I got 88% accuracy in model. But x_train and x_test do not match 😐
What can I do?
Yet another awsome tutorial sir.Waiting for more out of this playlist.And i have a doubt,If i have my own hand written digit on a paper then how can test with this ? should i crop the image and predict it ? thank you
Yes you need the crop the image and then predict
hello sir i have got everything perfect except the confusion matrix ,where all the values are null except first row
Sir, Please make a video on BiGAN from scratch along with python code
The model doest work when I take outside image using cv2 and try to figure out even black and white handwriting
Brilliant! This was great. Thank you.
You're god for the Beginner !!! The way you explain is way different than anyone else... SUPER AMAZING... HIGHLY RECOMMENDED
👍😊
which keyboard do you use ?
btw thanks for the amazing explanations
I took coursera and they had this in their instruction, but they didn't explain it so well. Thanks