Python Neural Networks - Tensorflow 2.0 Tutorial - Loading & Looking at Data
Key Takeaways
This video tutorial covers the basics of loading and looking at data using TensorFlow 2.0 and the Keras API, specifically with the Fashion MNIST dataset for image classification. It demonstrates how to install necessary libraries, load the dataset, split data into training and testing sets, and visualize the data using matplotlib.
Full Transcript
hey guys and welcome to the second video in the neural network tutorial series now in today's video what we're gonna be doing is actually getting our hands dirty and working with a bit of code and loading in our first data set so we're not actually gonna do anything with the model right now we're gonna do that in the next video this video is gonna be dedicated to understanding data the importance of data how we can scale that data look at it and understand how that's going to affect our model when training the most important part of machine learning at least in my opinion is the data and it's also one of the hardest things to actually get done correctly training the model and testing the model and using it is actually very easy and you guys will see that as we go through but getting the right information to our model and having it in the correct form is something that is way more challenging than it may seem with these initial data sets that we're gonna work with things are gonna be very easy because the data sets are gonna be given to us but when we move on into future videos to using our own data we're gonna have to pre-process it we're gonna have to put it in its correct form we're gonna have to send it into an array I'm gonna have to make sure that the data makes sense that we're not adding things that shouldn't be there or we're not omitting things that need to be there so anyways I'm just gonna quickly say here that I am kind of working off of this tensorflow 2.0 tutorial that is on tensorflow website now I'm kind of gonna stray from it quite a bit to be honest but I'm just using the data sets that they have and a little bit of the code that they have here because it's a very nice introduction to machine learning and neural networks but there's a lot of stuff in here that they don't talk about and it's not very in-depth so that's what I'm can I get to be adding and the reason why maybe you'd want to watch my version of this as opposed to just reading this off the website because if you have no experience with neural networks it is kind of confusing some of the stuff they do here and they don't really talk about why they use certain things or whatnot so anyways the data set we're gonna be working with today is known as the fashion m-miss data set so you may have heard of the old does so which is image image classification but it was like digits so like you had digits from 0 to 9 and the neural network about classified digits this one's a very similar principle except we're gonna be doing it with like t-shirts and pants and what do you call it sandals and all that so these are kind of some examples what the images look like and we'll be showing them as well in the code so that's enough about it I felt like I should tell you guys that the first thing that we're gonna be doing before we can actually start working with tensor flow is we obviously need to install it now actually maybe I'll grab the install command here so I'll have to copy it but this is the install command for tensor flow 2.0 so I'm just gonna copy here link will be in the description as well as on my website and you can see pink pip install - Q tensor flow equals equals 2.0 point OH - alpha zero now I already have this installed but I'm gonna go ahead and hit enter anyways and the - Q I believe just means don't give any output when you're installing so if this runs and you don't see any output whatsoever then you have successfully installed tensorflow 2.0 now I ran into an issue where I couldn't install it because I had a previous version of numpy installed in my system so if for some reason this doesn't work and there's something with numpy I would just PIP uninstall numpy and reinstall so do pip uninstall numpy like that I'm always not gonna run that but if you did that and then you tried to reinstall town flow 2.0 that should work for you and it should actually install its own version of the most updated version of numpy now another thing we're going to install here is going to be matplotlib now matplotlib is a nice library for just graphing and showing images and different information that we'll use a lot through this series so let's install that I already have it installed but go ahead and do that and then finally we will install pandas which we may be using in later videos in the series so I figured we might as well install it now so pip install pandas and once you've done that you should be ready to actually go here and start getting our data loaded in and looking at the data so I'm just gonna be working on sub line text and executing my Python files from the command line just because this is something that will work for everyone no matter what but feel free to work in ideally feel for you to work in pi tram as long as you understand how to set up your environment so that you have the necessary packages like tensorflow and all that then you should be good to go so let's start by importing tensorflow so import tensorflow as TF like that I don't know why it always short forms when I try to do this but anyways we're gonna import or actually sorry from tensorflow will import Kara's now Kara's is an API for tensorflow which essentially just allows us to write less code it does a lot of stuff for us like you'll see when we set up the model we use Kara's and it'll be really nice and simple and just like a high-level API and that's the way that they describe it that makes things a lot easier for people like us that aren't going to be defining our own tensors and writing our own code from scratch essentially now another thing we need to import is numpy so we're gonna say import if I could get this here import numpy as NP and finally we will import matplotlib so mat plot lib in this case dot pie plot as p ot and this again is just going to allow us to graph some things here all right so now what we're gonna do is we're actually gonna get our data set loaded in so the way that we can load in our data set is using care ass so to do this I'm just gonna say data equals in this case Kara's dot data sets dot fashion underscore m-miss and this is just the name of the data set there's a bunch of other data sets inside of Kara's that we will be using in the future now whenever we have data it's very important that we split our data into testing and training data now you may have heard this you talked about this in the previous Michigan learning tutorials I did but essentially what you want to do with any kind of machine learning algorithm especially a neural network is you don't want to pass all of your data into the network when you train it you want to pass about 90 80% of your data to the network to train it and then you want to test the network for accuracy and making sure that it works properly on the rest of your data that it hasn't seen yet now the reason you'd want to do this and a lot of people would say why don't I just give all my dad's the network could it make it better not necessarily and that's because if you test your data on if you test your network on data it's already seen then you can't be sure that it's not just simply memorizing the data it's seen right for example if you show me five images and then like you tell me the classes of all of them and then you show me that the same image again you say what's the class and I get it right well did I get it right because I figured out how to analyze the images properly or because I'd already seen it and I knew what it was right I just memorized what it was so that's something we want to try to avoid with our models so whenever we have our data we're gonna split it up into testing and training data and that's what we're gonna do right here so to do this I'm gonna say train in this case train underscore images and train understory labels combi in this case test underscore images comma test underscore and labels and then we say this is equal to data dot get underscore data so not get low done we're done now the reason we can do this is just because this load data method is gonna return information in a way where we can kind of split it up like this in most cases when you're writing your own models for your own data you're gonna have to write your own arrays and for loops and load and data and do all this fancy stuff but Chara's makes it nice and easy for us just by allowing us to write this line here which will get us our training and testing data in the for kind of variables that we need so quickly let me talk about what labels are now so for this specific data set there are 10 labels that means each image that we have will have a specific label assigned to it now if I actually I'll show you by just printing out if I print for example train underscore labels and let's just print like the 0 if I guess the first training label so let me just run this file so python tutorial 1 you can see that we simply get the number 9 now this is just what is represent like the label representation so obviously it's not giving us a string but let's say if I pick for example 6 and I hit enter here you can see that the label is 7 so the labels are between 0 & 9 so 10 labels in total now the thing is that's not very useful to us because we don't really know what label 0 is will label 9 is so what I'm gonna do is create a list that will actually define what those labels are so I'm gonna have to copy it from here because I actually don't remember the labels but you can see it says here what they are so for example label 0 is a t-shirt label 1 is a trouser 9 is an ankle boot and you can see what they all are so we just need to define exactly this list here so class names so that we can simply take whatever value is turn to us from the model of what label it thinks it is and then just throw that as an index to this list so we can get what label this alright sweet so that is how we're getting the data now so now I want to show you what some of these images look like and talk about the architecture of the neural network we might use in the next video so I'm gonna use PI plot just to show you some of these images and explain kind of the input and the output and all that so if you want to show an image using matplotlib you can do this by just doing PLT imshow and then in here simply putting the image so for example if i do train not labels images and let's say we do the seventh image and then I do PLT dot show if I run this now you guys will see what this image is so let's run this and you can see that we get this is actually I believe like a pullover or a hoodie now I know it looks weird and you've got all this like green and purple that's just because of the way that kind of matplotlib shows these images if you want to see it properly what you do is I believe you do see map equals in this case PLT dot see it I think it's like cm de binary or something I gotta have a look here because I forget yeah CM binary so if we do this and now we decide to display the image it should look a little bit better let's see here and there you go we can see now we're actually getting this like black and white kind of image now this is great and all but let me show you actually what our image looks like so like how was I just able to show like how was I just able to do this image well the reason I'm able to do that is because all of our images are actually a raise of 28 by 28 pixels so let me print one out for you here so if I do train underscore images let's do seven the same example here and print that to the screen I'll show you what the data actually looks like give it a second and there we go so you can see this is obviously what our data looks like it's just a bunch of lists so one lists for each row and it just has pixel values and these pixel values are simply representative of I believe like how much I don't actually know the scale that they're on but I think it's like an RGB value but in grayscale right so for example we have like zero 2:255 we're 255 is black and zero is white and I'm pretty sure that's how getting me information in someone can correct me if I'm wrong but I'm almost certain that that's how this actually works so this is gray Knoll but this is these are large numbers and remember I was saying before in the previous video that's typically a good idea to shrink our data down so that it's with it within a certain range that is a bit smaller so in this case what I'm actually going to do is I'm gonna modify this information a little bit so that we only have each value out of one so we instead of having no 255 we have it out of one so the way to do that is to divide every single pixel value by 255 now because these trained images are actually stored in what's known as a numpy array we can simply just divide it by 255 to achieve that so we'll say trained images equals trained images / 255 and we'll do the same thing here with our test images as well now obviously we don't have to modify the labels as well also because they're just between 0 & 9 and that's how the labels work but for our images we're going to divide those values so that it's a bit nicer so now let me show you what it looks like so if I go python tutorial 1 del pine and now you can see that we're getting these decimal values and that our shirt looks well the same but exactly like we've just shrunk down our data so it's gonna be easier to work with in the future with our model now that's about it I think that I'm gonna show you guys in terms of this data now we have our data loaded in and we're pretty much ready to go in terms of making a model now if you have any questions about the data please don't hesitate to leave a comment down below but essentially again the way it works is we're gonna have 28 by 28 pixel images and they're gonna come in as an array just as I've showed you here so these are all the values that we're gonna have we're gonna pass that to our model and then our model is gonna spit out what class it thinks it is and those classes are gonna be between 0 & 9 obviously 0 is gonna represent a t-shirt where 9 is gonna represent ankle boots and we will deal with that all in the next video so with that being said I hope you guys enjoyed if you did please make sure to leave a like and subscribe and I will see you in the next video [Music]
Original Description
This python tensorflow 2.0 tutorial covers how to load in the MNIST Fashion dataset that our neural network will use for image classification in future videos. We can load the data set quite easily by using the keras API provided by tensorflow. We will then use matplotlib to view our data.
Playlist: https://www.youtube.com/watch?v=OS0Ddkle0o4&list=PLzMcBGfZo4-lak7tiFDec5_ZMItiIIfmj
Tensorflow install: pip install -q tensorflow==2.0.0-alpha0
Text-Based Tutorial: https://techwithtim.net/tutorials/python-neural-networks/loading-data/
Tensorflow website: https://www.tensorflow.org/alpha/tutorials/keras/basic_classification
Want a sneak peak into my life? Follow my Instagram @tech_with_tim where I'm going to be filming a video each morning sharing my goals for the day and what I have planned:
https://www.instagram.com/tech_with_tim
◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python
https://tech-with-tim.teachable.com/p...
📸 Instagram: https://www.instagram.com/tech_with_tim
🌎 Website https://techwithtim.net
📱 Twitter: https://twitter.com/TechWithTimm
⭐ Discord: https://discord.gg/pr2k55t
📝 LinkedIn: https://www.linkedin.com/in/tim-rusci...
📂 GitHub: https://github.com/techwithtim
🔊 Podcast: https://anchor.fm/tech-with-tim
💵 One-Time Donations: https://www.paypal.com/donate/?token=...
💰 Patreon: https://www.patreon.com/techwithtim
◾◾◾◾◾◾
⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡
Tags:
- Tech With Tim
- Tensorflow Tutorial
- Python tensorflow 2.0 tutorial
- Python neural network turtorial
- Python Tutorials
- Keras MNIST
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tech With Tim · Tech With Tim · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: LLM Foundations
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Want to get started with deep learning
Reddit r/deeplearning
Building a Deepfake Detector From Scratch — What Nobody Tells You
Medium · Deep Learning
Unfolding the Meandering Path: High-Dimensional Invariance and the Flat 2D Plane of Neural…
Medium · Deep Learning
Implementing Neural Style Transfer from Scratch: The Project That Started It All
Medium · Deep Learning
🎓
Tutor Explanation
DeepCamp AI