From dd1b77a06ccdc25849df2ede6b2ed0b846b5f3d6 Mon Sep 17 00:00:00 2001 From: rizoudal Date: Wed, 10 Jul 2024 16:49:02 +0200 Subject: [PATCH 1/5] refactor: commented out all ViT mentions in files --- README.md | 2 +- .../architectures/image/__init__.py | 24 +++++++++---------- requirements.txt | 1 - setup.py | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 0c6bcb39..5547cf22 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The open-source software AUCMEDI allows fast setup of medical image classificati - Wide range of 2D/3D data entry options with interfaces to the most common medical image formats such as DICOM, MetaImage, NifTI, PNG or TIF already supplied. - Selection of pre-processing methods for preparing images, such as augmentation processes, color conversions, windowing, filtering, resizing and normalization. - Use of deep neural networks for binary, multi-class as well as multi-label classification and efficient methods against class imbalances using modern loss functions such as focal loss. -- Library from modern architectures, like ResNet up to EfficientNet and Vision-Transformers (ViT)⁠. +- Library from modern architectures, like ResNet up to EfficientNet. - Complex ensemble learning techniques (combination of predictions) using test-time augmentation, bagging via cross-validation or stacking via logistic regressions. - Explainable AI to explain opaque decision-making processes of the models using activation maps such as Grad-CAM or backpropagation. - Automated Machine Learning (AutoML) mentality to ensure easy deployment, integration and maintenance of complex medical image classification pipelines (Docker). diff --git a/aucmedi/neural_network/architectures/image/__init__.py b/aucmedi/neural_network/architectures/image/__init__.py index 6de1b5fc..873a31d0 100644 --- a/aucmedi/neural_network/architectures/image/__init__.py +++ b/aucmedi/neural_network/architectures/image/__init__.py @@ -61,10 +61,10 @@ # Xception from aucmedi.neural_network.architectures.image.xception import Xception # Vision Transformer (ViT) -from aucmedi.neural_network.architectures.image.vit_b16 import ViT_B16 -from aucmedi.neural_network.architectures.image.vit_b32 import ViT_B32 -from aucmedi.neural_network.architectures.image.vit_l16 import ViT_L16 -from aucmedi.neural_network.architectures.image.vit_l32 import ViT_L32 +# from aucmedi.neural_network.architectures.image.vit_b16 import ViT_B16 +# from aucmedi.neural_network.architectures.image.vit_b32 import ViT_B32 +# from aucmedi.neural_network.architectures.image.vit_l16 import ViT_L16 +# from aucmedi.neural_network.architectures.image.vit_l32 import ViT_L32 # ConvNeXt from aucmedi.neural_network.architectures.image.convnext_base import ConvNeXtBase from aucmedi.neural_network.architectures.image.convnext_tiny import ConvNeXtTiny @@ -103,10 +103,10 @@ "VGG16": VGG16, "VGG19": VGG19, "Xception": Xception, - "ViT_B16": ViT_B16, - "ViT_B32": ViT_B32, - "ViT_L16": ViT_L16, - "ViT_L32": ViT_L32, + # "ViT_B16": ViT_B16, + # "ViT_B32": ViT_B32, + # "ViT_L16": ViT_L16, + # "ViT_L32": ViT_L32, "ConvNeXtBase": ConvNeXtBase, "ConvNeXtTiny": ConvNeXtTiny, "ConvNeXtSmall": ConvNeXtSmall, @@ -190,10 +190,10 @@ "VGG16": "caffe", "VGG19": "caffe", "Xception": "tf", - "ViT_B16": "tf", - "ViT_B32": "tf", - "ViT_L16": "tf", - "ViT_L32": "tf", + # "ViT_B16": "tf", + # "ViT_B32": "tf", + # "ViT_L16": "tf", + # "ViT_L32": "tf", "ConvNeXtBase": None, "ConvNeXtTiny": None, "ConvNeXtSmall": None, diff --git a/requirements.txt b/requirements.txt index 05186c40..c6d39426 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,6 @@ scikit-image==0.21.0 lime==0.2.0.1 pooch==1.6.0 classification-models-3D==1.0.10 -vit-keras==0.1.2 tensorflow-addons==0.21.0 Keras-Applications==1.0.8 SimpleITK==2.2.0 diff --git a/setup.py b/setup.py index 5044d437..a4bc9ec8 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ 'lime>=0.2.0.1', 'pooch>=1.6.0', 'classification-models-3D>=1.0.10', - 'vit-keras>=0.1.2', + # 'vit-keras>=0.1.2', 'tensorflow-addons>=0.21.0', 'Keras-Applications==1.0.8', 'SimpleITK>=2.2.0', From 9289d9057584e51ddb8505e9a8c684c1f5017c5e Mon Sep 17 00:00:00 2001 From: rizoudal Date: Wed, 10 Jul 2024 16:57:35 +0200 Subject: [PATCH 2/5] refactor(tests): commented out ViT-related unittests --- tests/test_architectures_image.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_architectures_image.py b/tests/test_architectures_image.py index 64a1a5df..e1bc89e3 100644 --- a/tests/test_architectures_image.py +++ b/tests/test_architectures_image.py @@ -661,6 +661,7 @@ def test_Xception(self): self.datagen_GRAY.sf_resize = Resize(shape=(32, 32)) self.datagen_RGB.sf_resize = Resize(shape=(32, 32)) +''' #-------------------------------------------------# # Architecture: ViT B16 # #-------------------------------------------------# @@ -740,6 +741,7 @@ def test_ViT_L32(self): self.assertTrue(sdm_global["2D.ViT_L32"] == "tf") self.assertTrue("2D.ViT_L32" in architecture_dict) # self.datagen_RGB.sf_resize = Resize(shape=(32, 32)) +''' #-------------------------------------------------# # Architecture: ConvNeXtBase # From 437d3d0d91dfb01885dd333d423382977a534413 Mon Sep 17 00:00:00 2001 From: rizoudal Date: Tue, 16 Jul 2024 18:38:52 +0200 Subject: [PATCH 3/5] refactor: update imports and comments, remove deprecated dependencies - commented out ViT-related unittests to avoid IndentationError - Updated README (from Architecture EfficientNet to Architecture ConvNeXt) - Removed tensorflow-addons from requirements.txt and setup.py - Changed import of F1Score in file aucmedi/automl/block_train.py --- README.md | 2 +- aucmedi/automl/block_train.py | 3 +-- requirements.txt | 1 - setup.py | 1 - tests/test_architectures_image.py | 34 +++++++++++++++---------------- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 5547cf22..c3ef3d64 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The open-source software AUCMEDI allows fast setup of medical image classificati - Wide range of 2D/3D data entry options with interfaces to the most common medical image formats such as DICOM, MetaImage, NifTI, PNG or TIF already supplied. - Selection of pre-processing methods for preparing images, such as augmentation processes, color conversions, windowing, filtering, resizing and normalization. - Use of deep neural networks for binary, multi-class as well as multi-label classification and efficient methods against class imbalances using modern loss functions such as focal loss. -- Library from modern architectures, like ResNet up to EfficientNet. +- Library from modern architectures, like ResNet up to ConvNeXt. - Complex ensemble learning techniques (combination of predictions) using test-time augmentation, bagging via cross-validation or stacking via logistic regressions. - Explainable AI to explain opaque decision-making processes of the models using activation maps such as Grad-CAM or backpropagation. - Automated Machine Learning (AutoML) mentality to ensure easy deployment, integration and maintenance of complex medical image classification pipelines (Docker). diff --git a/aucmedi/automl/block_train.py b/aucmedi/automl/block_train.py index d6696d93..d14b7bc5 100644 --- a/aucmedi/automl/block_train.py +++ b/aucmedi/automl/block_train.py @@ -23,8 +23,7 @@ import os import numpy as np import json -from tensorflow.keras.metrics import AUC -from tensorflow_addons.metrics import F1Score +from tensorflow.keras.metrics import AUC, F1Score from tensorflow.keras.callbacks import ModelCheckpoint, CSVLogger, \ ReduceLROnPlateau, EarlyStopping # Internal libraries diff --git a/requirements.txt b/requirements.txt index c6d39426..bde7bc38 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,6 @@ scikit-image==0.21.0 lime==0.2.0.1 pooch==1.6.0 classification-models-3D==1.0.10 -tensorflow-addons==0.21.0 Keras-Applications==1.0.8 SimpleITK==2.2.0 batchgenerators==0.25 diff --git a/setup.py b/setup.py index a4bc9ec8..1e94fe81 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,6 @@ 'pooch>=1.6.0', 'classification-models-3D>=1.0.10', # 'vit-keras>=0.1.2', - 'tensorflow-addons>=0.21.0', 'Keras-Applications==1.0.8', 'SimpleITK>=2.2.0', 'batchgenerators>=0.25', diff --git a/tests/test_architectures_image.py b/tests/test_architectures_image.py index e1bc89e3..b5a35ee3 100644 --- a/tests/test_architectures_image.py +++ b/tests/test_architectures_image.py @@ -661,12 +661,11 @@ def test_Xception(self): self.datagen_GRAY.sf_resize = Resize(shape=(32, 32)) self.datagen_RGB.sf_resize = Resize(shape=(32, 32)) -''' #-------------------------------------------------# # Architecture: ViT B16 # #-------------------------------------------------# # Functionality and Interoperability testing deactived due to too intensive RAM requirements - def test_ViT_B16(self): + # def test_ViT_B16(self): # self.datagen_RGB.sf_resize = Resize(shape=(224, 224)) # arch = ViT_B16(Classifier(n_labels=4), channels=3, # input_shape=(224, 224)) @@ -677,16 +676,16 @@ def test_ViT_B16(self): # batch_queue_size=1, input_shape=(224, 224)) # try : model.model.summary() # except : raise Exception() - self.assertTrue(supported_standardize_mode["ViT_B16"] == "tf") - self.assertTrue(sdm_global["2D.ViT_B16"] == "tf") - self.assertTrue("2D.ViT_B16" in architecture_dict) + # self.assertTrue(supported_standardize_mode["ViT_B16"] == "tf") + # self.assertTrue(sdm_global["2D.ViT_B16"] == "tf") + # self.assertTrue("2D.ViT_B16" in architecture_dict) # self.datagen_RGB.sf_resize = Resize(shape=(32, 32)) #-------------------------------------------------# # Architecture: ViT B32 # #-------------------------------------------------# # Functionality and Interoperability testing deactived due to too intensive RAM requirements - def test_ViT_B32(self): + # def test_ViT_B32(self): # self.datagen_RGB.sf_resize = Resize(shape=(224, 224)) # arch = ViT_B32(Classifier(n_labels=4), channels=3, # input_shape=(224, 224)) @@ -697,16 +696,16 @@ def test_ViT_B32(self): # batch_queue_size=1, input_shape=(224, 224)) # try : model.model.summary() # except : raise Exception() - self.assertTrue(supported_standardize_mode["ViT_B32"] == "tf") - self.assertTrue(sdm_global["2D.ViT_B32"] == "tf") - self.assertTrue("2D.ViT_B32" in architecture_dict) + # self.assertTrue(supported_standardize_mode["ViT_B32"] == "tf") + # self.assertTrue(sdm_global["2D.ViT_B32"] == "tf") + # self.assertTrue("2D.ViT_B32" in architecture_dict) # self.datagen_RGB.sf_resize = Resize(shape=(32, 32)) #-------------------------------------------------# # Architecture: ViT L16 # #-------------------------------------------------# # Functionality and Interoperability testing deactived due to too intensive RAM requirements - def test_ViT_L16(self): + # def test_ViT_L16(self): # self.datagen_RGB.sf_resize = Resize(shape=(384, 384)) # arch = ViT_L16(Classifier(n_labels=4), channels=3, # input_shape=(384, 384)) @@ -717,16 +716,16 @@ def test_ViT_L16(self): # batch_queue_size=1, input_shape=(384, 384)) # try : model.model.summary() # except : raise Exception() - self.assertTrue(supported_standardize_mode["ViT_L16"] == "tf") - self.assertTrue(sdm_global["2D.ViT_L16"] == "tf") - self.assertTrue("2D.ViT_L16" in architecture_dict) + # self.assertTrue(supported_standardize_mode["ViT_L16"] == "tf") + # self.assertTrue(sdm_global["2D.ViT_L16"] == "tf") + # self.assertTrue("2D.ViT_L16" in architecture_dict) # self.datagen_RGB.sf_resize = Resize(shape=(32, 32)) #-------------------------------------------------# # Architecture: ViT L32 # #-------------------------------------------------# # Functionality and Interoperability testing deactived due to too intensive RAM requirements - def test_ViT_L32(self): + # def test_ViT_L32(self): # self.datagen_RGB.sf_resize = Resize(shape=(384, 384)) # arch = ViT_L32(Classifier(n_labels=4), channels=3, # input_shape=(384, 384)) @@ -737,11 +736,10 @@ def test_ViT_L32(self): # batch_queue_size=1, input_shape=(384, 384)) # try : model.model.summary() # except : raise Exception() - self.assertTrue(supported_standardize_mode["ViT_L32"] == "tf") - self.assertTrue(sdm_global["2D.ViT_L32"] == "tf") - self.assertTrue("2D.ViT_L32" in architecture_dict) + # self.assertTrue(supported_standardize_mode["ViT_L32"] == "tf") + # self.assertTrue(sdm_global["2D.ViT_L32"] == "tf") + # self.assertTrue("2D.ViT_L32" in architecture_dict) # self.datagen_RGB.sf_resize = Resize(shape=(32, 32)) -''' #-------------------------------------------------# # Architecture: ConvNeXtBase # From 6ab16d3ff0359a1857f8a097412ce1281b838109 Mon Sep 17 00:00:00 2001 From: rizoudal Date: Wed, 17 Jul 2024 12:26:56 +0200 Subject: [PATCH 4/5] fix(metrics): remove num_classes parameter from F1Score and update requirements.txt - Removed num_classes parameter from F1Score in the AutoML training block to align with updated tf.keras - Added and commented out vit-keras in requirements.txt --- aucmedi/automl/block_train.py | 3 +-- requirements.txt | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aucmedi/automl/block_train.py b/aucmedi/automl/block_train.py index d14b7bc5..6ca6f915 100644 --- a/aucmedi/automl/block_train.py +++ b/aucmedi/automl/block_train.py @@ -139,8 +139,7 @@ def block_train(config): "workers": config["workers"], "batch_queue_size": 4, "loss": loss, - "metrics": [AUC(100), F1Score(num_classes=class_n, - average="macro")], + "metrics": [AUC(100), F1Score(average="macro")], "pretrained_weights": True, "multiprocessing": False, } diff --git a/requirements.txt b/requirements.txt index bde7bc38..3c9b29ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,6 +8,7 @@ scikit-image==0.21.0 lime==0.2.0.1 pooch==1.6.0 classification-models-3D==1.0.10 +# vit-keras==0.1.2 Keras-Applications==1.0.8 SimpleITK==2.2.0 batchgenerators==0.25 From 8bbd83c724826d9c68fb85d498b8cfae3c8bb711 Mon Sep 17 00:00:00 2001 From: rizoudal Date: Fri, 26 Jul 2024 14:25:15 +0200 Subject: [PATCH 5/5] refactor(metrics): delete F1Score in the AutoML training block --- aucmedi/automl/block_train.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aucmedi/automl/block_train.py b/aucmedi/automl/block_train.py index 6ca6f915..70279c02 100644 --- a/aucmedi/automl/block_train.py +++ b/aucmedi/automl/block_train.py @@ -23,7 +23,7 @@ import os import numpy as np import json -from tensorflow.keras.metrics import AUC, F1Score +from tensorflow.keras.metrics import AUC from tensorflow.keras.callbacks import ModelCheckpoint, CSVLogger, \ ReduceLROnPlateau, EarlyStopping # Internal libraries @@ -139,7 +139,7 @@ def block_train(config): "workers": config["workers"], "batch_queue_size": 4, "loss": loss, - "metrics": [AUC(100), F1Score(average="macro")], + "metrics": [AUC(100)], "pretrained_weights": True, "multiprocessing": False, }