|
@@ -18,20 +18,16 @@ from data_attributes import get_image_features
|
|
|
|
|
|
|
|
|
|
# getting configuration information
|
|
# getting configuration information
|
|
-learned_folder = cfg.learned_zones_folder
|
|
|
|
|
|
+learned_folder = cfg.output_zones_learned
|
|
min_max_filename = cfg.min_max_filename_extension
|
|
min_max_filename = cfg.min_max_filename_extension
|
|
|
|
|
|
# define all scenes variables
|
|
# define all scenes variables
|
|
-scenes_list = cfg.scenes_names
|
|
|
|
-scenes_indexes = cfg.scenes_indices
|
|
|
|
-path = cfg.dataset_path
|
|
|
|
zones = cfg.zones_indices
|
|
zones = cfg.zones_indices
|
|
seuil_expe_filename = cfg.seuil_expe_filename
|
|
seuil_expe_filename = cfg.seuil_expe_filename
|
|
|
|
|
|
-renderer_choices = cfg.renderer_choices
|
|
|
|
normalization_choices = cfg.normalization_choices
|
|
normalization_choices = cfg.normalization_choices
|
|
features_choices = cfg.features_choices_labels
|
|
features_choices = cfg.features_choices_labels
|
|
-output_data_folder = cfg.output_data_folder
|
|
|
|
|
|
+output_data_folder = cfg.output_datasets
|
|
custom_min_max_folder = cfg.min_max_custom_folder
|
|
custom_min_max_folder = cfg.min_max_custom_folder
|
|
min_max_ext = cfg.min_max_filename_extension
|
|
min_max_ext = cfg.min_max_filename_extension
|
|
zones_indices = cfg.zones_indices
|
|
zones_indices = cfg.zones_indices
|
|
@@ -41,7 +37,7 @@ generic_output_file_svd = '_random.csv'
|
|
min_value_interval = sys.maxsize
|
|
min_value_interval = sys.maxsize
|
|
max_value_interval = 0
|
|
max_value_interval = 0
|
|
|
|
|
|
-def construct_new_line(path_seuil, interval, line, choice, each, norm):
|
|
|
|
|
|
+def construct_new_line(threshold, interval, line, choice, each, norm):
|
|
begin, end = interval
|
|
begin, end = interval
|
|
|
|
|
|
line_data = line.split(';')
|
|
line_data = line.split(';')
|
|
@@ -56,10 +52,7 @@ def construct_new_line(path_seuil, interval, line, choice, each, norm):
|
|
if choice == 'svdn':
|
|
if choice == 'svdn':
|
|
features = utils.normalize_arr(features)
|
|
features = utils.normalize_arr(features)
|
|
|
|
|
|
- with open(path_seuil, "r") as seuil_file:
|
|
|
|
- seuil_learned = int(seuil_file.readline().strip())
|
|
|
|
-
|
|
|
|
- if seuil_learned > int(seuil):
|
|
|
|
|
|
+ if threshold > int(seuil):
|
|
line = '1'
|
|
line = '1'
|
|
else:
|
|
else:
|
|
line = '0'
|
|
line = '0'
|
|
@@ -71,7 +64,7 @@ def construct_new_line(path_seuil, interval, line, choice, each, norm):
|
|
|
|
|
|
return line
|
|
return line
|
|
|
|
|
|
-def get_min_max_value_interval(_scenes_list, _interval, _feature):
|
|
|
|
|
|
+def get_min_max_value_interval(path, _scenes_list, _interval, _feature):
|
|
|
|
|
|
global min_value_interval, max_value_interval
|
|
global min_value_interval, max_value_interval
|
|
|
|
|
|
@@ -123,13 +116,10 @@ def get_min_max_value_interval(_scenes_list, _interval, _feature):
|
|
max_value_interval = max_value
|
|
max_value_interval = max_value
|
|
|
|
|
|
|
|
|
|
-def generate_data_model(_filename, _interval, _choice, _feature, _scenes = scenes_list, _zones = zones_indices, _percent = 1, _step=1, _each=1, _norm=False, _custom=False):
|
|
|
|
-
|
|
|
|
- output_train_filename = _filename + ".train"
|
|
|
|
- output_test_filename = _filename + ".test"
|
|
|
|
|
|
+def generate_data_model(_filename, _data_path, _interval, _choice, _feature, _thresholds, _learned_zones, _step=1, _each=1, _norm=False, _custom=False):
|
|
|
|
|
|
- if not '/' in output_train_filename:
|
|
|
|
- raise Exception("Please select filename with directory path to save data. Example : data/dataset")
|
|
|
|
|
|
+ output_train_filename = os.path.join(output_data_folder, _filename + ".train")
|
|
|
|
+ output_test_filename = os.path.join(output_data_folder,_filename + ".test")
|
|
|
|
|
|
# create path if not exists
|
|
# create path if not exists
|
|
if not os.path.exists(output_data_folder):
|
|
if not os.path.exists(output_data_folder):
|
|
@@ -138,24 +128,15 @@ def generate_data_model(_filename, _interval, _choice, _feature, _scenes = scene
|
|
train_file = open(output_train_filename, 'w')
|
|
train_file = open(output_train_filename, 'w')
|
|
test_file = open(output_test_filename, 'w')
|
|
test_file = open(output_test_filename, 'w')
|
|
|
|
|
|
- for folder_scene in scenes_list:
|
|
|
|
-
|
|
|
|
- # only take care of maxwell scenes
|
|
|
|
- scene_path = os.path.join(path, folder_scene)
|
|
|
|
-
|
|
|
|
- zones_indices = zones
|
|
|
|
-
|
|
|
|
- # write into file
|
|
|
|
- folder_learned_path = os.path.join(learned_folder, _filename.split('/')[1])
|
|
|
|
-
|
|
|
|
- if not os.path.exists(folder_learned_path):
|
|
|
|
- os.makedirs(folder_learned_path)
|
|
|
|
|
|
+ # get zone indices
|
|
|
|
+ zones_indices = np.arange(16)
|
|
|
|
|
|
- file_learned_path = os.path.join(folder_learned_path, folder_scene + '.csv')
|
|
|
|
|
|
+ for folder_scene in _thresholds:
|
|
|
|
|
|
- with open(file_learned_path, 'w') as f:
|
|
|
|
- for i in _zones:
|
|
|
|
- f.write(str(i) + ';')
|
|
|
|
|
|
+ # get train zones
|
|
|
|
+ train_zones = _learned_zones[folder_scene]
|
|
|
|
+ scene_thresholds = _thresholds[folder_scene]
|
|
|
|
+ scene_path = os.path.join(_data_path, folder_scene)
|
|
|
|
|
|
for id_zone, index_folder in enumerate(zones_indices):
|
|
for id_zone, index_folder in enumerate(zones_indices):
|
|
|
|
|
|
@@ -183,19 +164,16 @@ def generate_data_model(_filename, _interval, _choice, _feature, _scenes = scene
|
|
lines_indexes = np.arange(num_lines)
|
|
lines_indexes = np.arange(num_lines)
|
|
random.shuffle(lines_indexes)
|
|
random.shuffle(lines_indexes)
|
|
|
|
|
|
- path_seuil = os.path.join(zone_path, seuil_expe_filename)
|
|
|
|
-
|
|
|
|
counter = 0
|
|
counter = 0
|
|
# check if user select current scene and zone to be part of training data set
|
|
# check if user select current scene and zone to be part of training data set
|
|
for index in lines_indexes:
|
|
for index in lines_indexes:
|
|
|
|
|
|
image_index = int(lines[index].split(';')[0])
|
|
image_index = int(lines[index].split(';')[0])
|
|
- percent = counter / num_lines
|
|
|
|
|
|
|
|
if image_index % _step == 0:
|
|
if image_index % _step == 0:
|
|
- line = construct_new_line(path_seuil, _interval, lines[index], _choice, _each, _norm)
|
|
|
|
|
|
+ line = construct_new_line(scene_thresholds[id_zone], _interval, lines[index], _choice, _each, _norm)
|
|
|
|
|
|
- if id_zone in _zones and folder_scene in _scenes and percent <= _percent:
|
|
|
|
|
|
+ if id_zone in train_zones:
|
|
train_file.write(line)
|
|
train_file.write(line)
|
|
else:
|
|
else:
|
|
test_file.write(line)
|
|
test_file.write(line)
|
|
@@ -213,46 +191,63 @@ def main():
|
|
# getting all params
|
|
# getting all params
|
|
parser = argparse.ArgumentParser(description="Generate data for model using correlation matrix information from data")
|
|
parser = argparse.ArgumentParser(description="Generate data for model using correlation matrix information from data")
|
|
|
|
|
|
- parser.add_argument('--output', type=str, help='output file name desired (.train and .test)')
|
|
|
|
- parser.add_argument('--interval', type=str, help='Interval value to keep from svd', default='"0, 200"')
|
|
|
|
|
|
+ parser.add_argument('--output', type=str, help='output file name desired (.train and .test)', required=True)
|
|
|
|
+ parser.add_argument('--data', type=str, help='folder which contains data of dataset', required=True)
|
|
|
|
+ parser.add_argument('--thresholds', type=str, help='file with scene list information and thresholds', required=True)
|
|
|
|
+ parser.add_argument('--selected_zones', type=str, help='file which contains all selected zones of scene', required=True)
|
|
|
|
+ parser.add_argument('--interval', type=str, help='Interval value to keep from svd', default='"0, 200"', required=True)
|
|
parser.add_argument('--kind', type=str, help='Kind of normalization level wished', choices=normalization_choices)
|
|
parser.add_argument('--kind', type=str, help='Kind of normalization level wished', choices=normalization_choices)
|
|
- parser.add_argument('--feature', type=str, help='feature data choice', choices=features_choices)
|
|
|
|
- parser.add_argument('--scenes', type=str, help='List of scenes to use for training data')
|
|
|
|
- parser.add_argument('--zones', type=str, help='Zones indices to use for training data set')
|
|
|
|
- parser.add_argument('--percent', type=float, help='Percent of data use for train and test dataset (by default 1)', default=1.0)
|
|
|
|
|
|
+ parser.add_argument('--feature', type=str, help='feature data choice', choices=features_choices, required=True)
|
|
parser.add_argument('--step', type=int, help='Photo step to keep for build datasets', default=1)
|
|
parser.add_argument('--step', type=int, help='Photo step to keep for build datasets', default=1)
|
|
parser.add_argument('--each', type=int, help='Each features to keep from interval', default=1)
|
|
parser.add_argument('--each', type=int, help='Each features to keep from interval', default=1)
|
|
- parser.add_argument('--renderer', type=str, help='Renderer choice in order to limit scenes used', choices=renderer_choices, default='all')
|
|
|
|
parser.add_argument('--custom', type=str, help='Name of custom min max file if use of renormalization of data', default=False)
|
|
parser.add_argument('--custom', type=str, help='Name of custom min max file if use of renormalization of data', default=False)
|
|
|
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
|
|
|
p_filename = args.output
|
|
p_filename = args.output
|
|
|
|
+ p_data = args.data
|
|
|
|
+ p_thresholds = args.thresholds
|
|
|
|
+ p_selected_zones = args.selected_zones
|
|
p_interval = list(map(int, args.interval.split(',')))
|
|
p_interval = list(map(int, args.interval.split(',')))
|
|
p_kind = args.kind
|
|
p_kind = args.kind
|
|
p_feature = args.feature
|
|
p_feature = args.feature
|
|
- p_scenes = args.scenes.split(',')
|
|
|
|
- p_zones = list(map(int, args.zones.split(',')))
|
|
|
|
- p_percent = args.percent
|
|
|
|
p_step = args.step
|
|
p_step = args.step
|
|
p_each = args.each
|
|
p_each = args.each
|
|
- p_renderer = args.renderer
|
|
|
|
p_custom = args.custom
|
|
p_custom = args.custom
|
|
|
|
|
|
- # list all possibles choices of renderer
|
|
|
|
- scenes_list = dt.get_renderer_scenes_names(p_renderer)
|
|
|
|
- scenes_indices = dt.get_renderer_scenes_indices(p_renderer)
|
|
|
|
|
|
+ # 1. retrieve human_thresholds
|
|
|
|
+ human_thresholds = {}
|
|
|
|
+
|
|
|
|
+ # extract thresholds
|
|
|
|
+ with open(p_thresholds) as f:
|
|
|
|
+ thresholds_line = f.readlines()
|
|
|
|
+
|
|
|
|
+ for line in thresholds_line:
|
|
|
|
+ data = line.split(';')
|
|
|
|
+ del data[-1] # remove unused last element `\n`
|
|
|
|
+ current_scene = data[0]
|
|
|
|
+ thresholds_scene = data[1:]
|
|
|
|
+
|
|
|
|
+ # TODO : check if really necessary
|
|
|
|
+ if current_scene != '50_shades_of_grey':
|
|
|
|
+ human_thresholds[current_scene] = [ int(threshold) for threshold in thresholds_scene ]
|
|
|
|
+
|
|
|
|
+ # 2. get selected zones
|
|
|
|
+ selected_zones = {}
|
|
|
|
+ with(open(p_selected_zones, 'r')) as f:
|
|
|
|
+
|
|
|
|
+ for line in f.readlines():
|
|
|
|
|
|
- # getting scenes from indexes user selection
|
|
|
|
- scenes_selected = []
|
|
|
|
|
|
+ data = line.split(';')
|
|
|
|
+ del data[-1]
|
|
|
|
+ scene_name = data[0]
|
|
|
|
+ thresholds = data[1:]
|
|
|
|
|
|
- for scene_id in p_scenes:
|
|
|
|
- index = scenes_indices.index(scene_id.strip())
|
|
|
|
- scenes_selected.append(scenes_list[index])
|
|
|
|
|
|
+ selected_zones[scene_name] = [ int(t) for t in thresholds ]
|
|
|
|
|
|
# find min max value if necessary to renormalize data
|
|
# find min max value if necessary to renormalize data
|
|
if p_custom:
|
|
if p_custom:
|
|
- get_min_max_value_interval(scenes_list, p_interval, p_feature)
|
|
|
|
|
|
+ get_min_max_value_interval(p_data, selected_zones, p_interval, p_feature)
|
|
|
|
|
|
# write new file to save
|
|
# write new file to save
|
|
if not os.path.exists(custom_min_max_folder):
|
|
if not os.path.exists(custom_min_max_folder):
|
|
@@ -266,7 +261,7 @@ def main():
|
|
f.write(str(max_value_interval) + '\n')
|
|
f.write(str(max_value_interval) + '\n')
|
|
|
|
|
|
# create database using img folder (generate first time only)
|
|
# create database using img folder (generate first time only)
|
|
- generate_data_model(p_filename, p_interval, p_kind, p_feature, scenes_selected, p_zones, p_percent, p_step, p_each, p_custom)
|
|
|
|
|
|
+ generate_data_model(p_filename, p_data, p_interval, p_kind, p_feature, human_thresholds, selected_zones, p_step, p_each, p_custom)
|
|
|
|
|
|
if __name__== "__main__":
|
|
if __name__== "__main__":
|
|
- main()
|
|
|
|
|
|
+ main()
|