Skip to content

Commit

Permalink
chore: merged dev branch to ConvNeXt3D PR
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerdo committed Feb 21, 2024
2 parents e0d6779 + 439683a commit 729a275
Show file tree
Hide file tree
Showing 26 changed files with 117 additions and 161 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.10']
python-version: ['3.9', '3.10']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.10']
python-version: ['3.9', '3.10']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: '3.10'
- run: pip install \
black \
mkdocs-material \
Expand Down
14 changes: 9 additions & 5 deletions aucmedi/ensemble/bagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def train(self, training_generator, epochs=20, iterations=None,
data = (train_x, train_y, None, test_x, test_y, None)
else : data = fold

# Create model specific callback list
callbacks_model = callbacks.copy()
# Extend Callback list
cb_mc = ModelCheckpoint(os.path.join(self.cache_dir.name,
"cv_" + str(i) + \
Expand All @@ -169,7 +171,7 @@ def train(self, training_generator, epochs=20, iterations=None,
"cv_" + str(i) + \
".logs.csv"),
separator=',', append=True)
callbacks.extend([cb_mc, cb_cl])
callbacks_model.extend([cb_mc, cb_cl])

# Gather NeuralNetwork parameters
model_paras = {
Expand Down Expand Up @@ -210,7 +212,7 @@ def train(self, training_generator, epochs=20, iterations=None,
# Gather training parameters
parameters_training = {"epochs": epochs,
"iterations": iterations,
"callbacks": callbacks,
"callbacks": callbacks_model,
"class_weights": class_weights,
"transfer_learning": transfer_learning
}
Expand Down Expand Up @@ -298,12 +300,14 @@ def predict(self, prediction_generator, aggregate="mean",
"kwargs": temp_dg.kwargs
}

# Identify path to model directory
if isinstance(self.cache_dir, tempfile.TemporaryDirectory):
path_model_dir = self.cache_dir.name
else : path_model_dir = self.cache_dir

# Sequentially iterate over all fold models
for i in range(self.k_fold):
# Identify path to fitted model
if isinstance(self.cache_dir, tempfile.TemporaryDirectory):
path_model_dir = self.cache_dir.name
else : path_model_dir = self.cache_dir
path_model = os.path.join(path_model_dir,
"cv_" + str(i) + ".model.hdf5")

Expand Down
22 changes: 12 additions & 10 deletions aucmedi/ensemble/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,6 @@ def train(self, training_generator, epochs=20, iterations=None,
cv_sampling = sampling_kfold(x, y, m, n_splits=self.k_fold,
stratified=True, iterative=True)

# Gather training parameters
parameters_training = {"epochs": epochs,
"iterations": iterations,
"callbacks": callbacks,
"class_weights": class_weights,
"transfer_learning": transfer_learning
}

# Sequentially iterate over model list
for i in range(len(self.model_list)):
# Pack data into a tuple
Expand All @@ -224,6 +216,8 @@ def train(self, training_generator, epochs=20, iterations=None,
data = (train_x, train_y, None, test_x, test_y, None)
else : data = fold

# Create model specific callback list
callbacks_model = callbacks.copy()
# Extend Callback list
path_model = os.path.join(self.cache_dir.name,
"cv_" + str(i) + ".model.hdf5")
Expand All @@ -234,7 +228,7 @@ def train(self, training_generator, epochs=20, iterations=None,
"cv_" + str(i) + \
".logs.csv"),
separator=',', append=True)
callbacks.extend([cb_mc, cb_cl])
callbacks_model.extend([cb_mc, cb_cl])

# Gather NeuralNetwork parameters
model_paras = {
Expand Down Expand Up @@ -272,6 +266,14 @@ def train(self, training_generator, epochs=20, iterations=None,
"kwargs": temp_dg.kwargs
}

# Gather training parameters
parameters_training = {"epochs": epochs,
"iterations": iterations,
"callbacks": callbacks_model,
"class_weights": class_weights,
"transfer_learning": transfer_learning
}

# Start training process
process_queue = mp.Queue()
process_train = mp.Process(target=__training_process__,
Expand Down Expand Up @@ -335,7 +337,7 @@ def train_metalearner(self, training_generator):

# Sequentially iterate over model list
for i in range(len(self.model_list)):
# Extend Callback list
# Load current model
path_model = os.path.join(path_model_dir,
"cv_" + str(i) + ".model.hdf5")

Expand Down
22 changes: 12 additions & 10 deletions aucmedi/ensemble/stacking.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,10 @@ def train(self, training_generator, epochs=20, iterations=None,
data_train = (*ps_sampling[0], None)
data_val = (*ps_sampling[1], None)

# Gather training parameters
parameters_training = {"epochs": epochs,
"iterations": iterations,
"callbacks": callbacks,
"class_weights": class_weights,
"transfer_learning": transfer_learning
}

# Sequentially iterate over model list
for i in range(len(self.model_list)):
# Create model specific callback list
callbacks_model = callbacks.copy()
# Extend Callback list
path_model = os.path.join(self.cache_dir.name,
"nn_" + str(i) + ".model.hdf5")
Expand All @@ -222,7 +216,7 @@ def train(self, training_generator, epochs=20, iterations=None,
"nn_" + str(i) + \
".logs.csv"),
separator=',', append=True)
callbacks.extend([cb_mc, cb_cl])
callbacks_model.extend([cb_mc, cb_cl])

# Gather NeuralNetwork parameters
model_paras = {
Expand Down Expand Up @@ -260,6 +254,14 @@ def train(self, training_generator, epochs=20, iterations=None,
"kwargs": temp_dg.kwargs
}

# Gather training parameters
parameters_training = {"epochs": epochs,
"iterations": iterations,
"callbacks": callbacks_model,
"class_weights": class_weights,
"transfer_learning": transfer_learning
}

# Start training process
process_queue = mp.Queue()
process_train = mp.Process(target=__training_process__,
Expand Down Expand Up @@ -323,7 +325,7 @@ def train_metalearner(self, training_generator):

# Sequentially iterate over model list
for i in range(len(self.model_list)):
# Extend Callback list
# Load current model
path_model = os.path.join(path_model_dir,
"nn_" + str(i) + ".model.hdf5")

Expand Down
2 changes: 1 addition & 1 deletion aucmedi/evaluation/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def evaluate_comparison(pred_list,

# Optional: Macro average classes
if macro_average_classes:
metrics_avg = metrics.groupby(["metric", "model"]).mean()
metrics_avg = metrics.groupby(["metric", "model"])[["score"]].mean()
metrics = metrics_avg.reset_index()

# Append to dataframe list
Expand Down
2 changes: 1 addition & 1 deletion aucmedi/evaluation/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def evalby_barplot(metrics, out_path, class_names, show=False, suffix=None):
#-----------------------------------------------------#
def evalby_rocplot(fpr_list, tpr_list, out_path, class_names, show=False, suffix=None):
# Initialize result dataframe
df_roc = pd.DataFrame(data=[fpr_list, tpr_list], dtype=np.float64)
df_roc = pd.DataFrame(data=[fpr_list, tpr_list], dtype=object)
# Preprocess dataframe
df_roc = df_roc.transpose()
df_roc = df_roc.apply(pd.Series.explode)
Expand Down
15 changes: 4 additions & 11 deletions aucmedi/neural_network/architectures/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,8 +83,6 @@
"ResNet50V2": ResNet50V2,
"ResNet101V2": ResNet101V2,
"ResNet152V2": ResNet152V2,
"ResNeXt50": ResNeXt50,
"ResNeXt101": ResNeXt101,
"DenseNet121": DenseNet121,
"DenseNet169": DenseNet169,
"DenseNet201": DenseNet201,
Expand Down Expand Up @@ -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][].
Expand All @@ -175,8 +170,6 @@
"ResNet50V2": "tf",
"ResNet101V2": "tf",
"ResNet152V2": "tf",
"ResNeXt50": "torch",
"ResNeXt101": "torch",
"DenseNet121": "torch",
"DenseNet169": "torch",
"DenseNet201": "torch",
Expand Down Expand Up @@ -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"]
```
"""
2 changes: 1 addition & 1 deletion aucmedi/neural_network/architectures/image/resnext101.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#==============================================================================#
# Author: Dominik Müller #
# Copyright: 2023 IT-Infrastructure for Translational Medical Research, #
# Copyright: 2022 IT-Infrastructure for Translational Medical Research, #
# University of Augsburg #
# #
# This program is free software: you can redistribute it and/or modify #
Expand Down
2 changes: 1 addition & 1 deletion aucmedi/neural_network/architectures/image/resnext50.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#==============================================================================#
# Author: Dominik Müller #
# Copyright: 2023 IT-Infrastructure for Translational Medical Research, #
# Copyright: 2022 IT-Infrastructure for Translational Medical Research, #
# University of Augsburg #
# #
# This program is free software: you can redistribute it and/or modify #
Expand Down
2 changes: 1 addition & 1 deletion aucmedi/utils/class_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def compute_multilabel_weights(ohe_array, method="balanced"):
class_weights = np.empty([n_classes])
# Compute weight for each class individually
for i in range(0, n_classes):
weight = compute_class_weight(class_weight=method, classes=[0,1],
weight = compute_class_weight(class_weight=method, classes=np.array([0,1]),
y=ohe_array[:, i])
class_weights[i] = weight[1]
# Return resulting class weight list
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For this reason, rather than creating one huge “demonstration Notebook” seve

| Topic | Link |
|:------|:-----:|
| Three Pillars of AUCMEDI | [tutorial01.ipynb](https://github.com/frankkramer-lab/aucmedi/blob/master/examples/tutorials/Augmentation.ipynb) |
| Three Pillars of AUCMEDI | [tutorial01.ipynb](https://github.com/frankkramer-lab/aucmedi/blob/master/examples/tutorials/ThreePillars.ipynb) |
| Data Loading from CSV | [tutorial02.ipynb](https://github.com/frankkramer-lab/aucmedi/blob/master/examples/tutorials/dataLoadingFromCSV.ipynb) |
| Data Loading from Directories | [tutorial03.ipynb](https://github.com/frankkramer-lab/aucmedi/blob/master/examples/tutorials/dataLoadingFromDirectory.ipynb) |
| Architecture Selection | [tutorial04.ipynb](https://github.com/frankkramer-lab/aucmedi/blob/master/examples/tutorials/CustomArchitecture.ipynb) |
Expand Down
2 changes: 1 addition & 1 deletion docs/getstarted/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
AUCMEDI is tested and supported on the following systems:

- 64-bit Ubuntu 16.04 or later
- Python 3.8 - 3.10
- Python 3.9+

AUCMEDI is heavily based on TensorFlow 2: an approachable, highly-productive interface for solving machine learning problems, with a focus on modern deep learning. It provides essential abstractions and building blocks for developing and shipping machine learning solutions with high iteration velocity.

Expand Down
8 changes: 4 additions & 4 deletions examples/tutorials/Augmentation.ipynb

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions examples/tutorials/DataAndResultExploration.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions examples/tutorials/EarlyStoppingAndTransferlearning.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/tutorials/Metadata.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.0"
}
},
"nbformat": 4,
Expand Down
10 changes: 5 additions & 5 deletions examples/tutorials/ThreePillars.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/tutorials/Transferlearning.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/tutorials/XAI.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions examples/tutorials/dataLoadingFromDirectory.ipynb

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
tensorflow==2.11.0
tensorflow-addons==0.18.0
keras-applications==1.0.8
numpy==1.23.0
tensorflow==2.14.0
numpy==1.23.5
pillow==9.3.0
albumentations==1.3.0
pandas==1.5.0
scikit-learn==1.1.0
scikit-image==0.19.2
pandas==1.5.2
scikit-learn==1.3.0
scikit-image==0.21.0
lime==0.2.0.1
pooch==1.6.0
classification-models-3D==1.0.7
vit-keras==0.1.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.24
batchgenerators==0.25
volumentations-aucmedi==1.0.1
plotnine==0.10.0
plotnine==0.12.4
pathos==0.3.0
matplotlib==3.5.1
28 changes: 13 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,26 @@
entry_points={
'console_scripts': ['aucmedi = aucmedi.automl.main:main'],
},
python_requires='>=3.8',
install_requires=['tensorflow>=2.10.0',
'tensorflow-addons>=0.18.0',
'keras-applications>=1.0.8',
'numpy>=1.23.0',
python_requires='>=3.9',
install_requires=['tensorflow>=2.14.0',
'numpy>=1.23.5',
'pillow>=9.3.0',
'albumentations>=1.3.0',
'pandas>=1.5.0',
'scikit-learn>=1.1.0',
'scikit-image>=0.19.1',
'pandas>=1.5.2',
'scikit-learn>=1.3.0',
'scikit-image>=0.21.0',
'lime>=0.2.0.1',
'pooch>=1.6.0',
'classification-models-3D>=1.0.7',
'vit-keras>=0.1.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.24',
'batchgenerators>=0.25',
'volumentations-aucmedi>=1.0.1',
'plotnine>=0.10.0',
'pathos>=0.3.0',
'matplotlib>=3.5.0,<3.5.3'],
'plotnine==0.12.4',
'pathos>=0.3.0'],
classifiers=["Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
Expand Down
Loading

0 comments on commit 729a275

Please sign in to comment.