Parcourir la source

Fix folder list issue; Add README;

Jérôme BUISINE il y a 5 ans
Parent
commit
066fc2b99b
6 fichiers modifiés avec 173 ajouts et 26 suppressions
  1. 1 0
      .gitignore
  2. 33 0
      README.md
  3. 7 8
      make_dataset.py
  4. 56 11
      models_info/models_comparisons.csv
  5. 6 7
      reconstruct.py
  6. 70 0
      reconstruct_scene_mean.py

+ 1 - 0
.gitignore

@@ -3,5 +3,6 @@
 
 data
 saved_models
+reconstructed
 
 __pycache__

+ 33 - 0
README.md

@@ -0,0 +1,33 @@
+# Sample Analysis
+
+## Description
+
+The aim of this project is to predict the mean pixel value from monte carlo process rendering in synthesis images using only few samples information in input for model.
+
+
+### Data
+
+Data are all scenes samples information obtained during the rendering process.
+
+For each pixel we have a list of all grey value estimated (samples).
+
+### Models
+List of models tested :
+- Ridge Regression
+- SGD
+- SVR (with rbf kernel)
+
+
+## How to use
+
+First you need to contact **jerome.buisine@univ-littoral.fr** in order to get datatset version. The dataset is not available with this source code.
+
+
+```bash
+python make_dataset.py --n 10 --each_row 8 --each_column 8
+```
+
+```bash
+python reconstruct.py --scene Scene1 --model_path saved_models/Model1.joblib --n 10 --image_name output.png
+```
+

+ 7 - 8
make_dataset.py

@@ -36,20 +36,19 @@ def compute_files(_n, _each_row, _each_column):
     for scene in scenes:
 
         scene_path = os.path.join(cfg.folder_scenes_path, scene)
-        columns_folder = os.listdir(scene_path)
 
-        for id_column, column in enumerate(columns_folder):
+        for id_column in range(cfg.number_of_columns):
 
             if id_column % int(_each_column) == 0 :
 
-                folder_path = os.path.join(scene_path, column)
-
-                pixel_files_list = os.listdir(folder_path)
-
-                for id_row, pixel_file in enumerate(pixel_files_list):
+                folder_path = os.path.join(scene_path, str(id_column))
+                
+                for id_row in range(cfg.number_of_rows):
 
                     if id_row % int(_each_row) == 0:
-                        pixel_file_path = os.path.join(folder_path, pixel_file)
+
+                        pixel_filename = scene + '_' + str(id_column) + '_' + str(id_row) + ".dat"
+                        pixel_file_path = os.path.join(folder_path, pixel_filename)
 
                         saved_row = ''
 

+ 56 - 11
models_info/models_comparisons.csv

@@ -1,11 +1,56 @@
-model_name; number_samples; coeff_of_determination;
-10_column_7_row_7_SGD;60236;0.967103608014;
-10_column_8_row_7_SGD;52096;0.9668493240289788;
-10_column_9_row_7_SGD;46398;0.9657893418797697;
-10_column_10_row_7_SGD;42328;0.9662073687839958;
-10_column_7_row_8_SGD;52096;0.9678400765943843;
-10_column_8_row_8_SGD;45056;0.9717562796162227;
-10_column_9_row_8_SGD;40128;0.9690779553770827;
-10_column_10_row_8_SGD;36608;0.9696013575399688;
-10_column_7_row_9_SGD;46398;0.9698917329738924;
-10_column_8_row_9_SGD;40128;0.9680105640513834;
+model_name; number_of_approximations; coeff_of_determination;
+10_column_7_row_7_SGD;60236;0.9664839093717277;
+10_column_8_row_7_SGD;52096;0.9678826169810406;
+10_column_9_row_7_SGD;46398;0.9675521117545538;
+10_column_10_row_7_SGD;42328;0.9690566006746083;
+10_column_7_row_8_SGD;52096;0.9670321876554149;
+10_column_8_row_8_SGD;45056;0.9675700963072098;
+10_column_9_row_8_SGD;40128;0.9681146909422683;
+10_column_10_row_8_SGD;36608;0.9685975892512967;
+10_column_7_row_9_SGD;46398;0.9659828384202058;
+10_column_8_row_9_SGD;40128;0.9643140500095528;
+10_column_9_row_9_SGD;35739;0.9681206252300265;
+10_column_10_row_9_SGD;32604;0.9675376275385571;
+10_column_7_row_10_SGD;42328;0.9668247142099193;
+10_column_8_row_10_SGD;36608;0.9691928437989377;
+10_column_9_row_10_SGD;32604;0.9664142765421678;
+10_column_10_row_10_SGD;29744;0.96557812475763;
+10_column_7_row_7_Ridge;60236;0.9692904801421809;
+10_column_8_row_7_Ridge;52096;0.9688142127098829;
+10_column_9_row_7_Ridge;46398;0.9690793257605756;
+10_column_10_row_7_Ridge;42328;0.9692175480850063;
+10_column_7_row_8_Ridge;52096;0.9698205957605032;
+10_column_8_row_8_Ridge;45056;0.9687118568270947;
+10_column_9_row_8_Ridge;40128;0.9684702429653922;
+10_column_10_row_8_Ridge;36608;0.9689162994646794;
+10_column_7_row_9_Ridge;46398;0.9681677305109241;
+10_column_8_row_9_Ridge;40128;0.9660094332410658;
+10_column_9_row_9_Ridge;35739;0.9682634948079946;
+10_column_10_row_9_Ridge;32604;0.9676850705782724;
+10_column_7_row_10_Ridge;42328;0.9695503288973929;
+10_column_8_row_10_Ridge;36608;0.9692597134505115;
+10_column_9_row_10_Ridge;32604;0.9687488258562307;
+10_column_10_row_10_Ridge;29744;0.9680152308298698;
+10_column_7_row_7_SVR;60236;0.5717571135650313;
+10_column_8_row_7_SVR;52096;0.6064102246558929;
+10_column_9_row_7_SVR;46398;0.5641867800046533;
+10_column_10_row_7_SVR;42328;0.6150038267137997;
+10_column_7_row_8_SVR;52096;0.6206357673873072;
+10_column_8_row_8_SVR;45056;0.6331979961058917;
+10_column_9_row_8_SVR;40128;0.6217743796094698;
+10_column_10_row_8_SVR;36608;0.5907704117075545;
+10_column_7_row_9_SVR;46398;0.5735147080322717;
+10_column_8_row_9_SVR;40128;0.5360869924085242;
+10_column_9_row_9_SVR;35739;0.5669606458527935;
+10_column_10_row_9_SVR;32604;0.6161197699110612;
+10_column_7_row_10_SVR;42328;0.5742907589869939;
+10_column_8_row_10_SVR;36608;0.5830646274016172;
+10_column_9_row_10_SVR;32604;0.5595641043122157;
+10_column_10_row_10_SVR;29744;0.5683530544960993;
+15_column_7_row_7_SGD;60236;0.9771975053790135;
+15_column_8_row_7_SGD;52096;0.9774661245238926;
+15_column_9_row_7_SGD;46398;0.9798232669284889;
+15_column_10_row_7_SGD;42328;0.9780344702252113;
+15_column_7_row_8_SGD;52096;0.9783939220775737;
+15_column_8_row_8_SGD;45056;0.9763709016819202;
+15_column_9_row_8_SGD;40128;0.9792719020865562;

+ 6 - 7
reconstruct.py

@@ -25,17 +25,16 @@ def reconstruct(_scene_name, _model_path, _n):
     # load scene and its `n` first pixel value data
     scene_path = os.path.join(cfg.folder_scenes_path, _scene_name)
 
-    columns_folder = os.listdir(scene_path)
-    for id_column, column in enumerate(columns_folder):
+    for id_column in range(cfg.number_of_columns):
 
-        folder_path = os.path.join(scene_path, column)
-        pixel_files_list = os.listdir(folder_path)
+        folder_path = os.path.join(scene_path, str(id_column))
 
         pixels = []
-
-        for id_row, pixel_file in enumerate(pixel_files_list):
+        
+        for id_row in range(cfg.number_of_rows):
             
-            pixel_file_path = os.path.join(folder_path, pixel_file)
+            pixel_filename = _scene_name + '_' + str(id_column) + '_' + str(id_row) + ".dat"
+            pixel_file_path = os.path.join(folder_path, pixel_filename)
             
             with open(pixel_file_path, 'r') as f:
 

+ 70 - 0
reconstruct_scene_mean.py

@@ -0,0 +1,70 @@
+import numpy as np
+import pandas as pd
+
+import os, sys, argparse
+
+from sklearn import linear_model
+from sklearn import svm
+from sklearn.utils import shuffle
+
+import modules.config as cfg
+import modules.metrics as metrics
+
+from joblib import dump, load
+
+from PIL import Image
+
+def reconstruct(_scene_name):
+    
+    # construct the empty output image
+    output_image = np.empty([cfg.number_of_rows, cfg.number_of_columns])
+
+    # load scene and its `n` first pixel value data
+    scene_path = os.path.join(cfg.folder_scenes_path, _scene_name)
+
+    for id_column in range(cfg.number_of_columns):
+
+        folder_path = os.path.join(scene_path, str(id_column))
+
+        for id_row in range(cfg.number_of_rows):
+            
+            pixel_filename = _scene_name + '_' + str(id_column) + '_' + str(id_row) + ".dat"
+            pixel_file_path = os.path.join(folder_path, pixel_filename)
+            
+            with open(pixel_file_path, 'r') as f:
+
+                # predict the expected pixel value
+                lines = [float(l) for l in f.readlines()]
+                mean = sum(lines) / float(len(lines))
+                
+            output_image[id_row, id_column] = mean
+
+        print("{0:.2f}%".format(id_column / cfg.number_of_columns * 100))
+        sys.stdout.write("\033[F")
+
+    return output_image
+
+def main():
+
+    parser = argparse.ArgumentParser(description="Train model and saved it")
+
+    parser.add_argument('--scene', type=str, help='Scene name to reconstruct', choices=cfg.scenes_list)
+    parser.add_argument('--image_name', type=str, help="The ouput image name")
+
+    args = parser.parse_args()
+
+    param_scene_name = args.scene
+    param_image_name = args.image_name
+
+    output_image = reconstruct(param_scene_name)
+
+    if not os.path.exists(cfg.reconstructed_folder):
+        os.makedirs(cfg.reconstructed_folder)
+
+    image_path = os.path.join(cfg.reconstructed_folder, param_image_name)
+
+    img = Image.fromarray(np.uint8(output_image))
+    img.save(image_path)
+
+if __name__== "__main__":
+    main()