PyTorch vs. TensorFlow - DataLoader example

Connor Shorten · Beginner ·🧬 Deep Learning ·5y ago

Key Takeaways

PyTorch and TensorFlow's custom data loaders are compared, highlighting similarities in syntax and functionality, with PyTorch having a single standard way of loading data and TensorFlow having multiple methods.

Full Transcript

throughout these keras code examples i want to highlight instances where it's clear to me where there isn't as much of a large difference between pi torch and tensorflow i know this is a tough decision for many people for me as well it's been tough having to kind of learn pi torch as well as tensorflow and keras but once you kind of get to learn more you you know that it's really doing the same thing it just has a slightly different syntax so in this first video i want to show how pytorch and tensorflow custom data loaders are actually really similar in syntax probably the big difference to me is that tensorflow has many ways of doing this whereas i think pi torch has more of a single standard way of doing this so this is the functionality of pi torch that originally attracted me to switch from keras to pi torch is i really like how easy it is to load a data set and then add some custom pre-processing so in my personal experiments this is manifested in my testing with supervised contrastive learning this is where we load our data set and then we sample a given positive image and then we want to go find a corresponding another positive pair from that same data set so say we sample a cat from cfar 10 we want to go find another cat from cfr 10. this is how we do the supervised contrastive learning task so i really like this functionality that's available with git item in the pi torch dataset class so the question then is how do you do this in chaos in tensorflow and how different is this syntax really you know making these pi torch and keras such different things to learn but so going through these chaos examples i've seen some cases uh so this is an example of the semantic segmentation example from chaos examples where you have this same exact syntax it's just called a keras that utils does sequence so this is one kind of syntax in keras that basically exactly mimics this dataset loader in pi torch but as i mentioned previously there's kind of like a lot of ways to load data sets in tensorflow and keras and i think this makes it more confusing i think this is how it confuses people and people like the simplicity of pi torch at least for this one example so this is just one small case the data set loader of a difference between pi torch and tensorflow throughout this series i'll be trying to find more of these examples where they're really not so dissimilar again this is keras you see initializer length get item and then and this is pi torch this is really the same exact thing so then again so in tensorflow and keras they seem to have a lot of different ways of doing this this is an example of how you pipeline data from a directory that's stored in a file system and folders and then this is another example where you've uh you've loaded the data set into memory and now you turn it into a data object using from tensor slices and now here's the key difference in this syntax instead of doing the logic in this get item function you apply the custom processing to the data set by chaining on dot map and then giving it some function to do with each input sample and its label so in this case train pre-processing it takes in a volume because we're using three-dimensional ct scan classification but it doesn't matter at all what what exactly the data is it could be a text sequence or it could be just a regular rgb image and it applies some processing and it returns a processed volume label so another thing about a pi torch is once you define your data loader and you instantiate it by having say train loader equals torch.utils.edu.dataloader and then this custom train set that we just overwrit with our i think this is called super classic i'm not exactly sure but we see how we inherit the functionality of this dataset class from pi torch and then we write in our own custom logic define an instance of it and now something that i know a lot of people like about pytorch and it's built right into the right as you start off with pi torch they give you a c far 10 example and they show you how to do this visualization of the data set and i just think these these core examples like the start here examples are huge for how people generally not you know not like the super experts who already know exactly what to do but most people who are who are still torn between pi torch or tensorflow like these little examples that help them see how to do certain things so this is how you iterate and sample a batch from this trader train loader you do data editor equals iterator train loader and then dot next but in keras and tensorflow you have the exact same syntax the only difference is that it's slightly different this is when you have a tf.data object you just do take one same exact idea as pipelining this with dot next thanks for watching this quick overview of how the dataset loaders are similar in pi torch as well as tensorflow and keras i hope that videos like this will help people to not feel like i'm isolating them if you've if you're currently working with pytorch and you feel like these keras code examples are isolating you and your tool set i hope that these examples can show you how there's a lot of similarity between these frameworks and learning pytorch will improve your tensorflow skills it won't like hurt it or negatively cause you to say memorize all these things and then overwrite the syntax you memorize for the other language because you know there's a lot of insane similarities between the two so thanks for watching and please check out the chaos code example series if you haven't already

Original Description

I hope the Keras code series isn't off putting to people working with PyTorch! These videos will be interleaved throughout the Keras Code Examples to showcase similarities between the frameworks and show you how to leverage these Keras examples to improve your PyTorch skills if that's your framework of choice. Please let me know any other examples where you would like a translation from TensorFlow to PyTorch or vice versa! (Sorry no Jax haha) Links: PyTorch custom dataloader: https://pytorch.org/tutorials/beginner/data_loading_tutorial.html 3D image classification: https://keras.io/examples/vision/3D_image_classification/ image classification from scratch: https://keras.io/examples/vision/image_classification_from_scratch/ Image segmentation keras: https://keras.io/examples/vision/oxford_pets_image_segmentation/ Keras Examples: https://keras.io/examples/ Thanks for watching! Please subscribe and check out the rest of the Keras Code Examples playlist!
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Connor Shorten · Connor Shorten · 0 of 60

← Previous Next →
1 DenseNets
DenseNets
Connor Shorten
2 DeepWalk Explained
DeepWalk Explained
Connor Shorten
3 Inception Network Explained
Inception Network Explained
Connor Shorten
4 StackGAN
StackGAN
Connor Shorten
5 StyleGAN
StyleGAN
Connor Shorten
6 Progressive Growing of GANs Explained
Progressive Growing of GANs Explained
Connor Shorten
7 Improved Techniques for Training GANs
Improved Techniques for Training GANs
Connor Shorten
8 Word2Vec Explained
Word2Vec Explained
Connor Shorten
9 Must Read Papers on GANs
Must Read Papers on GANs
Connor Shorten
10 Unsupervised Feature Learning
Unsupervised Feature Learning
Connor Shorten
11 Self-Supervised GANs
Self-Supervised GANs
Connor Shorten
12 Embedding Graphs with Deep Learning
Embedding Graphs with Deep Learning
Connor Shorten
13 Transfer Learning in GANs
Transfer Learning in GANs
Connor Shorten
14 ReLU Activation Function
ReLU Activation Function
Connor Shorten
15 AC-GAN Explained
AC-GAN Explained
Connor Shorten
16 SimGAN Explained
SimGAN Explained
Connor Shorten
17 DC-GAN Explained!
DC-GAN Explained!
Connor Shorten
18 ResNet Explained!
ResNet Explained!
Connor Shorten
19 Graph Convolutional Networks
Graph Convolutional Networks
Connor Shorten
20 Neural Architecture Search
Neural Architecture Search
Connor Shorten
21 Henry AI Labs
Henry AI Labs
Connor Shorten
22 Video Classification with Deep Learning
Video Classification with Deep Learning
Connor Shorten
23 BigGANs in Data Augmentation
BigGANs in Data Augmentation
Connor Shorten
24 Introduction to Deep Learning
Introduction to Deep Learning
Connor Shorten
25 EfficientNet Explained!
EfficientNet Explained!
Connor Shorten
26 Self-Attention GAN
Self-Attention GAN
Connor Shorten
27 Curriculum Learning in Deep Neural Networks
Curriculum Learning in Deep Neural Networks
Connor Shorten
28 Deep Learning Podcast #1 | Edward Dixon | Stochastic Weight Averaging
Deep Learning Podcast #1 | Edward Dixon | Stochastic Weight Averaging
Connor Shorten
29 Deep Compression
Deep Compression
Connor Shorten
30 Skin Cancer Classification with Deep Learning
Skin Cancer Classification with Deep Learning
Connor Shorten
31 Deep Learning Podcast #2 | Edward Peake | Deep Learning in Medical Imaging
Deep Learning Podcast #2 | Edward Peake | Deep Learning in Medical Imaging
Connor Shorten
32 The Lottery Ticket Hypothesis Explained!
The Lottery Ticket Hypothesis Explained!
Connor Shorten
33 SqueezeNet
SqueezeNet
Connor Shorten
34 GauGAN Explained!
GauGAN Explained!
Connor Shorten
35 AutoML with Hyperband
AutoML with Hyperband
Connor Shorten
36 DL Podcast #3 | Yannic Kilcher | Population-Based Search
DL Podcast #3 | Yannic Kilcher | Population-Based Search
Connor Shorten
37 Weakly Supervised Pretraining
Weakly Supervised Pretraining
Connor Shorten
38 Image Data Augmentation for Deep Learning
Image Data Augmentation for Deep Learning
Connor Shorten
39 Unsupervised Data Augmentation
Unsupervised Data Augmentation
Connor Shorten
40 Wide ResNet Explained!
Wide ResNet Explained!
Connor Shorten
41 RevNet: Backpropagation without Storing Activations
RevNet: Backpropagation without Storing Activations
Connor Shorten
42 GANs with Fewer Labels
GANs with Fewer Labels
Connor Shorten
43 BigBiGAN Unsupervised Learning!
BigBiGAN Unsupervised Learning!
Connor Shorten
44 Self-Supervised Learning
Self-Supervised Learning
Connor Shorten
45 Multi-Task Self-Supervised Learning
Multi-Task Self-Supervised Learning
Connor Shorten
46 Self-Supervised GANs
Self-Supervised GANs
Connor Shorten
47 Population Based Training
Population Based Training
Connor Shorten
48 Show, Attend and Tell
Show, Attend and Tell
Connor Shorten
49 Siamese Neural Networks
Siamese Neural Networks
Connor Shorten
50 WaveGAN Explained!
WaveGAN Explained!
Connor Shorten
51 VAE-GAN Explained!
VAE-GAN Explained!
Connor Shorten
52 Evolution in Neural Architecture Search!
Evolution in Neural Architecture Search!
Connor Shorten
53 AI Research Weekly Update August 18th, 2019
AI Research Weekly Update August 18th, 2019
Connor Shorten
54 Weight Agnostic Neural Networks Explained!
Weight Agnostic Neural Networks Explained!
Connor Shorten
55 AI Research Weekly Update August 25th, 2019
AI Research Weekly Update August 25th, 2019
Connor Shorten
56 Neuroevolution of Augmenting Topologies (NEAT)
Neuroevolution of Augmenting Topologies (NEAT)
Connor Shorten
57 CoDeepNEAT
CoDeepNEAT
Connor Shorten
58 AI Research Weekly Update September 1st, 2019
AI Research Weekly Update September 1st, 2019
Connor Shorten
59 Randomly Wired Neural Networks
Randomly Wired Neural Networks
Connor Shorten
60 Genetic CNN
Genetic CNN
Connor Shorten

This video compares PyTorch and TensorFlow's custom data loaders, highlighting their similarities and differences, and demonstrates how to load and pre-process data in both frameworks.

Key Takeaways
  1. Import necessary libraries
  2. Load a dataset
  3. Define a custom data loader
  4. Apply pre-processing to the data
  5. Use the data loader to iterate over the dataset
💡 PyTorch and TensorFlow have similar data loading functionality, but PyTorch has a single standard way of loading data, while TensorFlow has multiple methods.

Related Reads

📰
I Found the Neural Network I Built in Class 9 — Here’s What Happened When I Tried to Run It Again
Revisiting a 4-year-old neural network project for handwritten digit recognition using a convolutional neural network and analyzing its performance
Medium · Deep Learning
📰
Introduction to Deep Learning and Neural Networks: From Human Brain to Artificial Intelligence
Learn how biological neurons inspired artificial neural networks and deep learning, transforming the AI landscape
Medium · Deep Learning
📰
Want to get started with deep learning
Get started with deep learning by leveraging resources like Andrew Karpathy's playlist and frameworks such as TensorFlow or PyTorch
Reddit r/deeplearning
📰
Building a Deepfake Detector From Scratch — What Nobody Tells You
Learn to build a deepfake detector from scratch and understand the challenges involved in detecting AI-generated fake media
Medium · Deep Learning
Up next
Image Classification with ml5.js
The Coding Train
Watch →