From 979a66073206c5b7ee3c9a1ac5915ddf05d6931c Mon Sep 17 00:00:00 2001 From: muellerdo Date: Wed, 21 Feb 2024 14:33:08 +0100 Subject: [PATCH] feat(Architectures): removed 2D ResNeXt image architecture support --- .../architectures/image/__init__.py | 15 +--- .../architectures/image/resnext101.py | 82 ------------------- .../architectures/image/resnext50.py | 82 ------------------- tests/test_architectures_image.py | 42 ---------- 4 files changed, 4 insertions(+), 217 deletions(-) delete mode 100644 aucmedi/neural_network/architectures/image/resnext101.py delete mode 100644 aucmedi/neural_network/architectures/image/resnext50.py diff --git a/aucmedi/neural_network/architectures/image/__init__.py b/aucmedi/neural_network/architectures/image/__init__.py index f75824b1..b3282fc0 100644 --- a/aucmedi/neural_network/architectures/image/__init__.py +++ b/aucmedi/neural_network/architectures/image/__init__.py @@ -49,9 +49,6 @@ from aucmedi.neural_network.architectures.image.resnet50v2 import ResNet50V2 from aucmedi.neural_network.architectures.image.resnet101v2 import ResNet101V2 from aucmedi.neural_network.architectures.image.resnet152v2 import ResNet152V2 -# ResNeXt -from aucmedi.neural_network.architectures.image.resnext50 import ResNeXt50 -from aucmedi.neural_network.architectures.image.resnext101 import ResNeXt101 # MobileNet from aucmedi.neural_network.architectures.image.mobilenet import MobileNet from aucmedi.neural_network.architectures.image.mobilenetv2 import MobileNetV2 @@ -86,8 +83,6 @@ "ResNet50V2": ResNet50V2, "ResNet101V2": ResNet101V2, "ResNet152V2": ResNet152V2, - "ResNeXt50": ResNeXt50, - "ResNeXt101": ResNeXt101, "DenseNet121": DenseNet121, "DenseNet169": DenseNet169, "DenseNet201": DenseNet201, @@ -153,8 +148,8 @@ For example: ```python - # for the image architecture "ResNeXt101" - architecture="2D.ResNeXt101" + # for the image architecture "ResNet101" + architecture="2D.ResNet101" ``` Architectures are based on the abstract base class [aucmedi.neural_network.architectures.arch_base.Architecture_Base][]. @@ -175,8 +170,6 @@ "ResNet50V2": "tf", "ResNet101V2": "tf", "ResNet152V2": "tf", - "ResNeXt50": "torch", - "ResNeXt101": "torch", "DenseNet121": "torch", "DenseNet169": "torch", "DenseNet201": "torch", @@ -237,8 +230,8 @@ For example: ```python - # for the image architecture "ResNeXt101" + # for the image architecture "ResNet101" from aucmedi.neural_network.architectures import supported_standardize_mode - sf_norm = supported_standardize_mode["2D.ResNeXt101"] + sf_norm = supported_standardize_mode["2D.ResNet101"] ``` """ diff --git a/aucmedi/neural_network/architectures/image/resnext101.py b/aucmedi/neural_network/architectures/image/resnext101.py deleted file mode 100644 index 7a08d805..00000000 --- a/aucmedi/neural_network/architectures/image/resnext101.py +++ /dev/null @@ -1,82 +0,0 @@ -#==============================================================================# -# Author: Dominik Müller # -# Copyright: 2023 IT-Infrastructure for Translational Medical Research, # -# University of Augsburg # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -#==============================================================================# -#-----------------------------------------------------# -# Documentation # -#-----------------------------------------------------# -""" The classification variant of the ResNeXt101 architecture. - -| Architecture Variable | Value | -| ------------------------ | -------------------------- | -| Key in architecture_dict | "2D.ResNeXt101" | -| Input_shape | (224, 224) | -| Standardization | "torch" | - -???+ abstract "Reference - Implementation" - [https://github.com/keras-team/keras-applications](https://github.com/keras-team/keras-applications)
- -???+ abstract "Reference - Publication" - Saining Xie, Ross Girshick, Piotr Dollár, Zhuowen Tu, Kaiming He. 16 Nov 2016. - Aggregated Residual Transformations for Deep Neural Networks. -
- [https://arxiv.org/abs/1611.05431](https://arxiv.org/abs/1611.05431) -""" -#-----------------------------------------------------# -# Library imports # -#-----------------------------------------------------# -# External libraries -from tensorflow import keras -from keras_applications.resnext import ResNeXt101 as BaseModel -# Internal libraries -from aucmedi.neural_network.architectures import Architecture_Base - -#-----------------------------------------------------# -# Architecture class: ResNeXt101 # -#-----------------------------------------------------# -class ResNeXt101(Architecture_Base): - #---------------------------------------------# - # Initialization # - #---------------------------------------------# - def __init__(self, classification_head, channels, input_shape=(224, 224), - pretrained_weights=False): - self.classifier = classification_head - self.input = input_shape + (channels,) - self.pretrained_weights = pretrained_weights - - #---------------------------------------------# - # Create Model # - #---------------------------------------------# - def create_model(self): - # Get pretrained image weights from imagenet if desired - if self.pretrained_weights : model_weights = "imagenet" - else : model_weights = None - - # Obtain ResNeXt101 as base model - base_model = BaseModel(include_top=False, weights=model_weights, - input_tensor=None, input_shape=self.input, - pooling=None, backend=keras.backend, - layers=keras.layers, models=keras.models, - utils=keras.utils) - top_model = base_model.output - - # Add classification head - model = self.classifier.build(model_input=base_model.input, - model_output=top_model) - - # Return created model - return model diff --git a/aucmedi/neural_network/architectures/image/resnext50.py b/aucmedi/neural_network/architectures/image/resnext50.py deleted file mode 100644 index 9eaa531d..00000000 --- a/aucmedi/neural_network/architectures/image/resnext50.py +++ /dev/null @@ -1,82 +0,0 @@ -#==============================================================================# -# Author: Dominik Müller # -# Copyright: 2023 IT-Infrastructure for Translational Medical Research, # -# University of Augsburg # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -#==============================================================================# -#-----------------------------------------------------# -# Documentation # -#-----------------------------------------------------# -""" The classification variant of the ResNeXt50 architecture. - -| Architecture Variable | Value | -| ------------------------ | -------------------------- | -| Key in architecture_dict | "2D.ResNeXt50" | -| Input_shape | (224, 224) | -| Standardization | "torch" | - -???+ abstract "Reference - Implementation" - [https://github.com/keras-team/keras-applications](https://github.com/keras-team/keras-applications)
- -???+ abstract "Reference - Publication" - Saining Xie, Ross Girshick, Piotr Dollár, Zhuowen Tu, Kaiming He. 16 Nov 2016. - Aggregated Residual Transformations for Deep Neural Networks. -
- [https://arxiv.org/abs/1611.05431](https://arxiv.org/abs/1611.05431) -""" -#-----------------------------------------------------# -# Library imports # -#-----------------------------------------------------# -# External libraries -from tensorflow import keras -from keras_applications.resnext import ResNeXt50 as BaseModel -# Internal libraries -from aucmedi.neural_network.architectures import Architecture_Base - -#-----------------------------------------------------# -# Architecture class: ResNeXt50 # -#-----------------------------------------------------# -class ResNeXt50(Architecture_Base): - #---------------------------------------------# - # Initialization # - #---------------------------------------------# - def __init__(self, classification_head, channels, input_shape=(224, 224), - pretrained_weights=False): - self.classifier = classification_head - self.input = input_shape + (channels,) - self.pretrained_weights = pretrained_weights - - #---------------------------------------------# - # Create Model # - #---------------------------------------------# - def create_model(self): - # Get pretrained image weights from imagenet if desired - if self.pretrained_weights : model_weights = "imagenet" - else : model_weights = None - - # Obtain ResNeXt50 as base model - base_model = BaseModel(include_top=False, weights=model_weights, - input_tensor=None, input_shape=self.input, - pooling=None, backend=keras.backend, - layers=keras.layers, models=keras.models, - utils=keras.utils) - top_model = base_model.output - - # Add classification head - model = self.classifier.build(model_input=base_model.input, - model_output=top_model) - - # Return created model - return model diff --git a/tests/test_architectures_image.py b/tests/test_architectures_image.py index 3c51c066..61ce1e8d 100644 --- a/tests/test_architectures_image.py +++ b/tests/test_architectures_image.py @@ -229,48 +229,6 @@ def test_ResNet152V2(self): self.assertTrue(supported_standardize_mode["ResNet152V2"] == "tf") self.assertTrue(sdm_global["2D.ResNet152V2"] == "tf") - #-------------------------------------------------# - # Architecture: ResNeXt50 # - #-------------------------------------------------# - def test_ResNeXt50(self): - arch = ResNeXt50(Classifier(n_labels=4), channels=1, - input_shape=(32, 32)) - model = NeuralNetwork(n_labels=4, channels=1, architecture=arch, - batch_queue_size=1) - model.predict(self.datagen_GRAY) - arch = ResNeXt50(Classifier(n_labels=4), channels=3, - input_shape=(32, 32)) - model = NeuralNetwork(n_labels=4, channels=3, architecture=arch, - batch_queue_size=1) - model.predict(self.datagen_RGB) - model = NeuralNetwork(n_labels=4, channels=3, architecture="2D.ResNeXt50", - batch_queue_size=1, input_shape=(32, 32)) - try : model.model.summary() - except : raise Exception() - self.assertTrue(supported_standardize_mode["ResNeXt50"] == "torch") - self.assertTrue(sdm_global["2D.ResNeXt50"] == "torch") - - #-------------------------------------------------# - # Architecture: ResNeXt101 # - #-------------------------------------------------# - def test_ResNeXt101(self): - arch = ResNeXt101(Classifier(n_labels=4), channels=1, - input_shape=(32, 32)) - model = NeuralNetwork(n_labels=4, channels=1, architecture=arch, - batch_queue_size=1) - model.predict(self.datagen_GRAY) - arch = ResNeXt101(Classifier(n_labels=4), channels=3, - input_shape=(32, 32)) - model = NeuralNetwork(n_labels=4, channels=3, architecture=arch, - batch_queue_size=1) - model.predict(self.datagen_RGB) - model = NeuralNetwork(n_labels=4, channels=3, architecture="2D.ResNeXt101", - batch_queue_size=1, input_shape=(32, 32)) - try : model.model.summary() - except : raise Exception() - self.assertTrue(supported_standardize_mode["ResNeXt101"] == "torch") - self.assertTrue(sdm_global["2D.ResNeXt101"] == "torch") - #-------------------------------------------------# # Architecture: DenseNet121 # #-------------------------------------------------#