Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Load data
train_folds, val_fold, _ = data_fold_loader.load_fold_assignment(test_fold=test_split)
X_val, y_val = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [val_fold])
X_test, y_test = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [test_split])
print X_val.shape, y_val.shape
print X_test.shape, y_test.shape
X_val = numpy.float32(X_val)
X_val /= 255.0
X_val *= 2.0
X_test = numpy.float32(X_test)
X_test /= 255.0
X_test *= 2.0
val_data_container = SupervisedDataContainer(X_val, y_val)
test_data_container = SupervisedDataContainer(X_test, y_test)
# Construct evaluator
preprocessor = [util.Normer3(filter_size=5, num_channels=1)]
checkpoint_file_list = sorted(
glob.glob(os.path.join(checkpoint_dir, '*.pkl')))
val_evaluator = util.Evaluator(model, val_data_container,
checkpoint_file_list[0], preprocessor)
test_evaluator = util.Evaluator(model, test_data_container,
checkpoint_file_list[0], preprocessor)
# For each checkpoint, compute the overall val accuracy
val_accuracies = []
for checkpoint in checkpoint_file_list:
print 'Checkpoint: %s' % os.path.split(checkpoint)[1]
# Load dataset
train_folds, val_fold, _ = data_fold_loader.load_fold_assignment(test_fold=test_split)
X_val, y_val = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [val_fold])
X_test, y_test = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [test_split])
print X_val.shape, y_val.shape
print X_test.shape, y_test.shape
X_val = numpy.float32(X_val)
X_val /= 255.0
X_val *= 2.0
X_test = numpy.float32(X_test)
X_test /= 255.0
X_test *= 2.0
val_data_container = SupervisedDataContainer(X_val, y_val)
test_data_container = SupervisedDataContainer(X_test, y_test)
# Construct evaluator
preprocessor = [util.Normer3(filter_size=5, num_channels=1)]
val_evaluator = util.Evaluator(model, val_data_container,
checkpoint_file, preprocessor)
test_evaluator = util.Evaluator(model, test_data_container,
checkpoint_file, preprocessor)
# For the inputted checkpoint, compute the overall val accuracy
print 'Checkpoint: %s' % os.path.split(checkpoint_file)[1]
val_evaluator.set_checkpoint(checkpoint_file)
val_accuracy = val_evaluator.run()
print 'Val Accuracy: %f\n' % val_accuracy
train_folds, val_fold, _ = data_fold_loader.load_fold_assignment(test_fold=test_split)
X_val, y_val = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [val_fold])
X_test, y_test = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [test_split])
print X_val.shape, y_val.shape
print X_test.shape, y_test.shape
X_val = numpy.float32(X_val)
X_val /= 255.0
X_val *= 2.0
X_test = numpy.float32(X_test)
X_test /= 255.0
X_test *= 2.0
val_data_container = SupervisedDataContainer(X_val, y_val)
test_data_container = SupervisedDataContainer(X_test, y_test)
# Construct evaluator
preprocessor = [util.Normer3(filter_size=5, num_channels=1)]
val_evaluator = util.Evaluator(model, val_data_container,
checkpoint_file, preprocessor)
test_evaluator = util.Evaluator(model, test_data_container,
checkpoint_file, preprocessor)
# For the inputted checkpoint, compute the overall val accuracy
print 'Checkpoint: %s' % os.path.split(checkpoint_file)[1]
val_evaluator.set_checkpoint(checkpoint_file)
val_accuracy = val_evaluator.run()
print 'Val Accuracy: %f\n' % val_accuracy
test_mask = numpy.logical_and(y_test != 0, y_test != 2)
X_test = X_test[test_mask, :, :, :]
y_test = y_test[test_mask]
y_test = reindex_labels(y_test)
num_test_samples = len(y_test)
print 'Reduced Val Data: ', X_val.shape, y_val.shape
print 'Reduced Test Data: ', X_test.shape, y_test.shape
if test_split == 9:
X_test, y_test = add_padding(X_test, y_test)
elif test_split == 8:
X_val, y_val = add_padding(X_val, y_val)
val_data_container = SupervisedDataContainer(X_val, y_val)
test_data_container = SupervisedDataContainer(X_test, y_test)
# Construct evaluator
preprocessor = [util.Normer3(filter_size=5, num_channels=1)]
checkpoint_file_list = sorted(
glob.glob(os.path.join(checkpoint_dir, '*.pkl')))
val_evaluator = util.Evaluator(model, val_data_container,
checkpoint_file_list[0], preprocessor)
test_evaluator = util.Evaluator(model, test_data_container,
checkpoint_file_list[0], preprocessor)
# For each checkpoint, compute the overall val accuracy
val_accuracies = []
for checkpoint in checkpoint_file_list:
print 'Checkpoint: %s' % os.path.split(checkpoint)[1]
train_folds, val_fold, _ = data_fold_loader.load_fold_assignment(test_fold=test_split)
X_val, y_val = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [val_fold])
X_test, y_test = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [test_split])
print X_val.shape, y_val.shape
print X_test.shape, y_test.shape
X_val = numpy.float32(X_val)
X_val /= 255.0
X_val *= 2.0
X_test = numpy.float32(X_test)
X_test /= 255.0
X_test *= 2.0
val_data_container = SupervisedDataContainer(X_val, y_val)
test_data_container = SupervisedDataContainer(X_test, y_test)
# Construct evaluator
preprocessor = [util.Normer3(filter_size=5, num_channels=1)]
checkpoint_file_list = sorted(
glob.glob(os.path.join(checkpoint_dir, '*.pkl')))
val_evaluator = util.Evaluator(model, val_data_container,
checkpoint_file_list[0], preprocessor)
test_evaluator = util.Evaluator(model, test_data_container,
checkpoint_file_list[0], preprocessor)
# For each checkpoint, compute the overall val accuracy
val_accuracies = []
for checkpoint in checkpoint_file_list:
print 'Checkpoint: %s' % os.path.split(checkpoint)[1]
val_evaluator.set_checkpoint(checkpoint)
mask_test = numpy.logical_and(y_test != 0, y_test != 2)
X_test = X_test[mask_test, :, :, :]
y_test = y_test[mask_test]
y_test = reindex_labels(y_test)
num_test_samples = len(y_test)
print 'Reduced Val Data: ', X_val.shape, y_val.shape
print 'Reduced Test Data: ', X_test.shape, y_test.shape
if test_split == 9:
X_test, y_test = add_padding(X_test, y_test)
elif test_split == 8:
X_val, y_val = add_padding(X_val, y_val)
val_data_container = SupervisedDataContainer(X_val, y_val)
test_data_container = SupervisedDataContainer(X_test, y_test)
# Construct evaluator
preprocessor = [util.Normer3(filter_size=5, num_channels=1)]
val_evaluator = util.Evaluator(model, val_data_container,
checkpoint_file, preprocessor)
test_evaluator = util.Evaluator(model, test_data_container,
checkpoint_file, preprocessor)
# For the inputted checkpoint, compute the overall test accuracy
#accuracies = []
print 'Checkpoint: %s' % os.path.split(checkpoint_file)[1]
val_evaluator.set_checkpoint(checkpoint_file)
if test_split != 8:
val_accuracy = val_evaluator.run()
train_folds, val_fold, _ = data_fold_loader.load_fold_assignment(test_fold=test_split)
X_val, y_val = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [val_fold])
X_test, y_test = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [test_split])
print 'Val Data: ', X_val.shape, y_val.shape
print 'Test Data: ', X_test.shape, y_test.shape
X_val = numpy.float32(X_val)
X_val /= 255.0
X_val *= 2.0
X_test = numpy.float32(X_test)
X_test /= 255.0
X_test *= 2.0
val_data_container = SupervisedDataContainer(X_val, y_val)
test_data_container = SupervisedDataContainer(X_test, y_test)
# Remove samples with neutral and contempt labels
val_mask = numpy.logical_and(y_val != 0, y_val != 2)
X_val = X_val[val_mask, :, :, :]
y_val = y_val[val_mask]
y_val = reindex_labels(y_val)
num_val_samples = len(y_val)
mask_test = numpy.logical_and(y_test != 0, y_test != 2)
X_test = X_test[mask_test, :, :, :]
y_test = y_test[mask_test]
y_test = reindex_labels(y_test)
num_test_samples = len(y_test)
train_folds, val_fold, _ = data_fold_loader.load_fold_assignment(test_fold=test_split)
X_val, y_val = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [val_fold])
X_test, y_test = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [test_split])
print 'Val Data: ', X_val.shape, y_val.shape
print 'Test Data: ', X_test.shape, y_test.shape
X_val = numpy.float32(X_val)
X_val /= 255.0
X_val *= 2.0
X_test = numpy.float32(X_test)
X_test /= 255.0
X_test *= 2.0
val_data_container = SupervisedDataContainer(X_val, y_val)
test_data_container = SupervisedDataContainer(X_test, y_test)
# Remove samples with neutral and contempt labels
val_mask = numpy.logical_and(y_val != 0, y_val != 2)
X_val = X_val[val_mask, :, :, :]
y_val = y_val[val_mask]
y_val = reindex_labels(y_val)
num_val_samples = len(y_val)
test_mask = numpy.logical_and(y_test != 0, y_test != 2)
X_test = X_test[test_mask, :, :, :]
y_test = y_test[test_mask]
y_test = reindex_labels(y_test)
num_test_samples = len(y_test)
print 'Reduced Val Data: ', X_val.shape, y_val.shape
train_folds, val_fold, _ = data_fold_loader.load_fold_assignment(test_fold=test_split)
X_val, y_val = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [val_fold])
X_test, y_test = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [test_split])
print 'Val Data: ', X_val.shape, y_val.shape
print 'Test Data: ', X_test.shape, y_test.shape
X_val = numpy.float32(X_val)
X_val /= 255.0
X_val *= 2.0
X_test = numpy.float32(X_test)
X_test /= 255.0
X_test *= 2.0
val_data_container = SupervisedDataContainer(X_val, y_val)
test_data_container = SupervisedDataContainer(X_test, y_test)
# Remove samples with neutral and contempt labels
val_mask = numpy.logical_and(y_val != 0, y_val != 2)
X_val = X_val[val_mask, :, :, :]
y_val = y_val[val_mask]
y_val = reindex_labels(y_val)
num_val_samples = len(y_val)
test_mask = numpy.logical_and(y_test != 0, y_test != 2)
X_test = X_test[test_mask, :, :, :]
y_test = y_test[test_mask]
y_test = reindex_labels(y_test)
num_test_samples = len(y_test)
train_folds, val_fold, _ = data_fold_loader.load_fold_assignment(test_fold=test_split)
X_val, y_val = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [val_fold])
X_test, y_test = data_fold_loader.load_folds(data_paths.ck_plus_data_path, [test_split])
print 'Val Data: ', X_val.shape, y_val.shape
print 'Test Data: ', X_test.shape, y_test.shape
X_val = numpy.float32(X_val)
X_val /= 255.0
X_val *= 2.0
X_test = numpy.float32(X_test)
X_test /= 255.0
X_test *= 2.0
val_data_container = SupervisedDataContainer(X_val, y_val)
test_data_container = SupervisedDataContainer(X_test, y_test)
# Remove samples with neutral and contempt labels
val_mask = numpy.logical_and(y_val != 0, y_val != 2)
X_val = X_val[val_mask, :, :, :]
y_val = y_val[val_mask]
y_val = reindex_labels(y_val)
num_val_samples = len(y_val)
mask_test = numpy.logical_and(y_test != 0, y_test != 2)
X_test = X_test[mask_test, :, :, :]
y_test = y_test[mask_test]
y_test = reindex_labels(y_test)
num_test_samples = len(y_test)
print 'Reduced Val Data: ', X_val.shape, y_val.shape