def imshow_unscaled(target, return_im=False): np_target = target np_target_scaled = np.clip(((np_target + 1) / 2.0) * 256, 0, 255) im = np.concatenate(np_target_scaled, axis=0) image.imshow(np.uint8(im)) if return_im: return im
from torch.autograd import Variable from config import MODEL_PATH from models.model import Net, classes from data import loadTestData from utils.image import imshow testset, testloader = loadTestData() net = Net() net.load_state_dict(torch.load(MODEL_PATH)) dataiter = iter(testloader) images, labels = dataiter.next() # print images imshow(torchvision.utils.make_grid(images)) print('GroundTruth: ', ' '.join('%5s' % classes[labels[j]] for j in range(4))) outputs = net(Variable(images)) _, predicted = torch.max(outputs.data, 1) print('Predicted: ', ' '.join('%5s' % classes[predicted[j][0]] for j in range(4))) class_correct = list(0. for i in range(10)) class_total = list(0. for i in range(10)) for data in testloader: images, labels = data outputs = net(Variable(images)) _, predicted = torch.max(outputs.data, 1)
targets = [] s = slice(batch_start, min(num_samples, batch_start + batch_size)) input_test = {y: ys[s], z: zs[s], truncation: trunc} out_input_test = sess.run(outputs_orig, input_test) for i in range(a.shape[0]): target_fn, mask_out = get_target_np(out_input_test, a[i]) alpha_val_for_graph = np.ones((zs[s].shape[0], Nsliders)) * np.log(a[i]) best_inputs = {z: zs[s], y: ys[s], truncation: trunc, alpha: alpha_val_for_graph, target: target_fn, mask: mask_out} best_im_out = sess.run(transformed_output, best_inputs) # collect images ims.append(np.uint8(np.clip(((best_im_out + 1) / 2.0) * 256, 0, 255))) targets.append(np.uint8(np.clip(((target_fn + 1) / 2.0) * 256, 0, 255))) im_stack = np.concatenate(targets + ims).astype(np.uint8) imshow(imgrid(im_stack, cols = len(a))) # plot losses import matplotlib.pyplot as plt plt.plot(loss_vals) plt.xlabel('num samples, lr{}'.format(lr)) plt.ylabel('Loss') plt.show()