Skip to content

Repository files navigation

Identifying Impurities in Vials’ Liquid

Installation

Create a Virtual Environment

Required packages

pip install -r requirements.txt

Dataset Directory Structure

Data organization begins with the root folder DATASET_NAME. This root folder holds a set of subfolders, each corresponding to a class of vials and named accordingly. Within each class folder, there are varying numbers of subfolders, each containing captured frames.

DATASET_NAME
|-- CLASS_1
|   |-- SUBFOLDER_01
|   |   |-- img_01
|   |   |-- ...
|   |   |-- img_19 
|   |   |-- ...
|   |-- ...
|-- CLASS_2 
|   |-- SUBFOLDER_01
|   |   |-- img_01
|   |   |-- ...
|   |   |-- img_19     
|   |   |-- ...
|   |-- ...
|-- CLASS_3
|   |-- SUBFOLDER_01
|   |   |-- img_01
|   |   |-- ...
|   |   |-- img_19 
|   |   |...
|   |...  
|-- CLASS_4
|   |-- SUBFOLDER_01
|   |   |-- img_01
|   |   |-- ...
|   |   |-- img_19 
|   |   |--...
|   |...    

dataset.py

The script dataset.py is launched with a dedicated configuration file (dataset.conf), which includes the following commands. These three commands must be executed in sequence. To run a specific command, the other two commands must be commented out in the configuration file.

1) Command: make sequences

This command generates a sequence file from a root folder that contains the original dataset.

make_sequences  
[input_folder]   # Input folder  
[sequences.pkl]  # Output file name

2) Command: make split

This command generates dataset splits into training and testing sets. It has two split modes, specified through optional arguments.

make_split    
[--numtrain]      # 1) [--numtrain] and [--perctrain] are mutually exclusive, choose one and comment the other  
[--perctrain]     # 2)  
[sequences.pkl]   # Input file name  
[split01.pkl]     # Split output file name  

3) Command: make_tensors

This command generates cropped tensors from images, each tensor file corresponds to a sequence of 19 frames.

make_tensors  
[--crop_box]                     # Coordinates to crop the frame : (left, upper, right, lower) (old dataset : crop_box=874,275,1199,543)
[--single_channel]               # True or false
[--cropped_folder]               # None for no save, otherwise specify the name of the folder  
[split01.pkl]                    # Input split file name  
[tensors01]                      # Output tensors folder  

Example usage

Once you have chosen the command to execute and commented out the other two, the script can be run as follows:

$ python dataset.py  @dataset.conf

The final result is a folder containing the tensors and the 'info.pkl' file:

tensors01
|-- Train
|   |   | Black0166.lz4
|   |   | Black0167.lz4
|   |   | Brown0196.lz4
|   |   | Sabbia0106.lz4
|   |   |-- ...
|   |-- ...
|-- Test 
|   |   | Black006.lz4
|   |   | Buoni099.lz4
|   |   | Vetro087.lz4   
|   |   |-- ...
|info.pkl

PBL_ResNet_Train.py

This script is used to train the model in either the multiclass version or the binary classifiers, depending on the presence of the [clean_class] parameter.

The parameters [--clean_class], [tensors_folder], and [weights_folder] can be specified via configuration file. 
If the [--clean_class] parameter is commented out, the version with binary classifiers will be executed.
The remaining parameters are customizable within the script's main.

[--workers]               # Number of data loading workers
[--batch_size]            # Batch size during the training
[--learning_rate]         # Learning rate
[--epochs]                # Number of epochs to train
[--job_id]                # Job ID  (used only to assign a specific name to the weights file; 'Pbl_' is the default)
[--clean_class]           # Clean class name for binary classifiers (multiclass if commented, e.g., #--clean_class=Buoni)
[tensors_folder]          # Folder containing the tensors
[weights_folder]          # Weights folder (e.g., 'data/Weights_dir_oldnew_multiclass')

Example usage

$ python PBL_ResNet_Train.py @PBL_ResNet_Train.conf

PBL_ResNet_Eval.py

This script is used to test the model. The batch size is set to 1 to evaluate one sequence at a time. Once the test is completed, two files will be saved: 'experiment_name_metrics_per_class.txt' (containing the metrics for accuracy, precision, recall, and F1-Score both per class and averaged) and 'experiment_name_confusion_matrix.png', the image containing the confusion matrix of the experiment.

The parameters [--clean_class], [tensors_folder], [weights_folder] and [experiment_name] can be specified via configuration file. 
If the [--clean_class] parameter is commented out, the version with binary classifiers will be executed.
The remaining parameters are customizable within the script's main.

[--workers]               # Number of data loading workers [2]
[--batch_size]            # Batch size during the testing [1]
[--job_id]                # Job ID (used only to assign a specific name to the weights file; 'Pbl_' is the default)
[tensors_folder]          # Folder containing the tensors
[weights_folder]          # Directory containing the model weights (e.g., 'data/Weights_dir_oldnew_multiclass')
[experiment_name]         # Name of the final result files (used to save 'experiment_name_metrics_per_class.txt' and 'experiment_name_confusion_matrix.png')
[--clean_class]           # Clean class name (multiclass if commented in the config file, e.g., #--clean_class=Buoni)

Example usage

$ python PBL_ResNet_Eval.py @PBL_ResNet_Eval.conf

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages