Minimal tutorials for PyTorch adapted from Alec Radford's Theano tutorials.
vinhkhuc / pytorch-mini-tutorials Goto Github PK
View Code? Open in Web Editor NEWMinimal tutorials for PyTorch
Minimal tutorials for PyTorch
Minimal tutorials for PyTorch adapted from Alec Radford's Theano tutorials.
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
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))
8in train(model, loss, optimizer, x, y)
7
8 # Forward
----> 9 fx = model.forward(x.view(len(x), 1))
10 output = loss.forward(fx, y)
11C:\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 resultRuntimeError: 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!
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())
doing .forward I believe is not recommended because it doesn't end up using masks or handle or something like that I forget...just heads up
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:
urllib.reqeust.urlretrieve()
if python major version is > 2Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.