Minimal tutorials for PyTorch adapted from Alec Radford's Theano tutorials.
Minimal tutorials for PyTorch
Overview
Comments
-
Py36 fix
Hi,
This is related to #3 changes to make these scripts work for Python 3.x.
I tested these changes with
Anaconda Python 3.6
.Hope this helps.
Thanks.
-
About CrossEntroyLoss
The pytorch document shows:
class torch.nn.CrossEntropyLoss(weight=None, size_average=True)[source] This criterion combines LogSoftMax and NLLLoss in one single class.
SO could I remove
softmax
layer from the model sequential?model.add_module("softmax", torch.nn.Softmax())
-
Including Multiple Independent Variable in Linear Model
Hi Vinh Khuc,
Thanks for creating this wonderful tutorial for pytorch. I was trying your examples to learn pytorch. For linear regression, I was trying a variant so that I understand better the inner working of pytorch. So, instead of using single independent variable, I'm using multiple independent variable (2 Xs, X1 and X2). I created them as following in the
training
function. Rest of the code is exactly the same as you have created.X1 = torch.linspace(-2, 2, 101) X2 = torch.linspace(-1, 1, 101) X = torch.cat(([X1, X2])).resize_(100,2)
But when I'm using
batch_size = 10
, I'm getting the following error:RuntimeError Traceback (most recent call last)
in () 4 for k in range(num_batches): 5 start, end = k * batch_size, (k + 1) * batch_size ----> 6 cost += train(model, loss, optimizer, X[start:end], Y[start:end]) 7 print("Epoch = %d, cost = %s" % (i + 1, cost / num_batches)) 8 in train(model, loss, optimizer, x, y) 7 8 # Forward ----> 9 fx = model.forward(x.view(len(x), 1)) 10 output = loss.forward(fx, y) 11 C:\Program Files\Anaconda3\lib\site-packages\torch\autograd\variable.py in view(self, *sizes) 466 467 def view(self, *sizes): --> 468 return View.apply(self, sizes) 469 470 def view_as(self, tensor):
C:\Program Files\Anaconda3\lib\site-packages\torch\autograd_functions\tensor.py in forward(ctx, i, sizes) 87 ctx.new_sizes = sizes 88 ctx.old_size = i.size() ---> 89 result = i.view(*sizes) 90 ctx.mark_shared_storage((i, result)) 91 return result
RuntimeError: size '[10 x 1]' is invalid for input of with 20 elements at D:\Downloads\pytorch-master-1\torch\lib\TH\THStorage.c:59
So, I'm not understanding, why I'm getting this error. If you could guide me then it will be a great help to me.
Thank you!
-
Minor changes for Python 3.x compatibility
Hi there,
Thanks for sharing this great set of tutorials. I made a few tiny changes to make it work for Python 3.x. Would you be interested in a pull request?
Changes:
- use integer division for calculating minibatch size
- use
urllib.reqeust.urlretrieve()
if python major version is > 2 - download MNIST files if any of the data files is missing, instead of just checking folder existence.
Thanks.
-
Replace .next() with next() for py3 compatibility
In Python3:
AttributeError Traceback (most recent call last) <ipython-input-16-dc3a6e32cc0b> in <module>() 1 ----> 2 w = model.parameters().next().data # model has only one parameter AttributeError: 'generator' object has no attribute 'next'
next() works in python 2 and python 3. .next() only works in python 2.
-
GPU versions of example 3 to 6
Hi @vinhkhuc ,
Would you be interested in a PR for the cuda version of these 4 models? I made some simple modifications to make them work on GPUs, while trying to preserve the flow of the original non-GPU versions.
Example 1 & 2 probably doesn't need a GPU version since they train quite fast anyway.
Thx
C++ Implementation of PyTorch Tutorials for Everyone
C++ Implementation of PyTorch Tutorials for Everyone OS (Compiler)\LibTorch 1.9.0 macOS (clang 10.0, 11.0, 12.0) Linux (gcc 8, 9, 10, 11) Windows (msv
Simple PyTorch Tutorials Zero to ALL!
PyTorchZeroToAll Quick 3~4 day lecture materials for HKUST students. Video Lectures: (RNN TBA) Youtube Bilibili Slides Lecture Slides @GoogleDrive If
PyTorch tutorials and best practices.
Effective PyTorch Table of Contents Part I: PyTorch Fundamentals PyTorch basics Encapsulate your model with Modules Broadcasting the good and the ugly
A set of examples around pytorch in Vision, Text, Reinforcement Learning, etc.
PyTorch Examples WARNING: if you fork this repo, github actions will run daily on it. To disable this, go to /examples/settings/actions and Disable Ac
Deep Learning (with PyTorch)
Deep Learning (with PyTorch) This notebook repository now has a companion website, where all the course material can be found in video and textual for
Open source guides/codes for mastering deep learning to deploying deep learning in production in PyTorch, Python, C++ and more.
Deep Learning Materials by Deep Learning Wizard Start Learning Now Please head to www.deeplearningwizard.com to start learning! It is mobile/tablet fr
Simple examples to introduce PyTorch
This repository introduces the fundamental concepts of PyTorch through self-contained examples. At its core, PyTorch provides two main features: An n-
PyTorch Tutorial for Deep Learning Researchers
This repository provides tutorial code for deep learning researchers to learn PyTorch. In the tutorial, most of the models were implemented with less
PyTorch Implementation of Fully Convolutional Networks. (Training code to reproduce the original result is available.)
pytorch-fcn PyTorch implementation of Fully Convolutional Networks. Requirements pytorch >= 0.2.0 torchvision >= 0.1.8 fcn >= 6.1.5 Pillow scipy tqdm
Pytorch implementations of various Deep NLP models in cs-224n(Stanford Univ)
DeepNLP-models-Pytorch Pytorch implementations of various Deep NLP models in cs-224n(Stanford Univ: NLP with Deep Learning) This is not for Pytorch be
A scalable template for PyTorch projects, with examples in Image Segmentation, Object classification, GANs and Reinforcement Learning.
PyTorch Project Template is being sponsored by the following tool; please help to support us by taking a look and signing up to a free trial PyTorch P
Some example scripts on pytorch
pytorch-practice Some example scripts on pytorch CONLL 2000 Chunking task Uses BiLSTM CRF loss with char CNN embeddings. To run use: cd data/conll2000
Example of network fine-tuning in pytorch for the kaggle competition Dogs vs. Cats Redux: Kernels Edition
Example of network fine-tuning in pytorch for the kaggle competition Dogs vs. Cats Redux: Kernels Edition Currently
ConvNet training using pytorch
Convolutional networks using PyTorch This is a complete training example for Deep Convolutional Networks on various datasets (ImageNet, Cifar10, Cifar
simple generative adversarial network (GAN) using PyTorch
Generative Adversarial Networks (GANs) in PyTorch Running Run the sample code by typing: ./gan_pytorch.py ...and you'll train two nets to battle it o
Torch Containers simplified in PyTorch
pytorch-containers This repository aims to help former Torchies more seamlessly transition to the "Containerless" world of PyTorch by providing a list
The Hitchiker's Guide to PyTorch
The Hitchiker's Guide to PyTorch
Minimal diffusion models - Minimal code and simple experiments to play with Denoising Diffusion Probabilistic Models (DDPMs)
Minimal code and simple experiments to play with Denoising Diffusion Probabilist
The Incredible PyTorch: a curated list of tutorials, papers, projects, communities and more relating to PyTorch.
This is a curated list of tutorials, projects, libraries, videos, papers, books and anything related to the incredible PyTorch. Feel free to make a pu
Simple tutorials on Pytorch DDP training
pytorch-distributed-training Distribute Dataparallel (DDP) Training on Pytorch Features Easy to study DDP training You can directly copy this code for