model.add(Dropout(0.25)) model.add(BatchNormalization()) model.add(Dense(10, activation='relu')) # 10 digits classes model.compile(loss='cce', optimizer=opt) model.summary() model_epochs = 5 fit_stats = model.fit(train_data, one_hot(train_label), batch_size=128, epochs=model_epochs, validation_data=(test_data, one_hot(test_label)), shuffle_data=True) eval_stats = model.evaluate(test_data, one_hot(test_label)) predictions = unhot(model.predict(test_data, True)) print_results(predictions, test_label) plot_img_results(test_data[:40], test_label[:40], predictions, dataset='mnist') # truncate to 40 samples model_name = model.model_name plot_metric('loss', model_epochs, fit_stats['train_loss'], fit_stats['valid_loss'], model_name=model_name) plot_metric('accuracy', model_epochs, fit_stats['train_acc'],
model.add(Dropout(0.2)) model.add(BatchNormalization()) model.add(Dense(100)) model.add(Activation('softmax')) model.compile(loss = 'cce', optimizer = opt) model.summary(model_name = 'cifar-100 mlp') model_epochs = 12 # change to 200 epochs fit_stats = model.fit(reshaped_train_data, one_hot(train_label), batch_size = 128, epochs = model_epochs, validation_data = (reshaped_test_data, one_hot(test_label)), shuffle_data = True) eval_stats = model.evaluate(reshaped_test_data, one_hot(test_label)) predictions = unhot(model.predict(reshaped_test_data, True)) print_results(predictions, test_label) plot_img_results(test_data, test_label, predictions, dataset = 'cifar', channels = 3) plot_metric('loss', model_epochs, fit_stats['train_loss'], fit_stats['valid_loss'], model_name = model.model_name) plot_metric('accuracy', model_epochs, fit_stats['train_acc'], fit_stats['valid_acc'], model_name = model.model_name) plot_metric('evaluation', eval_stats['valid_batches'], eval_stats['valid_loss'], eval_stats['valid_acc'], model_name = model_name, legend = ['loss', 'acc'])
model.add(Dense(10)) model.add(Activation('softmax')) model.compile(loss='cce', optimizer=opt) model.summary(model_name='cifar-10 mlp') model_epochs = 200 # change to 200 epochs fit_stats = model.fit(transformed_train_data, one_hot(train_label), batch_size=128, epochs=model_epochs, validation_data=(transformed_test_data, one_hot(test_label)), shuffle_data=True) eval_stats = model.evaluate(transformed_test_data, one_hot(test_label)) predictions = unhot(model.predict(transformed_test_data, True)) print_results(predictions, test_label) plot_img_results(test_data, test_label, predictions, dataset='cifar', channels=3) model_name = model.model_name plot_metric('loss', model_epochs, fit_stats['train_loss'], fit_stats['valid_loss'], model_name=model_name)