history = model.fit(x=X_train, y=y_train, verbose=2, epochs=3, batch_size=32, validation_split=0.1, callbacks=[early_stopping, save_model]) digit_test = pd.read_csv(os.path.join(path, "test.csv")) digit_test.shape digit_test.info() X_test = digit_test.values.astype('float32') / 255.0 X_test = X_test.reshape(X_test.shape[0], 28, 28, 1) digit_test['Label'] = np.argmax(model.predict(X_test), axis=1) digit_test['ImageId'] = list(range(1, X_test.shape[0] + 1)) digit_test.to_csv(os.path.join(path, "submission.csv"), index=False, columns=['ImageId', 'Label']) index = digit_test[digit_test.Label == 5] print(index.head()) act = kutils.get_activations(model, X_test[23:24]) kutils.display_activations(act, directory=os.path.join(path, 'digit_activations'), save=True) kutils.display_heatmaps(act, X_test_images[0:1], directory=os.path.join(path, 'digit_heatmaps'), save=True)
callbacks=[save_weights, early_stopping]) kutils.plot_loss_accuracy(history) test_datagen = ImageDataGenerator(rescale=1. / 255) test_generator = test_datagen.flow_from_directory(test_dir, target_size=(img_width, img_height), batch_size=batch_size, class_mode=None, shuffle=False) tmp = next(test_generator) act = kutils.get_activations(model, tmp[0:1]) # with just one sample. kutils.display_activations(act, directory=os.path.join("D:/cats vs dogs", 'digit_activations'), save=True) kutils.display_heatmaps(act, tmp[0:1], directory=os.path.join("D:/cats vs dogs", 'digit_heatmaps'), save=True) #print(test_generator.filenames) probabilities = model.predict_generator(test_generator, nb_test_samples // batch_size) mapper = {} i = 0 for file in test_generator.filenames: id = int(file.split('\\')[1].split('.')[0])