def execute(): test_data = load_npy_file(npy_files_dir_path + 'test_z_data.npy') test_labels = load_npy_file(npy_files_dir_path + 'test_labels.npy') one_hot_test_labels = tf.keras.utils.to_categorical(test_labels) model = tf.keras.models.load_model(model_saving_dir_path + 'model_Z.h5') loss, acc = model.evaluate(test_data, one_hot_test_labels) print_loss_acc(loss, acc)
def execute(): test_data = load_npy_file(npy_files_dir_path + 'test_y_data.npy') test_labels = load_npy_file(npy_files_dir_path + 'test_labels.npy') one_hot_test_labels = tf.keras.utils.to_categorical(test_labels) model = tf.keras.models.load_model(model_saving_dir_path + 'model_Y.h5') loss, acc = model.evaluate(test_data, one_hot_test_labels) print_loss_acc(loss, acc) converter = tf.lite.TFLiteConverter.from_keras_model(model) tf_lite_model = converter.convert() create_dir_if_necessary(tf_lite_model_saving_dir_path) open(tf_lite_model_saving_dir_path + 'model_Y.tflite', 'wb').write(tf_lite_model)
def main(): x_train = load_npy_file(npy_files_saving_dir_path + 'train_x_data.npy') x_val = load_npy_file(npy_files_saving_dir_path + 'valid_x_data.npy') x_test = load_npy_file(npy_files_saving_dir_path + 'test_x_data.npy') y_train = load_npy_file(npy_files_saving_dir_path + 'train_labels.npy') y_val = load_npy_file(npy_files_saving_dir_path + 'valid_labels.npy') y_test = load_npy_file(npy_files_saving_dir_path + 'test_labels.npy') print(len(x_train) == len(y_train)) print(len(x_val) == len(y_val)) print(len(x_test) == len(y_test))
def execute(): train_data = load_npy_file(npy_files_dir_path + 'train_z_data.npy') valid_data = load_npy_file(npy_files_dir_path + 'valid_z_data.npy') test_data = load_npy_file(npy_files_dir_path + 'test_z_data.npy') train_labels = load_npy_file(npy_files_dir_path + 'train_labels.npy') valid_labels = load_npy_file(npy_files_dir_path + 'valid_labels.npy') test_labels = load_npy_file(npy_files_dir_path + 'test_labels.npy') one_hot_train_labels = tf.keras.utils.to_categorical(train_labels) one_hot_valid_labels = tf.keras.utils.to_categorical(valid_labels) one_hot_test_labels = tf.keras.utils.to_categorical(test_labels) model = tf.keras.models.Sequential([ tf.keras.layers.Dense(512, activation='relu'), tf.keras.layers.Dense(512, activation='relu'), tf.keras.layers.Dense(3, activation='softmax') ]) model.compile( optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'] ) history = model.fit( train_data, one_hot_train_labels, epochs=20, batch_size=512, validation_data=(valid_data, one_hot_valid_labels) ) create_dir_if_necessary(model_saving_dir_path) model.save(model_saving_dir_path + 'model_Z.h5') loss, acc = model.evaluate(test_data, one_hot_test_labels) print_loss_acc(loss, acc) show_loss(history) show_accuracy(history)