Hi All I have a function which get the value from a scale and feeds a randomly sampled image using iter(testloader).next()
to a network to perform testing. For the testing results, I print the testing time. Even though the iter(testloader).next()
command is known to sample one image at random, the results after testing shows three testing times instead of just one as can be seen below. I am really lost as to why that’s happening, and can’t tell if three images are sampled which makes the code prints 3 results instead of 1 after testing. Below is my sample code for review:
Testing time report after testing
Testing complete in 0m 2s
Testing complete in 0m 3s
Testing complete in 0m 3s
Below is my sample code
test= data_utils.TensorDataset(torch.from_numpy(test_set),torch.from_numpy(label_set))
test_loader = data_utils.DataLoader(test,batch_size=TestBatchSize,shuffle=True)
def noise_scale(scale_value=0):
since = time.time()
images, labels = iter(test_loader).next()
images = images.view(1, 10, 200, 301)
labels = labels.view(1, 1, 201, 301)
if (scale.get()) == 0:
for i in range(1):
net.eval()
outputs = net(images,labels)
for k in range(1):
Img = images.view(10, 200, 301)
Img = Img[1,:,:].numpy()
elif (scale.get()) == 10:
for i in range(1):
net.eval()
outputs = net(images,labels)
for k in range(1):
Img = images.view(10, 200, 301)
Img = Img[1,:,:].numpy()
elif (scale.get()) == 20:
for i in range(1):
net.eval()
outputs = net(images,labels)
for k in range(1):
Img = images.view(10, 200, 301)
Img = Img[1,:,:].numpy()
time_elapsed = time.time() - since
print('Testing complete in {:.0f}m {:.0f}s' .format(time_elapsed // 60, time_elapsed % 60))
## This above line prints three times as shown above instead of just one.
## Scale ##
var3 = StringVar()
scale = tk.Scale(root, variable=var3, orient='horizontal', bg = "gray80", bd=1, from_=0, to=20, tickinterval=10, resolution=10, length=200, command=noise_scale)