Parcourir la source

Add of low 5 and 6 bits

Jerome Buisine il y a 6 ans
Parent
commit
5f2a74d75b

+ 16 - 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']
+metric_choices = ['lab', 'mscn', 'mscn_revisited', 'low_bits_2', 'low_bits_3', 'low_bits_4', 'low_bits_5', 'low_bits_6']
 
 def generate_data_svd(data_type, mode):
     """
@@ -142,6 +142,21 @@ def generate_data_svd(data_type, mode):
 
                     data = metrics.get_SVD_s(img_mscn_gray)
 
+                if data_type == 'low_bits_6':
+
+                    low_bits_6 = image_processing.rgb_to_LAB_L_low_bits(block, 63)
+
+                    # extract from temp image
+                    data = metrics.get_SVD_s(low_bits_6)
+
+                if data_type == 'low_bits_5':
+
+                    low_bits_5 = image_processing.rgb_to_LAB_L_low_bits(block, 31)
+
+                    # extract from temp image
+                    data = metrics.get_SVD_s(low_bits_5)
+
+
                 if data_type == 'low_bits_4':
 
                     low_bits_4 = image_processing.rgb_to_LAB_L_low_bits(block)

+ 78 - 0
metrics_predictions/predict_noisy_image_svd_low_bits_5.py

@@ -0,0 +1,78 @@
+from sklearn.externals import joblib
+
+from ipfml import image_processing
+from ipfml import metrics
+
+from PIL import Image
+
+import sys, os, getopt
+import numpy as np
+
+min_max_file_path = 'fichiersSVD_light/low_bits_5_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_5_values = metrics.get_SVD_s(image_processing.rgb_to_LAB_L_low_bits(img, 31))
+
+    # 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_5_values, min, max)
+
+    elif p_mode == 'svdn':
+        l_values = image_processing.normalize_arr(low_bits_5_values)
+    else:
+        l_values = low_bits_6_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()

+ 78 - 0
metrics_predictions/predict_noisy_image_svd_low_bits_6.py

@@ -0,0 +1,78 @@
+from sklearn.externals import joblib
+
+from ipfml import image_processing
+from ipfml import metrics
+
+from PIL import Image
+
+import sys, os, getopt
+import numpy as np
+
+min_max_file_path = 'fichiersSVD_light/low_bits_6_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_6_values = metrics.get_SVD_s(image_processing.rgb_to_LAB_L_low_bits(img, 63))
+
+    # 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_6_values, min, max)
+
+    elif p_mode == 'svdn':
+        l_values = image_processing.normalize_arr(low_bits_6_values)
+    else:
+        l_values = low_bits_6_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()

+ 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"}; do
+    for metric in {"lab","mscn","mscn_revisited","low_bits_2","low_bits_3","low_bits_4","low_bits_5","low_bits_6"}; do
         bash generateAndTrain_maxwell.sh ${size} ${metric}
     done
 done