def train(use_fisher): x, y = loader.load() if use_fisher: x = preprocessing.to_fisher(x) x_train, y_train, x_val, y_val = loader.split_data(x, y) x_train = x_train.reshape(x_train.shape[0], -1) x_val = x_val.reshape(x_val.shape[0], -1) clf = svm.SVC(class_weight='balanced') clf.fit(x_train, y_train) evaluate.evaluate(clf, x_val, y_val)
def train(args): x, y = loader.load() if args.model == 'mlp_fv': x = preprocessing.to_fisher(x) nb_samples, nb_landmarks, l = x.shape input_shape = (nb_landmarks, l) else: nb_samples, nb_frames, nb_landmarks, _ = x.shape input_shape = (nb_frames, nb_landmarks, 3) # x = loader.compact_frames(x, window_size=5, step_size=2) x_train, y_train, x_val, y_val = loader.split_data(x, y) model = get_model(args.model, input_shape=input_shape) print("Input shape: {}".format(x.shape)) print(model.summary()) model.compile(optimizer='adam', loss=losses.binary_crossentropy, metrics=['accuracy']) checkpointer = callbacks.ModelCheckpoint(filepath="data/weights.hdf5", verbose=1, save_best_only=True) early_stopping = callbacks.EarlyStopping(monitor='val_loss', min_delta=0, patience=2) class_weights = get_class_weights(y_train) model.fit(x_train, y_train, epochs=50, batch_size=8, validation_data=(x_val, y_val), callbacks=[ checkpointer, early_stopping, ], class_weight=class_weights, ) # Load best model model.load_weights('data/weights.hdf5') # Print evaluation matrix train_score = model.evaluate(x_train, y_train) val_score = model.evaluate(x_val, y_val) print(model.metrics_names, train_score, val_score) evaluate.evaluate(model, x_train, y_train) evaluate.evaluate(model, x_val, y_val)
def test_load(self): x, y = loader.load(shuffle=False) nb_x = x.shape[0] nb_y = len(y) # Test that number of samples match self.assertEqual(nb_x, nb_y) # Test that labels match csv with open('data/bluff_data.csv') as fp: reader = csv.DictReader(fp) labels = [] for row in reader: if row['error'] != '': continue labels.append(float(row['isBluffing'])) np.testing.assert_array_equal(y, np.array(labels))
def setUp(self): self.x, self.y = loader.load(shuffle=False)
def test_fisher_vector(self): x, y = loader.load(shuffle=False) fv = preprocessing.to_fisher(x)