def main(args): batch_size = 128 ds_train, ds_test, info = load_data(batch_size) image_shape = info.features["image"].shape image_size = tf.reduce_prod(image_shape) num_train_samples = info.splits["train"].num_examples num_test_samples = info.splits["test"].num_examples cnn = Cnn() if "init_model" in args.cnn_mode: cnn.create_model(batch_size=batch_size, image_shape=image_shape, feature_outputs=int(100)) if "train" in args.cnn_mode: cnn.train(ds_train, ds_test, epochs=10, steps_per_epoch=int(num_train_samples / batch_size)) if "save" in args.cnn_mode: cnn.save() if "load" in args.cnn_mode: cnn.load_combined_model() if "test" in args.cnn_mode: cnn.test(ds_test) gp = DeepKernelGP(ds_train, num_train_samples, image_size, 10, cnn.feature_extractor, num_inducing_points=100) if "train" in args.gp_mode: gp.train(10000) if "test" in args.gp_mode: gp.test(ds_test, image_size, batch_size, num_test_samples)
trainingLoss.append(trainLoss) #prints if weights are unchanged weights2 = [] unchangedWeights = 0 for param in cnn.parameters(): weights2.append(param.clone()) for i in zip(weights1, weights2): if torch.equal(i[0], i[1]): unchangedWeights += 1 if unchangedWeights > 0: print(unchangedWeights, "of", len(weights1), "Weights Unchanged") print("Testing") testAcc, testLoss = cnn.test(testImgs, testOneHotVecs, cfg.testBatchSize) testingAccuracy.append(testAcc) testingLoss.append(testLoss) #plots accuracy plt.plot(epochs, trainingAccuracy, label="Training Accuracy", color="green") plt.plot(epochs, testingAccuracy, label="Testing Accuracy", color="blue") plt.plot(epochs, [1 / numSubjects] * cfg.epochs, label="Blind Guessing Accuracy", color="purple") plt.xlabel("epochs") plt.ylabel("Accuracy (Decimal)")