I am learning RNN with pytorch from this github.
I’m a little bit confused, because the code didn’t show result of the training. Only show the accuracy. Now I want to show image that output from model.
I try to save image from output, but the result I get is a compressed representation (below is the image I got from output of the model)
# Train the model
total_step = len(train_loader)
for epoch in range(num_epochs):
for i, (images, labels) in enumerate(train_loader):
images = images.reshape(-1, sequence_length, input_size).to(device)
labels = labels.to(device)
# Forward pass
outputs = model(images)
loss = criterion(outputs, labels)
# Backward and optimize
optimizer.zero_grad()
loss.backward()
optimizer.step()
if (i+1) % 100 == 0:
print ('Epoch [{}/{}], Step [{}/{}], Loss: {:.4f}'
.format(epoch+1, num_epochs, i+1, total_step, loss.item()))
I am trying to show the image of the output by adding this cod
plt.imshow(outputs.reshape(28, 28))
But I got this error
RuntimeError: shape '[28, 28]' is invalid for input of size 1000
So, I assume that the output is 1000 size. but I want it to show as a mnist image (784 size (28*28)).