Ver código fonte

Add of simulation in order to get curves

Jerome Buisine 6 anos atrás
pai
commit
14e77fe8e5

+ 210 - 0
cnn_keras_svd.py

@@ -0,0 +1,210 @@
+from keras.preprocessing.image import ImageDataGenerator
+from keras.models import Sequential
+from keras.layers import Conv1D, MaxPooling1D
+from keras.layers import Activation, Dropout, Flatten, Dense, BatchNormalization
+from keras import backend as K
+import matplotlib.pyplot as plt
+
+from sklearn.utils import shuffle
+
+import numpy as np
+import pandas as pd
+
+from ipfml import image_processing
+from PIL import Image
+
+import sys, os, getopt
+import subprocess
+import time
+
+vector_size = 100
+epochs = 100
+batch_size = 24
+
+input_shape = (vector_size, 1)
+filename = "svd_model"
+
+def f1(y_true, y_pred):
+    def recall(y_true, y_pred):
+        """Recall metric.
+
+        Only computes a batch-wise average of recall.
+
+        Computes the recall, a metric for multi-label classification of
+        how many relevant items are selected.
+        """
+        true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
+        possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
+        recall = true_positives / (possible_positives + K.epsilon())
+        return recall
+
+    def precision(y_true, y_pred):
+        """Precision metric.
+
+        Only computes a batch-wise average of precision.
+
+        Computes the precision, a metric for multi-label classification of
+        how many selected items are relevant.
+        """
+        true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
+        predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
+        precision = true_positives / (predicted_positives + K.epsilon())
+        return precision
+    precision = precision(y_true, y_pred)
+    recall = recall(y_true, y_pred)
+    return 2*((precision*recall)/(precision+recall+K.epsilon()))
+
+def generate_model():
+
+    model = Sequential()
+
+    #model.add(Conv1D(128, (10), input_shape=input_shape))
+    #model.add(Activation('relu'))
+
+    #model.add(Conv1D(128, (10)))
+    #model.add(Activation('relu'))
+
+    #model.add(Conv1D(128, (10)))
+    #model.add(Activation('relu'))
+    #model.add(MaxPooling1D(pool_size=(2)))
+
+    #model.add(Conv1D(64, (10)))
+    #model.add(Activation('relu'))
+
+    #model.add(Conv1D(64, (10)))
+    #model.add(Activation('relu'))
+
+    #model.add(Conv1D(64, (10)))
+    #model.add(Activation('relu'))
+    #model.add(MaxPooling1D(pool_size=(2)))
+
+    #model.add(Conv1D(32, (10)))
+    #model.add(Activation('relu'))
+
+    #model.add(Conv1D(32, (10)))
+    #model.add(Activation('relu'))
+
+    #model.add(Conv1D(32, (10)))
+    #model.add(Activation('relu'))
+    #model.add(MaxPooling1D(pool_size=(2)))
+
+    model.add(Flatten(input_shape=input_shape))
+
+    #model.add(Dense(2048))
+    #model.add(Activation('relu'))
+    #model.add(BatchNormalization())
+    #model.add(Dropout(0.3))
+
+    model.add(Dense(1024))
+    model.add(Activation('relu'))
+    model.add(BatchNormalization())
+    model.add(Dropout(0.4))
+
+    model.add(Dense(512))
+    model.add(Activation('relu'))
+    model.add(BatchNormalization())
+    model.add(Dropout(0.4))
+
+    model.add(Dense(256))
+    model.add(Activation('relu'))
+    model.add(BatchNormalization())
+    model.add(Dropout(0.4))
+
+    model.add(Dense(128))
+    model.add(Activation('relu'))
+    model.add(BatchNormalization())
+    model.add(Dropout(0.4))
+
+    model.add(Dense(20))
+    model.add(Activation('relu'))
+    model.add(BatchNormalization())
+    model.add(Dropout(0.4))
+
+    model.add(Dense(1))
+    model.add(Activation('sigmoid'))
+
+    model.compile(loss='binary_crossentropy',
+                  optimizer='adam',
+                  metrics=['accuracy', f1])
+
+    return model
+
+def main():
+
+    if len(sys.argv) <= 1:
+        print('Run with default parameters...')
+        print('python save_model_result_in_md.py --data filename')
+        sys.exit(2)
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "hd", ["help=", "data="])
+    except getopt.GetoptError:
+        # print help information and exit:
+        print('python save_model_result_in_md.py --data filename')
+        sys.exit(2)
+    for o, a in opts:
+        if o == "-h":
+            print('python save_model_result_in_md.py --data filename')
+            sys.exit()
+        elif o in ("-d", "--data"):
+            p_datafile = a
+        else:
+            assert False, "unhandled option"
+
+    ###########################
+    # 1. Get and prepare data
+    ###########################
+    dataset_train = pd.read_csv(p_datafile + '.train', header=None, sep=";")
+    dataset_test = pd.read_csv(p_datafile + '.test', header=None, sep=";")
+
+    # default first shuffle of data
+    dataset_train = shuffle(dataset_train)
+    dataset_test = shuffle(dataset_test)
+
+    # get dataset with equal number of classes occurences
+    noisy_df_train = dataset_train[dataset_train.ix[:, 0] == 1]
+    not_noisy_df_train = dataset_train[dataset_train.ix[:, 0] == 0]
+    nb_noisy_train = len(noisy_df_train.index)
+
+    noisy_df_test = dataset_test[dataset_test.ix[:, 0] == 1]
+    not_noisy_df_test = dataset_test[dataset_test.ix[:, 0] == 0]
+    nb_noisy_test = len(noisy_df_test.index)
+
+    final_df_train = pd.concat([not_noisy_df_train[0:nb_noisy_train], noisy_df_train])
+    final_df_test = pd.concat([not_noisy_df_test[0:nb_noisy_test], noisy_df_test])
+
+    # shuffle data another time
+    final_df_train = shuffle(final_df_train)
+    final_df_test = shuffle(final_df_test)
+
+    final_df_train_size = len(final_df_train.index)
+    final_df_test_size = len(final_df_test.index)
+
+    # use of the whole data set for training
+    x_dataset_train = final_df_train.ix[:,1:]
+    x_dataset_test = final_df_test.ix[:,1:]
+
+    y_dataset_train = final_df_train.ix[:,0]
+    y_dataset_test = final_df_test.ix[:,0]
+
+    #######################
+    # 2. Getting model
+    #######################
+
+    model = generate_model()
+    model.summary()
+
+    #######################
+    # 3. Fit model : use of cross validation to fit model
+    #######################
+
+    # reshape input data
+    x_dataset_train = np.array(x_dataset_train).reshape(len(x_dataset_train), vector_size, 1)
+    x_dataset_test = np.array(x_dataset_test).reshape(len(x_dataset_test), vector_size, 1)
+
+    model.fit(x_dataset_train, y_dataset_train, epochs=epochs, batch_size=batch_size, validation_split=0.20)
+
+    score = model.evaluate(x_dataset_test, y_dataset_test, batch_size=batch_size)
+    print(score)
+
+if __name__== "__main__":
+    main()

+ 6 - 1
generate_all_data.py

@@ -32,7 +32,7 @@ path = './fichiersSVD_light'
 zones = np.arange(16)
 seuil_expe_filename = 'seuilExpe'
 
-metric_choices = ['lab', 'mscn', 'mscn_revisited', 'low_bits_2', 'low_bits_3', 'low_bits_4', 'low_bits_5', 'low_bits_6']
+metric_choices = ['lab', 'mscn', 'mscn_revisited', 'low_bits_2', 'low_bits_3', 'low_bits_4', 'low_bits_5', 'low_bits_6','low_bits_4_shifted_2']
 
 def generate_data_svd(data_type, mode):
     """
@@ -178,6 +178,11 @@ def generate_data_svd(data_type, mode):
                     # extract from temp image
                     data = metrics.get_SVD_s(low_bits_2)
 
+                if data_type == 'low_bits_4_shifted_2':
+
+                    data = metrics.get_SVD_s(image_processing.rgb_to_LAB_L_bits(block, (3, 6)))
+
+
                 ##################
                 # Data mode part #
                 ##################

+ 29 - 12
helpful_scripts/display_scenes_zones.py

@@ -33,7 +33,7 @@ seuil_expe_filename = 'seuilExpe'
 
 metric_choices = ['lab', 'mscn', 'mscn_revisited', 'low_bits_2', 'low_bits_3', 'low_bits_4', 'low_bits_5', 'low_bits_6']
 
-def display_data_scenes(data_type, p_scene):
+def display_data_scenes(data_type, p_scene, p_kind):
     """
     @brief Method which generates all .csv files from scenes photos
     @param path - path of scenes folder information
@@ -193,22 +193,35 @@ def display_data_scenes(data_type, p_scene):
                     ##################
 
                     # modify data depending mode
-                    data = image_processing.normalize_arr(data)
+
+                    if p_kind == 'svdn':
+                        data = image_processing.normalize_arr(data)
+
+                    if p_kind == 'svdne':
+                        path_min_max = os.path.join(path, data_type + min_max_filename)
+
+                        with open(path_min_max, 'r') as f:
+                            min_val = float(f.readline())
+                            max_val = float(f.readline())
+
+                        data = image_processing.normalize_arr_with_range(data, min_val, max_val)
+
+                    # append of data
                     images_data.append(data)
 
                 zones_images_data.append(images_data)
 
             fig=plt.figure(figsize=(8, 8))
-            fig.suptitle(data_type + " values for " + p_scene + " scene", fontsize=20)
+            fig.suptitle(data_type + " values for " + p_scene + " scene (normalization : " + p_kind + ")", fontsize=20)
 
             for id, data in enumerate(zones_images_data):
                 fig.add_subplot(4, 4, (id + 1))
                 plt.plot(data[0], label='Noisy_' + start_index_image)
                 plt.plot(data[1], label='Threshold_' + threshold_info[id])
                 plt.plot(data[2], label='Reference_' + end_index_image)
-                plt.ylabel(data_type + ' SVD, ZONE_' + str(id + 1), fontsize=14)
-                plt.xlabel('Vector features', fontsize=16)
-                plt.legend(bbox_to_anchor=(0.5, 1), loc=2, borderaxespad=0.2, fontsize=14)
+                plt.ylabel(data_type + ' SVD, ZONE_' + str(id + 1), fontsize=18)
+                plt.xlabel('Vector features', fontsize=18)
+                plt.legend(bbox_to_anchor=(0.5, 1), loc=2, borderaxespad=0.2, fontsize=18)
                 plt.ylim(0, 0.1)
             plt.show()
 
@@ -216,18 +229,17 @@ def main():
 
     if len(sys.argv) <= 1:
         print('Run with default parameters...')
-        print('python generate_all_data.py --metric all --scene A')
-        print('python generate_all_data.py --metric lab --scene A')
+        print('python generate_all_data.py --metric all --scene A --kind svdn')
         sys.exit(2)
     try:
-        opts, args = getopt.getopt(sys.argv[1:], "hm", ["help=", "metric=", "scene="])
+        opts, args = getopt.getopt(sys.argv[1:], "hm:s:k", ["help=", "metric=", "scene=", "kind="])
     except getopt.GetoptError:
         # print help information and exit:
-        print('python generate_all_data.py --metric all --scene A')
+        print('python generate_all_data.py --metric all --scene A --kind svdn')
         sys.exit(2)
     for o, a in opts:
         if o == "-h":
-            print('python generate_all_data.py --metric all --scene A')
+            print('python generate_all_data.py --metric all --scene A --kind svdn')
             sys.exit()
         elif o in ("-m", "--metric"):
             p_metric = a
@@ -241,11 +253,16 @@ def main():
                 assert False, "Invalid metric choice"
             else:
                 p_scene = scenes_list[scenes_indexes.index(p_scene)]
+        elif o in ("-k", "--kind"):
+            p_kind = a
+
+            if p_kind not in choices:
+                assert False, "Invalid metric choice"
         else:
             assert False, "unhandled option"
 
 
-    display_data_scenes(p_metric, p_scene)
+    display_data_scenes(p_metric, p_scene, p_kind)
 
 if __name__== "__main__":
     main()

+ 42 - 0
helpful_scripts/display_svd_values.py

@@ -12,6 +12,10 @@ low_bits_3_svd_values = []
 
 low_bits_4_svd_values = []
 
+low_bits_5_svd_values = []
+
+low_bits_6_svd_values = []
+
 mscn_revisited_svd_values = []
 
 mscn_svd_values = []
@@ -77,6 +81,26 @@ def open_and_display(path):
 
     low_bits_4_svd_values.append(low_bits_svd)
 
+    # computation of low bits parts 5 bits
+    low_bits_block = image_processing.rgb_to_LAB_L_low_bits(block_used, 31)
+
+    low_bits_svd = metrics.get_SVD_s(low_bits_block)
+
+    low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
+
+    low_bits_5_svd_values.append(low_bits_svd)
+
+    # computation of low bits parts 6 bits
+    low_bits_block = image_processing.rgb_to_LAB_L_low_bits(block_used, 63)
+
+    low_bits_svd = metrics.get_SVD_s(low_bits_block)
+
+    low_bits_svd = [b / low_bits_svd[0] for b in low_bits_svd]
+
+    low_bits_6_svd_values.append(low_bits_svd)
+
+
+
     # Other MSCN
     img_grey = np.array(color.rgb2gray(np.asarray(block_used))*255, 'uint8')
 
@@ -162,3 +186,21 @@ plt.xlabel('Vector features')
 plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
 plt.ylim(0, 0.1)
 plt.show()
+
+plt.plot(low_bits_5_svd_values[0], label='Noisy')
+plt.plot(low_bits_5_svd_values[1], label='Threshold')
+plt.plot(low_bits_5_svd_values[2], label='Reference')
+plt.ylabel('Low 5 bits SVD')
+plt.xlabel('Vector features')
+plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
+plt.ylim(0, 0.1)
+plt.show()
+
+plt.plot(low_bits_6_svd_values[0], label='Noisy')
+plt.plot(low_bits_6_svd_values[1], label='Threshold')
+plt.plot(low_bits_6_svd_values[2], label='Reference')
+plt.ylabel('Low 6 bits SVD')
+plt.xlabel('Vector features')
+plt.legend(bbox_to_anchor=(0.7, 1), loc=2, borderaxespad=0.2)
+plt.ylim(0, 0.1)
+plt.show()

+ 78 - 0
metrics_predictions/predict_noisy_image_svd_low_bits_4_shifted_2.py

@@ -0,0 +1,78 @@
+from sklearn.externals import joblib
+
+import numpy as np
+
+from ipfml import image_processing
+from ipfml import metrics
+from PIL import Image
+
+import sys, os, getopt
+
+min_max_file_path = 'fichiersSVD_light/low_bits_4_shifted_2_min_max_values'
+
+def main():
+
+    if len(sys.argv) <= 1:
+        print('Run with default parameters...')
+        print('python predict_noisy_image_svd_lab.py --image path/to/xxxx --interval "0,20" --model path/to/xxxx.joblib --mode ["svdn", "svdne"]')
+        sys.exit(2)
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "hi:t:m:o", ["help=", "image=", "interval=", "model=", "mode="])
+    except getopt.GetoptError:
+        # print help information and exit:
+        print('python predict_noisy_image_svd_lab.py --image path/to/xxxx --interval "xx,xx" --model path/to/xxxx.joblib --mode ["svdn", "svdne"]')
+        sys.exit(2)
+    for o, a in opts:
+        if o == "-h":
+            print('python predict_noisy_image_svd_lab.py --image path/to/xxxx --interval "xx,xx" --model path/to/xxxx.joblib --mode ["svdn", "svdne"]')
+            sys.exit()
+        elif o in ("-i", "--image"):
+            p_img_file = os.path.join(os.path.join(os.path.dirname(__file__),'../'), a)
+        elif o in ("-t", "--interval"):
+            p_interval = list(map(int, a.split(',')))
+        elif o in ("-m", "--model"):
+            p_model_file = os.path.join(os.path.join(os.path.dirname(__file__),'../'), a)
+        elif o in ("-o", "--mode"):
+            p_mode = a
+
+            if p_mode != 'svdn' and p_mode != 'svdne' and p_mode != 'svd':
+                assert False, "Mode not recognized"
+        else:
+            assert False, "unhandled option"
+
+    # load of model file
+    model = joblib.load(p_model_file)
+
+    # load image
+    img = Image.open(p_img_file)
+    low_bits_4_shifted_2_values = metrics.get_SVD_s(image_processing.rgb_to_LAB_L_bits(block_used, (3, 6)))
+
+    # check mode to normalize data
+    if p_mode == 'svdne':
+
+        # need to read min_max_file
+        file_path = os.path.join(os.path.join(os.path.dirname(__file__),'../'), min_max_file_path)
+        with open(file_path, 'r') as f:
+            min = float(f.readline().replace('\n', ''))
+            max = float(f.readline().replace('\n', ''))
+
+        l_values = image_processing.normalize_arr_with_range(low_bits_4_shifted_2_values, min, max)
+
+    elif p_mode == 'svdn':
+        l_values = image_processing.normalize_arr(low_bits_4_shifted_2_values)
+    else:
+        l_values = low_bits_4_shifted_2_values
+
+
+    # get interval values
+    begin, end = p_interval
+    test_data = l_values[begin:end]
+
+    # get prediction of model
+    prediction = model.predict([test_data])[0]
+
+    print(prediction)
+
+
+if __name__== "__main__":
+    main()

+ 13 - 13
predict_seuil_expe_maxwell.py

@@ -49,7 +49,7 @@ def main():
 
             if p_mode != 'svdn' and p_mode != 'svdne' and p_mode != 'svd':
                 assert False, "Mode not recognized"
-    
+
         elif o in ("-m", "--metric"):
             p_metric = a
         elif o in ("-l", "--limit_detection"):
@@ -58,16 +58,16 @@ def main():
             assert False, "unhandled option"
 
     scenes = os.listdir(scenes_path)
-    
+
     if min_max_filename in scenes:
         scenes.remove(min_max_filename)
 
     # go ahead each scenes
     for id_scene, folder_scene in enumerate(scenes):
-    
+
         # only take in consideration maxwell scenes
         if folder_scene in maxwell_scenes:
-    
+
             print(folder_scene)
 
             scene_path = os.path.join(scenes_path, folder_scene)
@@ -111,7 +111,7 @@ def main():
             check_all_done = False
 
             while(current_counter_index <= end_counter_index and not check_all_done):
-                
+
                 current_counter_index_str = str(current_counter_index)
 
                 while len(start_index_image) > len(current_counter_index_str):
@@ -126,7 +126,7 @@ def main():
                 check_all_done = all(d == True for d in threshold_expes_detected)
 
                 for id_block, block in enumerate(img_blocks):
-                    
+
                     # check only if necessary for this scene (not already detected)
                     if not threshold_expes_detected[id_block]:
 
@@ -140,9 +140,9 @@ def main():
 
                         ## call command ##
                         p = subprocess.Popen(python_cmd, stdout=subprocess.PIPE, shell=True)
-                        
+
                         (output, err) = p.communicate()
-                        
+
                         ## Wait for result ##
                         p_status = p.wait()
 
@@ -152,7 +152,7 @@ def main():
                             threshold_expes_counter[id_block] = threshold_expes_counter[id_block] + 1
                         else:
                             threshold_expes_counter[id_block] = 0
-                        
+
                         if threshold_expes_counter[id_block] == p_limit:
                             threshold_expes_detected[id_block] = True
                             threshold_expes_found[id_block] = current_counter_index
@@ -161,14 +161,14 @@ def main():
 
                 current_counter_index += step_counter
                 print("------------------------")
-                print("Scene " + str(id_scene + 1) + "/" + str(len(scenes)))
+                print("Scene " + str(id_scene + 1) + "/" + str(len(maxwell_scenes)))
                 print("------------------------")
 
             # end of scene => display of results
 
             # construct path using model name for saving threshold map folder
             model_treshold_path = os.path.join(threshold_map_folder, p_model_file.split('/')[-1].replace('.joblib', ''))
-            
+
             # create threshold model path if necessary
             if not os.path.exists(model_treshold_path):
                 os.makedirs(model_treshold_path)
@@ -191,7 +191,7 @@ def main():
                 if (id + 1) % 4 == 0:
                     f_map.write(line_information + '\n')
                     line_information = ""
-            
+
             f_map.write(line_information + '\n')
 
             min_abs_dist = min(abs_dist)
@@ -220,4 +220,4 @@ def main():
 
 
 if __name__== "__main__":
-    main()
+    main()

+ 179 - 0
predict_seuil_expe_maxwell_curve.py

@@ -0,0 +1,179 @@
+from sklearn.externals import joblib
+
+import numpy as np
+
+from ipfml import image_processing
+from PIL import Image
+
+import sys, os, getopt
+import subprocess
+import time
+
+current_dirpath = os.getcwd()
+
+config_filename   = "config"
+scenes_path = './fichiersSVD_light'
+min_max_filename = '_min_max_values'
+threshold_expe_filename = 'seuilExpe'
+tmp_filename = '/tmp/__model__img_to_predict.png'
+
+maxwell_scenes = ['Appart1opt02', 'Cuisine01', 'SdbCentre', 'SdbDroite']
+
+threshold_map_folder = "threshold_map"
+simulation_curves_zones = "simulation_curves_zones_"
+
+zones = np.arange(16)
+
+def main():
+
+    if len(sys.argv) <= 1:
+        print('Run with default parameters...')
+        print('python predict_seuil_expe_maxwell.py --interval "0,20" --model path/to/xxxx.joblib --mode svdn --metric lab --limit_detection xx')
+        sys.exit(2)
+    try:
+        opts, args = getopt.getopt(sys.argv[1:], "ht:m:o:l", ["help=", "interval=", "model=", "mode=", "metric=", "limit_detection="])
+    except getopt.GetoptError:
+        # print help information and exit:
+        print('python predict_seuil_expe_maxwell.py --interval "xx,xx" --model path/to/xxxx.joblib --mode svdn --metric lab --limit_detection xx')
+        sys.exit(2)
+    for o, a in opts:
+        if o == "-h":
+            print('python predict_seuil_expe_maxwell.py --interval "xx,xx" --model path/to/xxxx.joblib --mode svdn --metric lab --limit_detection xx')
+            sys.exit()
+        elif o in ("-t", "--interval"):
+            p_interval = a
+        elif o in ("-m", "--model"):
+            p_model_file = a
+        elif o in ("-o", "--mode"):
+            p_mode = a
+
+            if p_mode != 'svdn' and p_mode != 'svdne' and p_mode != 'svd':
+                assert False, "Mode not recognized"
+
+        elif o in ("-m", "--metric"):
+            p_metric = a
+        elif o in ("-l", "--limit_detection"):
+            p_limit = int(a)
+        else:
+            assert False, "unhandled option"
+
+    scenes = os.listdir(scenes_path)
+
+    if min_max_filename in scenes:
+        scenes.remove(min_max_filename)
+
+    # go ahead each scenes
+    for id_scene, folder_scene in enumerate(scenes):
+
+        # only take in consideration maxwell scenes
+        if folder_scene in maxwell_scenes:
+
+            print(folder_scene)
+
+            scene_path = os.path.join(scenes_path, folder_scene)
+
+            config_path = os.path.join(scene_path, config_filename)
+
+            with open(config_path, "r") as config_file:
+                last_image_name = config_file.readline().strip()
+                prefix_image_name = config_file.readline().strip()
+                start_index_image = config_file.readline().strip()
+                end_index_image = config_file.readline().strip()
+                step_counter = int(config_file.readline().strip())
+
+            threshold_expes = []
+            threshold_expes_found = []
+            block_predictions_str = []
+
+            # get zones list info
+            for index in zones:
+                index_str = str(index)
+                if len(index_str) < 2:
+                    index_str = "0" + index_str
+                zone_folder = "zone"+index_str
+
+                threshold_path_file = os.path.join(os.path.join(scene_path, zone_folder), threshold_expe_filename)
+
+                with open(threshold_path_file) as f:
+                    threshold = int(f.readline())
+                    threshold_expes.append(threshold)
+
+                    # Initialize default data to get detected model threshold found
+                    threshold_expes_found.append(int(end_index_image)) # by default use max
+
+                block_predictions_str.append(index_str + ";" + p_model_file + ";" + str(threshold) + ";" + str(start_index_image) + ";" + str(step_counter))
+
+            current_counter_index = int(start_index_image)
+            end_counter_index = int(end_index_image)
+
+            print(current_counter_index)
+
+            while(current_counter_index <= end_counter_index):
+
+                current_counter_index_str = str(current_counter_index)
+
+                while len(start_index_image) > len(current_counter_index_str):
+                    current_counter_index_str = "0" + current_counter_index_str
+
+                img_path = os.path.join(scene_path, prefix_image_name + current_counter_index_str + ".png")
+
+                current_img = Image.open(img_path)
+                img_blocks = image_processing.divide_in_blocks(current_img, (200, 200))
+
+                for id_block, block in enumerate(img_blocks):
+
+                    # check only if necessary for this scene (not already detected)
+                    #if not threshold_expes_detected[id_block]:
+
+                        tmp_file_path = tmp_filename.replace('__model__',  p_model_file.split('/')[-1].replace('.joblib', '_'))
+                        block.save(tmp_file_path)
+
+                        python_cmd = "python metrics_predictions/predict_noisy_image_svd_" + p_metric + ".py --image " + tmp_file_path + \
+                                        " --interval '" + p_interval + \
+                                        "' --model " + p_model_file  + \
+                                        " --mode " + p_mode
+
+                        ## call command ##
+                        p = subprocess.Popen(python_cmd, stdout=subprocess.PIPE, shell=True)
+
+                        (output, err) = p.communicate()
+
+                        ## Wait for result ##
+                        p_status = p.wait()
+
+                        prediction = int(output)
+
+                        # save here in specific file of block all the predictions done
+                        block_predictions_str[id_block] = block_predictions_str[id_block] + ";" + str(prediction)
+
+                        print(str(id_block) + " : " + str(current_counter_index) + "/" + str(threshold_expes[id_block]) + " => " + str(prediction))
+
+                current_counter_index += step_counter
+                print("------------------------")
+                print("Scene " + str(id_scene + 1) + "/" + str(len(scenes)))
+                print("------------------------")
+
+            # end of scene => display of results
+
+            # construct path using model name for saving threshold map folder
+            model_treshold_path = os.path.join(threshold_map_folder, p_model_file.split('/')[-1].replace('.joblib', ''))
+
+            # create threshold model path if necessary
+            if not os.path.exists(model_treshold_path):
+                os.makedirs(model_treshold_path)
+
+            map_filename = os.path.join(model_treshold_path, simulation_curves_zones + folder_scene)
+            f_map = open(map_filename, 'w')
+
+            for line in block_predictions_str:
+                f_map.write(line + '\n')
+            f_map.close()
+
+            print("Scene " + str(id_scene + 1) + "/" + str(len(maxwell_scenes)) + " Done..")
+            print("------------------------")
+
+            time.sleep(10)
+
+
+if __name__== "__main__":
+    main()

+ 1 - 1
runAll_maxwell.sh

@@ -18,7 +18,7 @@ fi
 
 for size in {"4","8","16","26","32","40"}; do
 
-    for metric in {"lab","mscn","mscn_revisited","low_bits_2","low_bits_3","low_bits_4","low_bits_5","low_bits_6"}; do
+    for metric in {"lab","mscn","mscn_revisited","low_bits_2","low_bits_3","low_bits_4","low_bits_5","low_bits_6","low_bits_shifted_2"}; do
         bash generateAndTrain_maxwell.sh ${size} ${metric}
     done
 done

+ 1 - 1
run_maxwell_simulation.sh

@@ -8,7 +8,7 @@ scenes="A, D, G, H"
 VECTOR_SIZE=200
 
 for size in {"4","8","16","26","32","40"}; do
-    for metric in {"lab","mscn","mscn_revisited","low_bits_2","low_bits_3","low_bits_4"}; do
+    for metric in {"lab","mscn","mscn_revisited","low_bits_2","low_bits_3","low_bits_4","low_bits_5","low_bits_6","low_bits_4_shifted_2"}; do
 
         half=$(($size/2))
         start=-$half