Created
February 21, 2019 18:57
-
-
Save ayoubbenaissa/9f53c24a244c01aec0b74ef3174cba08 to your computer and use it in GitHub Desktop.
pytorch tuto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = 100 | |
for epoch in range(n): | |
epoch +=1 | |
#convert numpy array into torch variable: | |
inputs = Variable(torch.from_numpy(x_train)) | |
labels = Variable(torch.from_numpy(y_train)) | |
#clear gradient w.r.t parameters: | |
optimizer.zero_grad() | |
#Forward: | |
outputs = model(inputs) | |
#calculate Loss: | |
loss = criterion(outputs, labels) | |
#getting gradient w.r.t parameters: | |
loss.backward() | |
#updating parameters: | |
optimizer.step() | |
print('epoch {}, loss {}'.format(epoch, loss.item())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment