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)
model.add(Convolution2D(nb_filters, nb_conv, nb_conv)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool))) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(128)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(nb_classes)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='adadelta') model.fit(train, train_label, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1, validation_data=(validation, validation_label)) logger.info("model training complete") score = model.evaluate(validation, validation_label, verbose=0) logger.info("validation score: %f" % (score)) save_model(model) logger.info("model saved")
model = Sequential() model.add(Convolution2D(nb_filters, nb_conv, nb_conv, border_mode = 'valid', input_shape = (1, img_rows, img_cols))) model.add(Activation('relu')) model.add(Convolution2D(nb_filters, nb_conv, nb_conv)) model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(nb_pool, nb_pool))) model.add(Dropout(0.25)) model.add(Flatten()) model.add(Dense(128)) model.add(Activation('relu')) model.add(Dropout(0.5)) model.add(Dense(nb_classes)) model.add(Activation('softmax')) model.compile(loss = 'categorical_crossentropy', optimizer = 'adadelta') model.fit(train, train_label, batch_size = batch_size, nb_epoch = nb_epoch, verbose = 1, validation_data = (validation, validation_label)) logger.info("model training complete") score = model.evaluate(validation, validation_label, verbose = 0) logger.info("validation score: %f" % (score)) save_model(model) logger.info("model saved")
earlyStopping = keras.callbacks.EarlyStopping(monitor='val_loss', patience=10, verbose=1, mode='auto') model_rack = build_model(5) history_rack = model_rack.fit(train_rack_data, train_rack_labels, epochs=10, validation_data=(test_rack_data, test_rack_labels), batch_size=500, verbose=2, callbacks=[earlyStopping]) ml_utils.save_model(model_rack, 'model_rack.h5') model_container = build_model(25) start_time = time.time() history_container = model_container.fit( train_container_data, train_container_labels, epochs=50, validation_data=(test_container_data, test_container_labels), batch_size=1000, verbose=2, 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')
epochs=20, validation_data=(test_left_data, test_left_labels), batch_size=500, verbose=2) model_right = dl_clf.build_model(8, input_shape) history_right = model_right.fit(train_right_data, train_right_labels, epochs=20, validation_data=(test_right_data, test_right_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)
# earlyStopping = keras.callbacks.EarlyStopping(monitor='val_loss', patience=10, verbose=1, mode='auto') model_bottom = dl_clf.build_model(5, 6) history_bottom = model_bottom.fit(train_bottom_data, train_bottom_labels, epochs=10, validation_data=(test_bottom_data, test_bottom_labels), batch_size=500, verbose=2) model_left = dl_clf.build_model(7, 6) 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) model_right = dl_clf.build_model(8, 6) history_right = model_right.fit(train_right_data, train_right_labels, epochs=10, validation_data=(test_right_data, test_right_labels), batch_size=500, verbose=2) ml_utils.save_model(model_bottom, 'model_bottom.h5') ml_utils.save_model(model_left, 'model_left.h5') ml_utils.save_model(model_right, 'model_right.h5') 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