Explorar el Código

Add of script generator

Jerome Buisine hace 6 años
padre
commit
e1a8d9154f
Se han modificado 7 ficheros con 27083 adiciones y 0 borrados
  1. 11 0
      .gitignore
  2. 9 0
      LICENCE
  3. 23 0
      README.md
  4. 150 0
      generate_data.py
  5. 10 0
      requirements.txt
  6. 15616 0
      test.test
  7. 11264 0
      test.train

+ 11 - 0
.gitignore

@@ -0,0 +1,11 @@
+# project data
+data
+.python-version
+__pycache__
+
+# by default avoid model files and png files
+*.h5
+*.png
+!saved_models/*.h5
+!saved_models/*.png
+.vscode

+ 9 - 0
LICENCE

@@ -0,0 +1,9 @@
+MIT License
+Copyright (c) <year> <copyright holders>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+

+ 23 - 0
README.md

@@ -0,0 +1,23 @@
+# Noise detection using SVM
+
+## Requirements
+
+```
+pip install -r requirements.txt
+```
+
+## How to use
+
+Generate data .csv files (run only once time or clean data folder before) :
+
+```
+python generate_data.py
+```
+
+## Models
+
+*Documentation will be implemented later...*
+
+## How to contribute
+
+This git project uses [git-flow](https://danielkummer.github.io/git-flow-cheatsheet/) implementation. You are free to contribute to it.

+ 150 - 0
generate_data.py

@@ -0,0 +1,150 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+Created on Fri Sep 14 21:02:42 2018
+
+@author: jbuisine
+"""
+
+from __future__ import print_function
+import sys, os
+import numpy as np
+import random
+import time
+
+config_filename   = "config"
+zone_folder       = "zone"
+min_max_filename  = "min_max_values"
+output_file_svd   = "SVD_LAB_test_im6.csv"
+output_file_svdn  = "SVDN_LAB_test_im6.csv"
+output_file_svdne = "SVDNE_LAB_test_im6.csv" 
+
+# define all scenes values
+scenes = ['Appart1opt02', 'Bureau1', 'Cendrier', 'EchecsBas', 'PNDVuePlongeante', 'SdbCentre', 'SdbDroite', 'Selles']
+choices = ['svd', 'svdn', 'svdne']
+path = './data'
+zones = np.arange(16)
+file_choice = [output_file_svd, output_file_svdn, output_file_svdne]
+seuil_expe_filename = 'seuilExpe'
+
+def generate_data_svd_lab():
+    """
+    @brief Method which generates all .csv files from scenes photos
+    @param path - path of scenes folder information
+    @return nothing
+    """
+
+    # TODO : 
+    # - parcourir chaque dossier de scene
+    scenes = os.listdir(path)
+
+    for folder_scene in scenes:
+
+        folder_path = path + "/" + folder_scene
+
+        with open(folder_path + "/" + config_filename, "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())
+
+        
+        current_counter_index = int(start_index_image)
+        end_counter_index = int(start_index_image)
+
+        print(current_counter_index)
+        while(current_counter_index <= end_index_image):
+            print(current_counter_index)
+            current_counter_index += step_counter
+
+    # - récupérer les informations des fichiers de configurations
+    # - création des fichiers de sortie SVD, SVDE, SVDNE
+
+def construct_new_line(path_seuil, interval, line, sep):
+    begin, end = interval
+
+    line_data = line.split(';')
+    seuil = line_data[0]
+    metrics = line_data[begin+1:end]
+
+    with open(path_seuil, "r") as seuil_file:
+        seuil_learned = int(seuil_file.readline().strip())
+       
+    if seuil_learned > int(seuil):
+        line = '0'
+    else:
+        line = '1'
+
+    for idx, val in enumerate(metrics):
+        line += " " + str(idx + 1) + ":" + val
+    line += '\n'
+    
+    return line
+
+def generate_data_svm(_filename, _interval, _choice, _scenes = scenes, _zones = zones, _percent = 1, _sep=':'):
+
+    output_train_filename = _filename + ".train"
+    output_test_filename = _filename + ".test"
+
+    train_file = open(output_train_filename, 'w')
+    test_file = open(output_test_filename, 'w')
+
+    scenes = os.listdir(path)
+
+    for id_scene, folder_scene in enumerate(scenes):
+        scene_path = path + "/" + folder_scene
+        
+        print("Current path scene : " + scene_path)
+        zones_folder = []
+        # create zones list
+        for index in zones:
+            index_str = str(index)
+            if len(index_str) < 2:
+                index_str = "0" + index_str
+            zones_folder.append("zone"+index_str)
+
+        for id_zone, zone_folder in enumerate(zones_folder):
+            print(zone_folder)
+            zone_path = scene_path + "/" + zone_folder
+            data_filename = file_choice[choices.index(_choice)]
+            data_file_path = zone_path + "/" + data_filename
+            print(data_file_path)
+
+            print(id_zone in _zones)
+
+             # getting number of line and read randomly lines
+            f = open(data_file_path)       
+            lines = f.readlines()
+            #num_lines = sum(1 for line in open(data_file_path))
+            
+            num_lines = len(lines)
+
+            lines_indexes = np.arange(num_lines)
+            random.shuffle(lines_indexes)
+
+            path_seuil = zone_path + "/" + seuil_expe_filename
+
+            # check if user select current scene and zone to be part of training data set
+            for index in lines_indexes:
+                line = construct_new_line(path_seuil, _interval, lines[index], _sep)
+
+                if id_zone in _zones and folder_scene in _scenes:
+                    train_file.write(line)
+                else:
+                    test_file.write(line)
+
+            f.close()
+
+    train_file.close()
+    test_file.close()
+                
+
+
+def main():
+
+    # create database using img folder (generate first time only)
+    generate_data_svm('test', [20, 100], 'svdne', _scenes=['Appart1opt02', 'Bureau1', 'Cendrier', 'EchecsBas', 'PNDVuePlongeante', 'SdbCentre'], _zones=[2, 3, 7, 8, 9, 10, 15, 0])
+
+if __name__== "__main__":
+    main()

+ 10 - 0
requirements.txt

@@ -0,0 +1,10 @@
+IPFML
+sklearn
+scikit-image
+tensorflow
+keras
+image_slicer
+Pillow
+pydot
+matplotlib
+path.py

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 15616 - 0
test.test


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 11264 - 0
test.train