return model text_class_model = build_model(113) earlyStopping = keras.callbacks.EarlyStopping(monitor='loss', patience=10, verbose=1, mode='auto') text_class_model.fit(train_data, train_labels, epochs=50, batch_size=5, callbacks=[earlyStopping]) ml_utils.save_model(text_class_model, 'text_class_model.h5') test_predicted_res = text_class_model.predict(test_data, batch_size=1) print( '\n****************Classification result for text classification************************' ) ml_utils.display_result( test_labels_raw, test_predicted_res.argmax(axis=1), 'text classification') # Print the classification result # for result in test_predicted_res: # ml_utils.display_confidence(result)
import ml_utils from numpy import genfromtxt """ This File is used to generate the final confusion matrix. Please add the bottom_color,left_color,right_color,Predicted_boxNumber,Actual_boxNumber values in 'result_confusion_matrix' file and then run the below code. """ if __name__ == "__main__": csv_path = "./resources/result_confusion_matrix.csv" dt = genfromtxt(csv_path, delimiter=',', skip_header=1) actual_labels = dt[:, -1] predicted_labels = dt[:, -2] ml_utils.display_result(actual_labels, predicted_labels, 'Real Time Prediction')
callbacks=[earlyStopping]) elapsed_time = time.time() - start_time print('Deep Learning Training time: {}'.format(elapsed_time)) ml_utils.save_model(model_container, 'model_container.h5') test_predicted_container_res = model_container.predict(test_container_data, batch_size=1) test_predicted_rack_res = model_rack.predict(test_rack_data, batch_size=1).argmax(axis=-1) # print('Color Space: {}'.format(color_space)) print( '\n****************Classification result for rack************************' ) ml_utils.display_result(test_rack_labels_raw, test_predicted_rack_res, 'rack') # Print the classification result print( '\n****************Classification result for container************************' ) ml_utils.display_result(test_container_labels_raw, test_predicted_container_res.argmax(axis=1), 'container') # Print the classification result # for result in test_predicted_container_res: # ml_utils.display_confidence(result) if not ml_utils.load_configurations_from_files( ): # If parameters are loaded from file then we can not get history. ml_plots_utils.plot_history(history_rack, 'rack') ml_plots_utils.plot_history(history_container, 'container')
# iterate over classifiers for name, clf in zip(names, classifiers): clf.fit(train_left_data, train_left_labels_raw) # score = clf.score(test_container_data, test_container_labels_raw) start_time = time.time() clf.fit(train_left_data, train_left_labels_raw) elapsed_time = time.time() - start_time training_time[name] = elapsed_time start_time = time.time() test_predicted_left_res = clf.predict(test_left_data) elapsed_time = time.time() - start_time prediction_time[name] = elapsed_time precision, recall, f1score, accuracy = ml_utils.display_result( test_left_labels_raw, test_predicted_left_res, name) precisions[name] = precision * 100 recalls[name] = recall * 100 f1scores[name] = f1score * 100 accuracy_scores[name] = accuracy * 100 # ------------------------------------------- Deep learning -------------------------------------------------- model_left = dl_clf.build_model(7, 6) start_time = time.time() history_left = model_left.fit(train_left_data, train_left_labels, epochs=10, validation_data=(test_left_data, test_left_labels),
batch_size=500, verbose=2) ml_utils.save_model(model_bottom, 'model_bottom.h5', config_save_load_dir_path) ml_utils.save_model(model_left, 'model_left.h5', config_save_load_dir_path) ml_utils.save_model(model_right, 'model_right.h5', config_save_load_dir_path) test_predicted_bottom_res = model_bottom.predict(test_bottom_data, batch_size=1) print( '\n****************Classification result for Bottom************************' ) ml_utils.display_result(test_bottom_labels_raw, test_predicted_bottom_res.argmax(axis=1), 'Bottom') # Print the classification result # for result in test_predicted_bottom_res: # ml_utils.display_confidence(result) test_predicted_left_res = model_left.predict(test_left_data, batch_size=1) print( '\n****************Classification result for Left************************') ml_utils.display_result(test_left_labels_raw, test_predicted_left_res.argmax(axis=1), 'Left') # Print the classification result # for result in test_predicted_left_res: # ml_utils.display_confidence(result) test_predicted_right_res = model_right.predict(test_right_data, batch_size=1)