model.add(Connected_layer(outputs=8, activation='relu')) model.add(Connected_layer(outputs=1, activation='linear')) model.add(Cost_layer(cost_type='mse')) # keras standard arguments model.compile(optimizer=RMSprop(lr=0.001, epsilon=1e-7))#, metrics=[mean_absolute_error]) print('*************************************') print('\n Total input dimension: {}'.format(X_train.shape), '\n') print('**************MODEL SUMMARY***********') model.summary() print('\n***********START TRAINING***********\n') # Fit the model on the training set model.fit(X=X_train, y=y_train.reshape(-1, 1, 1, 1), max_iter=10) print('\n***********START TESTING**************\n') # Test the prediction with timing loss, out = model.evaluate(X=X_test, truth=y_test, verbose=True) mae = mean_absolute_error(y_test, out) print('\n') print('Loss Score: {:.3f}'.format(loss)) print('MAE Score: {:.3f}'.format(mae)) # concatenate the prediction train_predicted = model.predict(X=X_train, verbose=False)
model.add(Softmax_layer(spatial=True, groups=1, temperature=1.)) # model.add(Cost_layer(cost_type=cost_type.mse)) # model.compile(optimizer=SGD(lr=0.01, decay=0., lr_min=0., lr_max=np.inf)) model.compile(optimizer=Adam(), metrics=[accuracy]) print('*************************************') print('\n Total input dimension: {}'.format(X_train.shape), '\n') print('**************MODEL SUMMARY***********') model.summary() print('\n***********START TRAINING***********\n') # Fit the model on the training set model.fit(X=X_train, y=y_train, max_iter=10, verbose=True) print('\n***********START TESTING**************\n') # Test the prediction with timing loss, out = model.evaluate(X=X_test, truth=y_test, verbose=True) truth = from_categorical(y_test) predicted = from_categorical(out) accuracy = mean_accuracy_score(truth, predicted) print('\nLoss Score: {:.3f}'.format(loss)) print('Accuracy Score: {:.3f}'.format(accuracy)) # SGD : best score I could obtain was 94% with 10 epochs, lr = 0.01 % # Momentum : best score I could obtain was 93% with 10 epochs # Adam : best score I could obtain was 95% with 10 epochs
outputs=num_classes, activation='Linear')) model.add(Softmax_layer(spatial=True)) print('*************************************') print('\n Total input dimension: {}'.format(X_train.shape), '\n') print('*************************************') model.compile(optimizer=Adam) model.summary() print('\n***********START TRAINING***********\n') # Fit the model on the training set model.fit(X=X_train, y=y_train, max_iter=5) print('\n***********END TRAINING**************\n') # Test the prediction out = model.predict(X=X_test) truth = y_test.argmax(axis=3).ravel() predicted = out.argmax(axis=3).ravel() #print('True label: ', truth) #print('Predicted label: ', predicted) # accuracy test print('Accuracy Score : {:.3f}'.format(accuracy_score(truth, predicted)))