In [1]:
import helper.data_provider as data_provider
from sklearn.preprocessing import normalize as normalize

In [2]:
feat_dir = '../features/resize_crop/res2'
validation_ratio = 0
skip_folder = ['yiwen']

In [3]:
data = data_provider.load_features_by_subfolder(
    feat_dir,
    validation_ratio=validation_ratio,
    skip_folder=skip_folder,
    use_subfolder=True
)


=> Label: bad (0) [Files: 500 Total, 500 Training, 0 Validation]
=> Label: good (1) [Files: 500 Total, 500 Training, 0 Validation]


In [4]:
root_dir    = '../features/resize_crop/res2'
new_dir = '../features/resize_crop/res2-norm'

for read_path in data['training_paths']:
    read_file = open(read_path, 'r')
    lines = read_file.readlines()
    feat = [[float(l) for l in lines]]
    feat = normalize(feat, norm='l2', axis=1, copy=False)
    
    write_path = read_path.replace(root_dir, new_dir)
    feat_string = '\n'.join("{:.16f}".format(x) for x in feat[0])
    with open(write_path, 'w') as write_file:
        write_file.write(feat_string)

In [ ]: