DP - Segmentation of intracardiac records

Solution segmenting intracardiac records in 2D using convolutional neural network and image processing methods
Bc. Jan Rehor, 195747, xrehor05@vutbr.cz
---------------------------------------
1) Introductory information
2) Procedure
3) Important notice
---------------------------------------
1) Introduction information
The work was created in the Spyder environment
Python 3.8
The work requires the following libraries installed:
    Pandas
    NumPy
    natsort
    pathlib
    OpenCV
    Matplotlib
    TensorFlow
    skikit-learn
    scikit-image

In addition to the source code, training (118) and test (7) data (images) are available. The same training and test dataset was used for both models (for comparison)
The training data were used for training U-net (model stored in unet_nodel.h5) and SegNet (model stored in segnet_nodel.h5) and subsequently tested on test data (outputs in the diploma thesis).

Structure:
    segmentation_of_intracardial_signal.py - main file that runs.
    imageprocessing.py - a file that contains the ImageProcessing class for the needs of the diploma thesis, which, for example, creates images, thresholding, image cropping or dilation from 1D signals.
    networkmodel.py - a file that contains the NetworkModel class for the needs of the diploma thesis. Contains methods for creating U-net and Segnet
    stats.py - a file that contains the Stats class for the needs of the diploma thesis. It contains methods for model evaluation, such as determining the dice coefficient, or determining TP, TN, FP, FN, sensitivity and precission-
    signals / - directory where .csv and .json signal files were located - empty (they were deleted - more in Important notice)
    annotations / - directory where .sel files were located (annotations) - empty (they were deleted - more in Important notice)
    train / - directory where the training data is located (images of signals and corresponding masks - label, divided in the directories images and masks)
    test / - directory where the training data is located (images of signals and corresponding masks, divided in the directories images and masks)
    .h5 files - files where the parameters of the learned models are stored (unet_nodel.h5, segnet_model.h5, according to which the outputs are in the text of the thesis)
2)
Method:
   - the image creation process requires .csv and .sel files, however, there are already images in the train / and test / directories,
     on which the model can be tested (.csv and .sel files are used here only for creating images)
     the training and test data are in the ratio of 118 training images (and thus 118 images of the respective masks) to 7 test images of the signal (and thus 7 images of the respective masks)
   - These test data can be used to test the model.
   - Steps:
          1) import of libraries and classes -> if uploading, importing or creating objects from created classes would not work (For example, the message 'No module named ...') via section execution, it is possible to start the whole program and then quit it immediately ( then section booting works).
          2) Configuration settings, lines 65-109. It is recommended to keep the configuration and change only the directory paths
          2.5) On lines 114-116 it is necessary to run these lines to create objects from created classes (even in case of prediction testing)
          3)
              I) in case of prediction testing - overwrite in line 324 the path to the required .h5 file (unet_nodel.h5 or segnet_model.h5) and run everything from the prediction section to the end.
              If the .h5 file is in the same directory as segmentation_of_intracardical_signal.py, only the name with the suffix can be written
              If the training started and on line 297 there would be either unet_nodel.h5 and segnet_model.h5 (instead of model.h5), the parameters will be translated after training, therefore ...
              ... II) in case of trial and training, it is advisable to keep the specified model on lines 297 and 324.h5 in the save () method
              III) In case of trying to create a model, there is a possibility to call the created method either create_unet () or create_segnet () on line 264.

3)
Important notice
    - There are no files in the signals / and annotations / directories as they cannot be published by me
      (but these files are only used to create images in this solution - the rest is based on the images that are in the train / and test / directories)
    - If the image creation process starts, all images in the train / test directories will be replaced by new images (if there are the same number or more)
    - If training and saving on line 297 starts, and there will be one on these lines on line 297 and .324: unet_nodel.h5 and segnet_model.h5, there is a risk of their transfer. To test the training, it is recommended to use model.h5, which is basically defined in the save method (297 rows).