plt.title('Dataset Images', fontsize=9) epoch_list = [6, 9, 12, 18, 29] for i in range(5): fig.add_subplot(2, 3, 2 + i) plt.imshow(model.list_thetas[epoch_list[i]]) plt.xticks([]), plt.yticks([]) plt.title('Transformed Images ' + str(epoch_list[i] + 1) + ' epochs', fontsize=9) fig.tight_layout() plt.show(fig) fig.savefig('stn_test.pdf', dpi=300) visualize_stn(model) temp = model.localization(tensor.cuda()) temp = temp.view(-1, model.n_units_stn) # Regress the transformation matrices theta = model.fc_loc(temp) theta = theta.view(-1, 1, 2) zoom = theta.narrow(2, 0, 1) rotation = theta.narrow(2, 1, 1) #print(theta) # We only allow for zooming in the trafo N_thetas = list(thetas.shape)[0] identity_tensor = Variable(torch.tensor([[[1.0, 0.0, 0.0],
Images.append(temp) #Load our pretrained CNN-Model model, logger, _ = import_classifier() # Construct dataset and dataloader with Images evaluationset = Evalset(Images) dataloader = DataLoader(evaluationset, batch_size=32, shuffle=True) use_gpu = torch.cuda.is_available() if not use_gpu: print("Warning! No CUDA available. This is untested!") if use_gpu: model.cuda() # Calculate the accuracy of the pretrained model on the data from the SVM accuracy = evaluate(model, dataloader, use_gpu=use_gpu) # Visualize the STN on sample images of SVM output if use_gpu: model.databatch = next(iter(dataloader))["tensor"].cuda() else: model.databatch = next(iter(dataloader))["tensor"].cuda() visualize_stn(model, filename="./Classifier/Plots/stn_gtsdb_output.pdf") print( "For the GTSDB dataset (full) we obtain a total accuracy of the STN+CNN classifier of : " + str(accuracy))