N_ANCHORS = Configuration.ANCHORS.shape[0] GRID_SIZE = Configuration.GRID_SIZE #%% #Load Model along with weights model = get_pre_trained_model() model.load_weights( 'trained_weights\leaf_data_v2\model_weights_16-nosoftmax.h5') model.summary() #%% dataset = ImageDataset('data/leaf_data_v2/train', 'data/leaf_data_v2/test', shuffle=True, histogram_equ=False, brightness_range=None) #%% x, y = dataset.next_test_batch() #%% y_pred = model.predict(x) #%% y_pred_1 = y_pred[0] x_1 = x[0] #%% y_pred_1 = np.reshape(y_pred_1, (GRID_SIZE * GRID_SIZE * N_ANCHORS, N_CLASSES + 5)) for i in range(y_pred_1.shape[0]): y_pred_1[i, 0:4] = util.cvt_coord_to_diagonal(y_pred_1[i, 0:4]) y_pred_1[:, 0:4] = np.clip(y_pred_1[:, 0:4], a_min=0.0, a_max=1.0) #%% y_pred_1 = non_max_suppression(y_pred_1, 0.5, 0.3) #%% img = x_1
'data/leaf_data_v2/test', shuffle=True) x, y = dataset.next_train_batch() #%% for i in range(EPOCHS): print("Epoch ", i + 1) for j in range(STEPS_PER_EPOCH): X, y = dataset.next_train_batch() X = np.reshape(X, newshape=(BATCH_SIZE, Configuration.IMAGE_HEIGHT, Configuration.IMAGE_WIDTH, 3)) y = np.reshape(y, newshape=(BATCH_SIZE, GRID_SIZE, GRID_SIZE, PREDICTIONS_PER_CELL)) model.train_on_batch(X, y) if (j) % 100 == 0: print("Step {}".format(j)) X_test, y_test = dataset.next_test_batch() X_test = np.reshape(X_test, (BATCH_SIZE, Configuration.IMAGE_HEIGHT, Configuration.IMAGE_WIDTH, 3)) y_test = np.reshape( y_test, (BATCH_SIZE, GRID_SIZE, GRID_SIZE, PREDICTIONS_PER_CELL)) l1 = model.evaluate(X_test, y_test) print('Val Loss:{}'.format(l1)) model.save_weights('trained_weights/leaf_v2_model.h5') #%% print("Finished Training") model.save_weights('trained_weigths/leaf_v2_model.h5')