From 598c4aec520f6ab737e281bdc6e48254759d2fcc Mon Sep 17 00:00:00 2001 From: Schneider Leo <leo.schneider@etu.ec-lyon.fr> Date: Wed, 18 Jun 2025 15:48:02 +0200 Subject: [PATCH] fix : tile classification model change : pywiff reader location --- config/config.py | 2 +- dataset/dataset.py | 41 ++++++++---------- image_processing/build_dataset.py | 19 +++++--- .../pyRawMSDataReader}/.gitignore | 0 .../DLLs/Clearcore.Licensing.dll | Bin .../DLLs/Clearcore2.Compression.dll | Bin .../Clearcore2.Data.Acquisition.Client.dll | Bin .../Clearcore2.Data.Acquisition.Contracts.dll | Bin .../Clearcore2.Data.AnalystDataProvider.dll | Bin .../DLLs/Clearcore2.Data.Client.dll | Bin .../DLLs/Clearcore2.Data.Common.dll | Bin .../DLLs/Clearcore2.Data.CommonInterfaces.dll | Bin .../DLLs/Clearcore2.Data.Contracts.dll | Bin .../DLLs/Clearcore2.Data.Core.dll | Bin .../DLLs/Clearcore2.Data.Wiff2.dll | Bin .../DLLs/Clearcore2.Data.WiffReader.dll | Bin .../DLLs/Clearcore2.Data.dll | Bin .../DLLs/Clearcore2.DataService.dll | Bin .../DLLs/Clearcore2.Devices.Types.dll | Bin ...e2.Domain.Acquisition.Methods.MassSpec.dll | Bin .../DLLs/Clearcore2.Domain.Acquisition.dll | Bin .../DLLs/Clearcore2.Infrastructure.dll | Bin .../Clearcore2.InternalRawXYProcessing.dll | Bin .../DLLs/Clearcore2.Muni.dll | Bin .../DLLs/Clearcore2.Processing.dll | Bin .../DLLs/Clearcore2.ProjectUtilities.dll | Bin .../DLLs/Clearcore2.RawXYProcessing.dll | Bin .../DLLs/Clearcore2.StructuredStorage.dll | Bin .../DLLs/Clearcore2.UserLog.Types.dll | Bin .../DLLs/Clearcore2.Utility.dll | Bin .../DLLs/Clearcore2.XmlHelpers.dll | Bin .../DLLs/Sciex.Clearcore.FMan.dll | Bin .../DLLs/Sciex.Data.Processing.dll | Bin .../DLLs/Sciex.Data.SimpleTypes.dll | Bin .../DLLs/Sciex.Data.XYData.dll | Bin .../pyRawMSDataReader}/DLLs/Sciex.FMan.dll | Bin .../pyRawMSDataReader}/DLLs/Sciex.Wiff.dll | Bin .../pyRawMSDataReader}/DLLs/SciexToolKit.dll | Bin .../DLLs/ThermoFisher.CommonCore.Data.dll | Bin .../ThermoFisher.CommonCore.RawFileReader.dll | Bin .../DLLs/WiffFileReader.dll | Bin .../pyRawMSDataReader}/DLLs/libtimsdata.so | Bin .../pyRawMSDataReader}/DLLs/timsdata.dll | Bin .../pyRawMSDataReader}/LICENSE | 0 .../pyRawMSDataReader}/THERMO_LICENSE.txt | 0 .../pyRawMSDataReader}/__init__.py | 0 .../pyRawMSDataReader}/build_install_test.ps1 | 0 .../pyRawMSDataReader/RawFileReader.py | 6 +-- .../pyRawMSDataReader/WiffFileReader_py.py | 4 +- .../pyRawMSDataReader/__init__.py | 0 .../pyRawMSDataReader}/readme.md | 0 .../pyRawMSDataReader}/setup.py | 0 main.py | 19 +++++--- models/model.py | 27 +++++++----- 54 files changed, 67 insertions(+), 51 deletions(-) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/.gitignore (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore.Licensing.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Compression.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.Acquisition.Client.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.Acquisition.Contracts.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.AnalystDataProvider.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.Client.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.Common.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.CommonInterfaces.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.Contracts.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.Core.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.Wiff2.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.WiffReader.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Data.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.DataService.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Devices.Types.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Domain.Acquisition.Methods.MassSpec.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Domain.Acquisition.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Infrastructure.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.InternalRawXYProcessing.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Muni.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Processing.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.ProjectUtilities.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.RawXYProcessing.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.StructuredStorage.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.UserLog.Types.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.Utility.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Clearcore2.XmlHelpers.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Sciex.Clearcore.FMan.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Sciex.Data.Processing.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Sciex.Data.SimpleTypes.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Sciex.Data.XYData.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Sciex.FMan.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/Sciex.Wiff.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/SciexToolKit.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/ThermoFisher.CommonCore.Data.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/ThermoFisher.CommonCore.RawFileReader.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/WiffFileReader.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/libtimsdata.so (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/DLLs/timsdata.dll (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/LICENSE (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/THERMO_LICENSE.txt (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/__init__.py (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/build_install_test.ps1 (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/pyRawMSDataReader/RawFileReader.py (99%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/pyRawMSDataReader/WiffFileReader_py.py (97%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/pyRawMSDataReader/__init__.py (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/readme.md (100%) rename {pyRawMSDataReader => image_processing/pyRawMSDataReader}/setup.py (100%) diff --git a/config/config.py b/config/config.py index 9965772b..dd67082a 100644 --- a/config/config.py +++ b/config/config.py @@ -18,7 +18,7 @@ def load_args(): parser.add_argument('--output', type=str, default='output/out.csv') parser.add_argument('--save_path', type=str, default='output/best_model.pt') parser.add_argument('--pretrain_path', type=str, default=None) - parser.add_argument('--pretrain_imgnet', action=argparse.BooleanOptionalAction, default=True) + parser.add_argument('--pretrain_imgnet', action=argparse.BooleanOptionalAction, default=False) args = parser.parse_args() return args diff --git a/dataset/dataset.py b/dataset/dataset.py index 619c56f3..3d4c750c 100644 --- a/dataset/dataset.py +++ b/dataset/dataset.py @@ -251,28 +251,31 @@ class ImageFolderDuoPatch(data.Dataset): self.classes = torchvision.datasets.folder.find_classes(root)[0] impathAER, _, _ = self.imlist[0] imgAER = self.loader(impathAER) - self.shape = imgAER.shape[0],imgAER.shape[1] + self.shape = imgAER.shape[1],imgAER.shape[2] self.patches = math.ceil(self.shape[0]/224) ,math.ceil(self.shape[1]/224) - self.padded_shape = self.patches[0]*224, self.patches[0]*224 + self.padded_shape = self.patches[0]*224, self.patches[1]*224 def __getitem__(self, index): impathAER, impathANA, target = self.imlist[index] - imgAER = self.loader(impathAER) - imgANA = self.loader(impathANA) + imgAER = self.loader(impathAER).float() + imgANA = self.loader(impathANA).float() + shape_ana = imgANA.shape + shape_aer = imgAER.shape if self.transform is not None: imgAER = self.transform(imgAER) imgANA = self.transform(imgANA) if self.target_transform is not None: target = self.target_transform(target) - imgAER = torch.nn.functional.pad(imgAER, pad=(self.padded_shape[0] - self.shape[0], 0, - self.padded_shape[1] - self.shape[1],0)) - imgANA = torch.nn.functional.pad(imgANA, pad=(self.padded_shape[0] - self.shape[0], 0, - self.padded_shape[1] - self.shape[1], 0)) - imgAER = imgAER.unfold(0, 224, 224).unfold(1, 224, 224) + imgAER = torch.nn.functional.pad(imgAER, pad=(self.padded_shape[1] - shape_aer[2], 0, + self.padded_shape[0] - shape_aer[1],0)) + imgANA = torch.nn.functional.pad(imgANA, pad=(self.padded_shape[1] - shape_ana[2], 0, + self.padded_shape[0] - shape_ana[1], 0)) + + imgAER = imgAER.unfold(1, 224, 224).unfold(2, 224, 224) imgAER = imgAER.resize(self.patches[0]*self.patches[1],224,224) - imgANA = imgANA.unfold(0, 224, 224).unfold(1, 224, 224) + imgANA = imgANA.unfold(1, 224, 224).unfold(2, 224, 224) imgANA = imgANA.resize(self.patches[0] * self.patches[1], 224, 224) return imgAER, imgANA, target #channel (patch, H, W) @@ -281,7 +284,7 @@ class ImageFolderDuoPatch(data.Dataset): return len(self.imlist) -def load_data_duo_patch(base_dir, batch_size, shuffle=True, noise_threshold=0): +def load_data_duo_patch(base_dir_train, base_dir_val, batch_size, base_dir_test=None, shuffle=True, noise_threshold=0): train_transform = transforms.Compose( [Log_normalisation(), transforms.Normalize(0.5, 0.5)]) @@ -292,19 +295,9 @@ def load_data_duo_patch(base_dir, batch_size, shuffle=True, noise_threshold=0): transforms.Normalize(0.5, 0.5)]) print('Default val transform') - train_dataset = ImageFolderDuo(root=base_dir, transform=train_transform) - val_dataset = ImageFolderDuo(root=base_dir, transform=val_transform) - classes_numbers = [51, 12, 9, 10, 86, 231, 20, 13, 24, 96, 11, 39, 11] - classes_names = ["Citrobacter freundii", "Citrobacter koseri", "Enterobacter asburiae", "Enterobacter cloacae", - "Enterobacter hormaechei", "Escherichia coli", "Klebsiella aerogenes", "Klebsiella michiganensis", - "Klebsiella oxytoca", "Klebsiella pneumoniae", "Klebsiella quasipneumoniae", "Proteus mirabilis", - "Salmonella enterica"] - repart_weights = [classes_names[i] for i in range(len(classes_names)) for k in - range(classes_numbers[i])] - iTrain, iVal = train_test_split(range(len(train_dataset)), test_size=0.2, shuffle=shuffle, stratify=repart_weights, - random_state=42) - train_dataset = torch.utils.data.Subset(train_dataset, iTrain) - val_dataset = torch.utils.data.Subset(val_dataset, iVal) + train_dataset = ImageFolderDuoPatch(root=base_dir_train, transform=train_transform) + val_dataset = ImageFolderDuoPatch(root=base_dir_val, transform=val_transform) + data_loader_train = data.DataLoader( dataset=train_dataset, diff --git a/image_processing/build_dataset.py b/image_processing/build_dataset.py index 4296af25..6adbd73f 100644 --- a/image_processing/build_dataset.py +++ b/image_processing/build_dataset.py @@ -1,6 +1,8 @@ import argparse import glob import os +import random + import pandas as pd import re import numpy as np @@ -8,7 +10,7 @@ import matplotlib.image as mpimg import sys sys.path.append(os.getcwd()) -from pyRawMSDataReader.pyRawMSDataReader.WiffFileReader_py import WiffFileReader + from build_image import build_image_ms1_wiff_charge_filtered, build_image_ms1_wiff_charge_filtered_apex_only @@ -169,10 +171,12 @@ def create_dataset(bin_mz=1,tolerance=0.005,noise=1000,apex='apex',suffix='-d200 """ label = create_antibio_dataset(suffix=suffix,base_path=base_path) tolerance_str=str(tolerance)[2::] - for path in glob.glob(os.path.join(base_path,"data/raw_data/**.wiff")): + file_list = glob.glob(os.path.join(base_path,"data/raw_data/**.wiff")) + for path in file_list: print(path) species = None #check if file exists in the label table + if path.split("/")[-1] in label['path_ana'].values: species = label[label['path_ana'] == path.split("/")[-1]]['species'].values[0] name = label[label['path_ana'] == path.split("/")[-1]]['sample_name'].values[0] @@ -211,8 +215,9 @@ def load_args_dataset(): parser.add_argument('--noise', type=float, default=1000.) parser.add_argument('--tolerance', type=float, default=0.005) - parser.add_argument('--mz_bin', type=float, default=1.) - parser.add_argument('--apex', type=str, default='apex') + parser.add_argument('--mz_bin', type=float, default=0.2) + parser.add_argument('--apex', type=str, default='fuul_peak') + parser.add_argument('--nb', type=int, default=1) args = parser.parse_args() return args @@ -220,7 +225,9 @@ def load_args_dataset(): if __name__ =='__main__' : base_path = os.getcwd() args = load_args_dataset() - create_dataset(noise=args.noise, tolerance=args.tolerance, bin_mz=args.mz_bin, apex=args.apex, suffix='-d200',base_path=base_path) - create_dataset(noise=args.noise, tolerance=args.tolerance, bin_mz=args.mz_bin, apex=args.apex, suffix='_100vW_100SPD',base_path=base_path) + if args.nb == 1 : + create_dataset(noise=args.noise, tolerance=args.tolerance, bin_mz=args.mz_bin, apex=args.apex, suffix='-d200',base_path=base_path) + else : + create_dataset(noise=args.noise, tolerance=args.tolerance, bin_mz=args.mz_bin, apex=args.apex, suffix='_100vW_100SPD',base_path=base_path) #KLEAER-12-AER-d200.wiff problème \ No newline at end of file diff --git a/pyRawMSDataReader/.gitignore b/image_processing/pyRawMSDataReader/.gitignore similarity index 100% rename from pyRawMSDataReader/.gitignore rename to image_processing/pyRawMSDataReader/.gitignore diff --git a/pyRawMSDataReader/DLLs/Clearcore.Licensing.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore.Licensing.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore.Licensing.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore.Licensing.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Compression.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Compression.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Compression.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Compression.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.Acquisition.Client.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Acquisition.Client.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.Acquisition.Client.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Acquisition.Client.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.Acquisition.Contracts.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Acquisition.Contracts.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.Acquisition.Contracts.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Acquisition.Contracts.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.AnalystDataProvider.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.AnalystDataProvider.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.AnalystDataProvider.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.AnalystDataProvider.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.Client.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Client.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.Client.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Client.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.Common.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Common.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.Common.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Common.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.CommonInterfaces.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.CommonInterfaces.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.CommonInterfaces.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.CommonInterfaces.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.Contracts.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Contracts.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.Contracts.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Contracts.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.Core.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Core.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.Core.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Core.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.Wiff2.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Wiff2.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.Wiff2.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.Wiff2.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.WiffReader.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.WiffReader.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.WiffReader.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.WiffReader.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Data.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Data.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Data.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.DataService.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.DataService.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.DataService.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.DataService.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Devices.Types.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Devices.Types.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Devices.Types.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Devices.Types.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Domain.Acquisition.Methods.MassSpec.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Domain.Acquisition.Methods.MassSpec.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Domain.Acquisition.Methods.MassSpec.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Domain.Acquisition.Methods.MassSpec.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Domain.Acquisition.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Domain.Acquisition.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Domain.Acquisition.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Domain.Acquisition.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Infrastructure.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Infrastructure.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Infrastructure.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Infrastructure.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.InternalRawXYProcessing.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.InternalRawXYProcessing.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.InternalRawXYProcessing.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.InternalRawXYProcessing.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Muni.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Muni.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Muni.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Muni.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Processing.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Processing.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Processing.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Processing.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.ProjectUtilities.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.ProjectUtilities.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.ProjectUtilities.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.ProjectUtilities.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.RawXYProcessing.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.RawXYProcessing.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.RawXYProcessing.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.RawXYProcessing.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.StructuredStorage.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.StructuredStorage.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.StructuredStorage.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.StructuredStorage.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.UserLog.Types.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.UserLog.Types.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.UserLog.Types.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.UserLog.Types.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.Utility.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.Utility.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.Utility.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.Utility.dll diff --git a/pyRawMSDataReader/DLLs/Clearcore2.XmlHelpers.dll b/image_processing/pyRawMSDataReader/DLLs/Clearcore2.XmlHelpers.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Clearcore2.XmlHelpers.dll rename to image_processing/pyRawMSDataReader/DLLs/Clearcore2.XmlHelpers.dll diff --git a/pyRawMSDataReader/DLLs/Sciex.Clearcore.FMan.dll b/image_processing/pyRawMSDataReader/DLLs/Sciex.Clearcore.FMan.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Sciex.Clearcore.FMan.dll rename to image_processing/pyRawMSDataReader/DLLs/Sciex.Clearcore.FMan.dll diff --git a/pyRawMSDataReader/DLLs/Sciex.Data.Processing.dll b/image_processing/pyRawMSDataReader/DLLs/Sciex.Data.Processing.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Sciex.Data.Processing.dll rename to image_processing/pyRawMSDataReader/DLLs/Sciex.Data.Processing.dll diff --git a/pyRawMSDataReader/DLLs/Sciex.Data.SimpleTypes.dll b/image_processing/pyRawMSDataReader/DLLs/Sciex.Data.SimpleTypes.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Sciex.Data.SimpleTypes.dll rename to image_processing/pyRawMSDataReader/DLLs/Sciex.Data.SimpleTypes.dll diff --git a/pyRawMSDataReader/DLLs/Sciex.Data.XYData.dll b/image_processing/pyRawMSDataReader/DLLs/Sciex.Data.XYData.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Sciex.Data.XYData.dll rename to image_processing/pyRawMSDataReader/DLLs/Sciex.Data.XYData.dll diff --git a/pyRawMSDataReader/DLLs/Sciex.FMan.dll b/image_processing/pyRawMSDataReader/DLLs/Sciex.FMan.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Sciex.FMan.dll rename to image_processing/pyRawMSDataReader/DLLs/Sciex.FMan.dll diff --git a/pyRawMSDataReader/DLLs/Sciex.Wiff.dll b/image_processing/pyRawMSDataReader/DLLs/Sciex.Wiff.dll similarity index 100% rename from pyRawMSDataReader/DLLs/Sciex.Wiff.dll rename to image_processing/pyRawMSDataReader/DLLs/Sciex.Wiff.dll diff --git a/pyRawMSDataReader/DLLs/SciexToolKit.dll b/image_processing/pyRawMSDataReader/DLLs/SciexToolKit.dll similarity index 100% rename from pyRawMSDataReader/DLLs/SciexToolKit.dll rename to image_processing/pyRawMSDataReader/DLLs/SciexToolKit.dll diff --git a/pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.Data.dll b/image_processing/pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.Data.dll similarity index 100% rename from pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.Data.dll rename to image_processing/pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.Data.dll diff --git a/pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.RawFileReader.dll b/image_processing/pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.RawFileReader.dll similarity index 100% rename from pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.RawFileReader.dll rename to image_processing/pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.RawFileReader.dll diff --git a/pyRawMSDataReader/DLLs/WiffFileReader.dll b/image_processing/pyRawMSDataReader/DLLs/WiffFileReader.dll similarity index 100% rename from pyRawMSDataReader/DLLs/WiffFileReader.dll rename to image_processing/pyRawMSDataReader/DLLs/WiffFileReader.dll diff --git a/pyRawMSDataReader/DLLs/libtimsdata.so b/image_processing/pyRawMSDataReader/DLLs/libtimsdata.so similarity index 100% rename from pyRawMSDataReader/DLLs/libtimsdata.so rename to image_processing/pyRawMSDataReader/DLLs/libtimsdata.so diff --git a/pyRawMSDataReader/DLLs/timsdata.dll b/image_processing/pyRawMSDataReader/DLLs/timsdata.dll similarity index 100% rename from pyRawMSDataReader/DLLs/timsdata.dll rename to image_processing/pyRawMSDataReader/DLLs/timsdata.dll diff --git a/pyRawMSDataReader/LICENSE b/image_processing/pyRawMSDataReader/LICENSE similarity index 100% rename from pyRawMSDataReader/LICENSE rename to image_processing/pyRawMSDataReader/LICENSE diff --git a/pyRawMSDataReader/THERMO_LICENSE.txt b/image_processing/pyRawMSDataReader/THERMO_LICENSE.txt similarity index 100% rename from pyRawMSDataReader/THERMO_LICENSE.txt rename to image_processing/pyRawMSDataReader/THERMO_LICENSE.txt diff --git a/pyRawMSDataReader/__init__.py b/image_processing/pyRawMSDataReader/__init__.py similarity index 100% rename from pyRawMSDataReader/__init__.py rename to image_processing/pyRawMSDataReader/__init__.py diff --git a/pyRawMSDataReader/build_install_test.ps1 b/image_processing/pyRawMSDataReader/build_install_test.ps1 similarity index 100% rename from pyRawMSDataReader/build_install_test.ps1 rename to image_processing/pyRawMSDataReader/build_install_test.ps1 diff --git a/pyRawMSDataReader/pyRawMSDataReader/RawFileReader.py b/image_processing/pyRawMSDataReader/pyRawMSDataReader/RawFileReader.py similarity index 99% rename from pyRawMSDataReader/pyRawMSDataReader/RawFileReader.py rename to image_processing/pyRawMSDataReader/pyRawMSDataReader/RawFileReader.py index ffd8b793..30f7502f 100644 --- a/pyRawMSDataReader/pyRawMSDataReader/RawFileReader.py +++ b/image_processing/pyRawMSDataReader/pyRawMSDataReader/RawFileReader.py @@ -4,14 +4,14 @@ import numpy as np from pythonnet import load # require pythonnet, pip install pythonnet -load("coreclr") +load("mono") import clr base_path = os.getcwd() from System import String # sys.path.append("DLLs") -clr.AddReference(os.path.join(base_path,'pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.Data')) -clr.AddReference(os.path.join(base_path,'pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.RawFileReader')) +clr.AddReference(os.path.join(base_path,'image_processing/pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.Data')) +clr.AddReference(os.path.join(base_path,'image_processing/pyRawMSDataReader/DLLs/ThermoFisher.CommonCore.RawFileReader')) import ThermoFisher from ThermoFisher.CommonCore.Data.Interfaces import IScanEventBase, IScanEvent ''' diff --git a/pyRawMSDataReader/pyRawMSDataReader/WiffFileReader_py.py b/image_processing/pyRawMSDataReader/pyRawMSDataReader/WiffFileReader_py.py similarity index 97% rename from pyRawMSDataReader/pyRawMSDataReader/WiffFileReader_py.py rename to image_processing/pyRawMSDataReader/pyRawMSDataReader/WiffFileReader_py.py index 1505f974..3261301f 100644 --- a/pyRawMSDataReader/pyRawMSDataReader/WiffFileReader_py.py +++ b/image_processing/pyRawMSDataReader/pyRawMSDataReader/WiffFileReader_py.py @@ -3,11 +3,11 @@ import sys import numpy as np from pythonnet import load -load("coreclr") +load("mono") import clr base_path = os.getcwd() -clr.AddReference(os.path.join(base_path,'pyRawMSDataReader/DLLs/WiffFileReader.dll')) +clr.AddReference(os.path.join(base_path,'image_processing/pyRawMSDataReader/DLLs/WiffFileReader.dll')) from WiffFileReader import WiffFile from .RawFileReader import DotNetArrayToNPArray diff --git a/pyRawMSDataReader/pyRawMSDataReader/__init__.py b/image_processing/pyRawMSDataReader/pyRawMSDataReader/__init__.py similarity index 100% rename from pyRawMSDataReader/pyRawMSDataReader/__init__.py rename to image_processing/pyRawMSDataReader/pyRawMSDataReader/__init__.py diff --git a/pyRawMSDataReader/readme.md b/image_processing/pyRawMSDataReader/readme.md similarity index 100% rename from pyRawMSDataReader/readme.md rename to image_processing/pyRawMSDataReader/readme.md diff --git a/pyRawMSDataReader/setup.py b/image_processing/pyRawMSDataReader/setup.py similarity index 100% rename from pyRawMSDataReader/setup.py rename to image_processing/pyRawMSDataReader/setup.py diff --git a/main.py b/main.py index 8cdbb714..2e4b7fb8 100644 --- a/main.py +++ b/main.py @@ -2,10 +2,10 @@ import matplotlib.pyplot as plt import numpy as np from config.config import load_args -from dataset.dataset import load_data, load_data_duo +from dataset.dataset import load_data, load_data_duo, load_data_duo_patch import torch import torch.nn as nn -from models.model import Classification_model, Classification_model_duo, Classification_model_duo_pretrained +from models.model import Classification_model, Classification_model_duo, Classification_model_duo_pretrained, Classification_model_duo_tile import torch.optim as optim from sklearn.metrics import confusion_matrix import seaborn as sn @@ -193,14 +193,23 @@ def test_duo(model, data_test, loss_function, epoch): def run_duo(args): #load data - data_train, data_test,_ = load_data_duo(base_dir_train=args.dataset_train_dir, base_dir_val=args.dataset_val_dir, base_dir_test=args.dataset_test_dir, batch_size=args.batch_size) + + #data_train, data_test,_ = load_data_duo(base_dir_train=args.dataset_train_dir, base_dir_val=args.dataset_val_dir, base_dir_test=args.dataset_test_dir, batch_size=args.batch_size) + data_train, data_test = load_data_duo_patch(base_dir_train=args.dataset_train_dir, base_dir_val=args.dataset_val_dir, + base_dir_test=args.dataset_test_dir, batch_size=args.batch_size) #load model if not args.pretrain_imgnet: - model = Classification_model_duo(model = args.model, n_class=len(data_train.dataset.classes)) + #adaptative path model + for imaer,imana, label in data_train: + img_shape = imaer.shape # batch x tile x img + break + model = Classification_model_duo_tile(model = args.model, n_class=len(data_train.dataset.classes),n_tile=img_shape[1]) + + #model = Classification_model_duo(model = args.model, n_class=len(data_train.dataset.classes)) else : model = Classification_model_duo_pretrained(model = args.model, n_class=len(data_train.dataset.classes)) - model.double() + model = model.to(torch.float) #load weight if args.pretrain_path is not None : load_model(model,args.pretrain_path) diff --git a/models/model.py b/models/model.py index 3fde4b15..4d479f4d 100644 --- a/models/model.py +++ b/models/model.py @@ -293,24 +293,31 @@ class Classification_model_duo(nn.Module): out = torch.concat([out_aer,out_ana],dim=1) return self.predictor(out) -class Classification_model_duo_adaptative_res(nn.Module): +class Classification_model_duo_tile(nn.Module): - def __init__(self, model, n_class,tile_dim, *args, **kwargs): + def __init__(self, model, n_class,n_tile, *args, **kwargs): super().__init__(*args, **kwargs) self.n_class = n_class - self.tile_dim = tile_dim + self.n_tile = n_tile if model =='ResNet18': - self.im_encoder = resnet18(num_classes=self.n_class, in_channels=self.tile_dim[0]*self.tile_dim[1]) + self.im_encoder = resnet18(num_classes=self.n_class, in_channels=1) if model =='ResNet50': - self.im_encoder = resnet50(num_classes=self.n_class, in_channels=self.tile_dim[0]*self.tile_dim[1]) - self.predictor = nn.Linear(in_features=self.n_class*2,out_features=self.n_class) + self.im_encoder = resnet50(num_classes=self.n_class, in_channels=1) + self.merging_layer = nn.Linear(in_features=self.n_class*2,out_features=self.n_class) + self.predictor = nn.Linear(in_features=self.n_class*self.n_tile,out_features=self.n_class) def forward(self, input_aer, input_ana): - out_aer = self.im_encoder(input_aer) - out_ana = self.im_encoder(input_ana) - out = torch.concat([out_aer,out_ana],dim=1) - return self.predictor(out) + out_list = [] + for t in range(self.n_tile) : + out_aer = self.im_encoder(input_aer[:,t,:,:].unsqueeze(1)) + out_ana = self.im_encoder(input_ana[:,t,:,:].unsqueeze(1)) + concat_out = torch.concat([out_aer,out_ana],dim=1) + merged_out = self.merging_layer(concat_out) + out_list.append(merged_out) + full_concat_merged = torch.concat(out_list,dim=1) + out = self.predictor(full_concat_merged) + return out class Classification_model_duo_pretrained(nn.Module): -- GitLab