Skip to content

Commit 598137f

Browse files
committed
Write code to calculate MTCP
1 parent 739ff63 commit 598137f

11 files changed

Lines changed: 1092 additions & 71 deletions

File tree

code/autoencoder_model/scripts/thesis_scripts/classifier_all.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@ def load_to_RAM(frames_source):
300300
im_file = os.path.join(DATA_DIR, filename)
301301
try:
302302
frame = cv2.imread(im_file, cv2.IMREAD_COLOR)
303-
frames[i] = frame.astype(np.float32)
303+
if RANDOM_AUGMENTATION:
304+
frames[i] = frame.astype(np.float32)
305+
else:
306+
frames[i] = (frame.astype(np.float32) - 127.5) / 127.5
304307
j = j + 1
305308
except AttributeError as e:
306309
print(im_file)
@@ -609,7 +612,7 @@ def train(BATCH_SIZE, ENC_WEIGHTS, DEC_WEIGHTS, CLA_WEIGHTS):
609612
# Load test action annotations
610613
val_action_labels = hkl.load(os.path.join(VAL_DATA_DIR, 'annotations_val_208.hkl'))
611614
val_ped_action_classes, val_ped_class_count = get_action_classes(val_action_labels)
612-
print("VAl Stats: " + str(val_ped_class_count))
615+
print("Val Stats: " + str(val_ped_class_count))
613616

614617
# Build the Spatio-temporal Autoencoder
615618
print ("Creating models.")
@@ -670,7 +673,7 @@ def train(BATCH_SIZE, ENC_WEIGHTS, DEC_WEIGHTS, CLA_WEIGHTS):
670673
c_loss.append(sclassifier.train_on_batch(X_train, [y_true_imgs, y_true_class]))
671674

672675
y_train_true.extend(y_true_class)
673-
y_train_pred.extend(sclassifier.predict(X_train, verbose=0))
676+
y_train_pred.extend(sclassifier.predict(X_train, verbose=0)[1])
674677

675678
arrow = int(index / (NB_ITERATIONS / 30))
676679
stdout.write("\rIter: " + str(index) + "/" + str(NB_ITERATIONS - 1) + " " +
@@ -738,7 +741,7 @@ def train(BATCH_SIZE, ENC_WEIGHTS, DEC_WEIGHTS, CLA_WEIGHTS):
738741

739742
val_c_loss.append(sclassifier.test_on_batch(X_val, [y_true_imgs, y_true_class]))
740743
y_val_true.extend(y_true_class)
741-
y_val_pred.extend(sclassifier.predict(X_val, verbose=0))
744+
y_val_pred.extend(sclassifier.predict(X_val, verbose=0)[1])
742745

743746
arrow = int(index / (NB_VAL_ITERATIONS / 40))
744747
stdout.write("\rIter: " + str(index) + "/" + str(NB_VAL_ITERATIONS - 1) + " " +
@@ -812,16 +815,16 @@ def train(BATCH_SIZE, ENC_WEIGHTS, DEC_WEIGHTS, CLA_WEIGHTS):
812815
avg='binary',
813816
pos_label=1)
814817

815-
print("Train Prec: %.2f, Recall: %.2f, Fbeta: %.2f" % (train_prec, train_rec, train_fbeta))
818+
print("\nTrain Prec: %.2f, Recall: %.2f, Fbeta: %.2f" % (train_prec, train_rec, train_fbeta))
816819
print("Val Prec: %.2f, Recall: %.2f, Fbeta: %.2f" % (val_prec, val_rec, val_fbeta))
817-
# loss_values = np.asarray(avg_c_loss.tolist() + [train_prec.tolist()] +
818-
# [train_rec.tolist()] +
819-
# avg_val_c_loss.tolist() + [val_prec.tolist()] +
820-
# [val_rec.tolist()], dtype=np.float32)
821-
loss_values = np.asarray(avg_c_loss.tolist() + train_prec.tolist() +
822-
train_rec.tolist() +
823-
avg_val_c_loss.tolist() + val_prec.tolist() +
824-
val_rec.tolist(), dtype=np.float32)
820+
loss_values = np.asarray(avg_c_loss.tolist() + [train_prec.tolist()] +
821+
[train_rec.tolist()] +
822+
avg_val_c_loss.tolist() + [val_prec.tolist()] +
823+
[val_rec.tolist()], dtype=np.float32)
824+
# loss_values = np.asarray(avg_c_loss.tolist() + train_prec.tolist() +
825+
# train_rec.tolist() +
826+
# avg_val_c_loss.tolist() + val_prec.tolist() +
827+
# val_rec.tolist(), dtype=np.float32)
825828

826829
precs = ['prec_' + action for action in simple_ped_set]
827830
recs = ['rec_' + action for action in simple_ped_set]

0 commit comments

Comments
 (0)