From 4b56e164a1ef75a278c093be4a84d3eecff0b57d Mon Sep 17 00:00:00 2001 From: BinarySandia04 Date: Thu, 21 May 2026 17:45:28 +0200 Subject: [PATCH] Parellization ok! --- skin_cancer_classification.py | 38 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/skin_cancer_classification.py b/skin_cancer_classification.py index 50987bf..540344b 100644 --- a/skin_cancer_classification.py +++ b/skin_cancer_classification.py @@ -29,9 +29,9 @@ Original file is located at import sys IN_COLAB = 'google.colab' in sys.modules -#if IN_COLAB: -# !pip install pandas numpy matplotlib seaborn pillow scikit-learn tensorflow -# !pip install --upgrade kagglehub[pandas-datasets,hf-datasets] +# if IN_COLAB: +# !pip install pandas numpy matplotlib seaborn pillow scikit-learn tensorflow +# !pip install --upgrade kagglehub[pandas-datasets,hf-datasets] import kagglehub @@ -282,24 +282,28 @@ data_augmentation = tf.keras.Sequential([ tf.keras.layers.RandomContrast(0.1), ]) -base_model = DenseNet121( - weights='imagenet', - include_top=False, - input_shape=(224, 224, 3) -) +with strategy.scope(): + base_model = DenseNet121( + weights='imagenet', + include_top=False, + input_shape=(224, 224, 3) + ) -inputs = tf.keras.Input(shape=(224,224,3)) +with strategy.scope(): + inputs = tf.keras.Input(shape=(224,224,3)) -x = data_augmentation(inputs) + x = data_augmentation(inputs) -x = base_model.output -x = GlobalAveragePooling2D()(x) -x = Dense(512, activation='relu')(x) # Added another Dense layer -x = Dense(256, activation='relu')(x) # Existing Dense layer -predictions = Dense(1, activation='sigmoid')(x) # Output layer for binary classification +with strategy.scope(): + x = base_model.output + x = GlobalAveragePooling2D()(x) + x = Dense(512, activation='relu')(x) # Added another Dense layer + x = Dense(256, activation='relu')(x) # Existing Dense layer + predictions = Dense(1, activation='sigmoid')(x) # Output layer for binary classification -model = Model(inputs=base_model.input, outputs=predictions) -model.compile(optimizer=Adam(learning_rate=0.0001), loss='binary_crossentropy', metrics=['accuracy']) +with strategy.scope(): + model = Model(inputs=base_model.input, outputs=predictions) + model.compile(optimizer=Adam(learning_rate=0.0001), loss='binary_crossentropy', metrics=['accuracy']) """## 4. Data Generators