Last active
February 19, 2019 15:35
-
-
Save rafalpronko/fe299ca46248273f0a3b72ea2609694f to your computer and use it in GitHub Desktop.
This file contains 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
%%time | |
for e in range(10): | |
# define the loss value after the epoch | |
losss = 0.0 | |
number_of_sub_epoch = 0 | |
# loop for every training batch (one epoch) | |
for images, labels in train_loader: | |
#create the output from the network | |
out = modelpy(images) | |
# count the loss function | |
loss = criterion(out, labels) | |
# in pytorch you have assign the zero for gradien in any sub epoch | |
optim.zero_grad() | |
# count the backpropagation | |
loss.backward() | |
# learning | |
optim.step() | |
# add new value to the main loss | |
losss += loss.item() | |
number_of_sub_epoch += 1 | |
print("step {}: loss: {}".format(e, losss / number_of_sub_epoch)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment