def create_network(network_input, n_vocab, result_dir): results_dir = utils.get_results_dir(result_dir) model = utils.load_model_from_json(results_dir) model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy']) model.summary() return model
def evaluate(): # Avalia o resultado obtido pela NN comparando com os objetivos reais dos agentes model = load_model_from_json('inverse_planning_model') model.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.Adam(), metrics=['accuracy']) test_nn_input, expected_nn_output = load_data('eval') predicted_labels = model.predict(test_nn_input) model.summary() score = model.evaluate(test_nn_input, expected_nn_output) print('Test loss:', score[0]) print('Test accuracy:', score[1]) for i in range(20): index = random.randint(0, test_nn_input.shape[0]) print('Example: {}. Expected Label: {}. Predicted Label: {}.'.format( index, expected_nn_output[index], greatest_equal_one(predicted_labels[index])))
import numpy as np import keras from keras.utils.np_utils import to_categorical # Comment this line to enable training using your GPU os.environ['CUDA_VISIBLE_DEVICES'] = '-1' NUM_IMAGES_RANDOM = 5 NUM_IMAGES_MISCLASSIFICATION = 5 # Loading the test dataset test_features, test_labels = read_mnist('t10k-images-idx3-ubyte.gz', 't10k-labels-idx1-ubyte.gz') # Loading the model from files model = load_model_from_json('lenet5') model.summary() # We need to do this to keep Keras happy model.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.Adam(), metrics=['accuracy']) # Predicting labels and evaluating the model on the test set predicted_labels = model.predict(test_features) score = model.evaluate(test_features, to_categorical(test_labels)) print('Test loss:', score[0]) print('Test accuracy:', score[1]) # Showing some random images for i in range(NUM_IMAGES_RANDOM): index = random.randint(0, test_features.shape[0]) display_image(test_features[index],
(min_paw, max_paw, _) = normalize_data(_paw) (min_resistances, max_resistances, _) = normalize_data(_resistances) (min_capacitances, max_capacitances, _) = normalize_data(_capacitances) (_, _, flow_norm) = normalize_data(flow, minimum=min_flow, maximum=max_flow) (_, _, volume_norm) = normalize_data(volume, minimum=min_volume, maximum=max_volume) (_, _, paw_norm) = normalize_data(paw, minimum=min_paw, maximum=max_paw) input_data = np.zeros((num_examples, num_samples, 3)) input_data[:, :, 0] = flow_norm input_data[:, :, 1] = volume_norm input_data[:, :, 2] = paw_norm models = [load_model_from_json(model_filename)] output_pred_test = [model.predict(input_data) for model in models] output_pred_test = sum(output_pred_test) / len(output_pred_test) err_r = [] err_c = [] err_pmus = [] # R_hat = np.average([denormalize_data(output_pred_test[i, 0], minimum=min_resistances, maximum=max_resistances) for i in range(num_examples)]) # C_hat = np.average([denormalize_data(output_pred_test[i, 1], minimum= min_capacitances, maximum= max_capacitances) for i in range(num_examples)]) R_hat = denormalize_data(output_pred_test[0, 0], minimum=min_resistances, maximum=max_resistances) C_hat = denormalize_data(output_pred_test[0, 1],
fs = max(Fs) time_ = np.arange(0, np.floor(180.0 / rr * fs) + 1, 1) / fs flow = np.load('./data/flow' + str(size) + '.npy') volume = np.load('./data/volume' + str(size) + '.npy') paw = np.load('./data/paw' + str(size) + '.npy') resistances = np.load('./data/rins' + str(size) + '.npy') capacitances = np.load('./data/capacitances' + str(size) + '.npy') (min_flow, max_flow, _) = normalize_data(flow) (min_volume, max_volume, _) = normalize_data(volume) (min_paw, max_paw, _) = normalize_data(paw) (min_resistances, max_resistances, _) = normalize_data(resistances) (min_capacitances, max_capacitances, _) = normalize_data(capacitances) model = load_model_from_json(model_filename) input_data = np.load('./data/input_test.npy') output_data = np.load('./data/output_test.npy') # flow = flow[:,indexes].T # volume = volume[:,indexes].T # paw = paw[:,indexes].T # resistances = resistances[:,indexes].T # capacitances = capacitances[:,indexes].T # num_examples = flow.shape[0] # num_samples = flow.shape[1] # (_, _, flow_norm) = normalize_data(flow, minimum=min_flow, maximum=max_flow) # (_, _, volume_norm) = normalize_data(volume, minimum=min_volume, maximum=max_volume)