{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/agilecpu154/Documents/Task-8 Skin Cancer Detection/env/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Path to dataset files: /home/agilecpu154/.cache/kagglehub/datasets/kmader/skin-cancer-mnist-ham10000/versions/2\n" ] } ], "source": [ "import kagglehub\n", "\n", "# Download latest version\n", "path = kagglehub.dataset_download(\"kmader/skin-cancer-mnist-ham10000\")\n", "\n", "print(\"Path to dataset files:\", path)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-01-31 11:54:34.550935: I external/local_xla/xla/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.\n", "2025-01-31 11:54:34.601784: I external/local_xla/xla/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.\n", "2025-01-31 11:54:34.631089: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n", "WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n", "E0000 00:00:1738304674.660236 59431 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n", "E0000 00:00:1738304674.670043 59431 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n", "2025-01-31 11:54:34.705842: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n", "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n" ] } ], "source": [ "import seaborn as sns\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import numpy as np\n", "from imblearn.over_sampling import RandomOverSampler\n", "from sklearn.model_selection import train_test_split\n", "import tensorflow as tf\n", "from tensorflow.keras.models import Sequential\n", "from tensorflow.keras.layers import Conv2D, Flatten, Dense, MaxPool2D, Input\n", "from tensorflow.keras.callbacks import ModelCheckpoint" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1.) Importing Tabular Data" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " lesion_id image_id dx dx_type age sex localization\n", "0 HAM_0000118 ISIC_0027419 bkl histo 80.0 male scalp\n", "1 HAM_0000118 ISIC_0025030 bkl histo 80.0 male scalp\n", "2 HAM_0002730 ISIC_0026769 bkl histo 80.0 male scalp\n", "3 HAM_0002730 ISIC_0025661 bkl histo 80.0 male scalp\n", "4 HAM_0001466 ISIC_0031633 bkl histo 75.0 male ear\n" ] } ], "source": [ "tabular_data = pd.read_csv(r'/home/agilecpu154/.cache/kagglehub/datasets/kmader/skin-cancer-mnist-ham10000/versions/2/HAM10000_metadata.csv')\n", "\n", "print(tabular_data.head())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Importing Data Images with Pixel Values and Labels" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "data = pd.read_csv('/home/agilecpu154/.cache/kagglehub/datasets/kmader/skin-cancer-mnist-ham10000/versions/2/hmnist_28_28_RGB.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Splitting Data into Features(x) and Labels(y)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "x = data.drop('label', axis=1)\n", "y = data['label']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "OverSampling to Overcome Class Imbalance" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "oversample = RandomOverSampler(random_state=42)\n", "x_resampled, y_resampled = oversample.fit_resample(x, y)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reshaping x to match image dimensions(28,28,3)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Shape of x after oversampling and reshaping: (46935, 28, 28, 3)\n" ] } ], "source": [ "x_resampled = np.array(x_resampled).reshape(-1, 28, 28, 3)\n", "\n", "print('Shape of x after oversampling and reshaping:', x_resampled.shape)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Standardizing Data" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "mean = np.mean(x_resampled)\n", "std = np.std(x_resampled)\n", "x_resampled = (x_resampled - mean) / std" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Splitting Data into Train and Test DataSets" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Training set size: (37548, 28, 28, 3), Testing set size: (9387, 28, 28, 3)\n" ] } ], "source": [ "X_train, X_test, Y_train, Y_test = train_test_split(\n", " x_resampled, y_resampled, test_size=0.2, random_state=1\n", ")\n", "\n", "print(f'Training set size: {X_train.shape}, Testing set size: {X_test.shape}')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Building the CNN Model" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-01-31 11:54:53.175525: E external/local_xla/xla/stream_executor/cuda/cuda_driver.cc:152] failed call to cuInit: INTERNAL: CUDA error: Failed call to cuInit: UNKNOWN ERROR (303)\n" ] } ], "source": [ "model = Sequential([\n", " Input(shape=(28, 28, 3)), # Adjusted input shape to match data\n", " Conv2D(16, kernel_size=(3, 3), activation='relu', padding='same'),\n", " Conv2D(32, kernel_size=(3, 3), activation='relu'),\n", " MaxPool2D(pool_size=(2, 2)),\n", " Conv2D(32, kernel_size=(3, 3), activation='relu', padding='same'),\n", " Conv2D(64, kernel_size=(3, 3), activation='relu'),\n", " MaxPool2D(pool_size=(2, 2), padding='same'),\n", " Flatten(),\n", " Dense(64, activation='relu'),\n", " Dense(32, activation='relu'),\n", " Dense(7, activation='softmax')\n", "])" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Model: \"sequential\"\n",
"
\n"
],
"text/plain": [
"\u001b[1mModel: \"sequential\"\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n", "┃ Layer (type) ┃ Output Shape ┃ Param # ┃\n", "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n", "│ conv2d (Conv2D) │ (None, 28, 28, 16) │ 448 │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ conv2d_1 (Conv2D) │ (None, 26, 26, 32) │ 4,640 │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ max_pooling2d (MaxPooling2D) │ (None, 13, 13, 32) │ 0 │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ conv2d_2 (Conv2D) │ (None, 13, 13, 32) │ 9,248 │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ conv2d_3 (Conv2D) │ (None, 11, 11, 64) │ 18,496 │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ max_pooling2d_1 (MaxPooling2D) │ (None, 6, 6, 64) │ 0 │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ flatten (Flatten) │ (None, 2304) │ 0 │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ dense (Dense) │ (None, 64) │ 147,520 │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ dense_1 (Dense) │ (None, 32) │ 2,080 │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ dense_2 (Dense) │ (None, 7) │ 231 │\n", "└─────────────────────────────────┴────────────────────────┴───────────────┘\n", "\n" ], "text/plain": [ "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n", "│ conv2d (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m28\u001b[0m, \u001b[38;5;34m28\u001b[0m, \u001b[38;5;34m16\u001b[0m) │ \u001b[38;5;34m448\u001b[0m │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ conv2d_1 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m26\u001b[0m, \u001b[38;5;34m26\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m4,640\u001b[0m │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ max_pooling2d (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m13\u001b[0m, \u001b[38;5;34m13\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ conv2d_2 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m13\u001b[0m, \u001b[38;5;34m13\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m9,248\u001b[0m │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ conv2d_3 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m11\u001b[0m, \u001b[38;5;34m11\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m18,496\u001b[0m │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ max_pooling2d_1 (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m6\u001b[0m, \u001b[38;5;34m6\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ flatten (\u001b[38;5;33mFlatten\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m2304\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ dense (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m147,520\u001b[0m │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ dense_1 (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m2,080\u001b[0m │\n", "├─────────────────────────────────┼────────────────────────┼───────────────┤\n", "│ dense_2 (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m7\u001b[0m) │ \u001b[38;5;34m231\u001b[0m │\n", "└─────────────────────────────────┴────────────────────────┴───────────────┘\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Total params: 182,663 (713.53 KB)\n", "\n" ], "text/plain": [ "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m182,663\u001b[0m (713.53 KB)\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Trainable params: 182,663 (713.53 KB)\n", "\n" ], "text/plain": [ "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m182,663\u001b[0m (713.53 KB)\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Non-trainable params: 0 (0.00 B)\n", "\n" ], "text/plain": [ "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m0\u001b[0m (0.00 B)\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "model.summary()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Callback to save the best model" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "callback = ModelCheckpoint(\n", " filepath='best_model.keras', # Changed to .keras extension\n", " monitor='val_accuracy', # Monitoring validation accuracy\n", " mode='max',\n", " save_best_only=True,\n", " verbose=1\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compiling the Model" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "model.compile(\n", " loss='sparse_categorical_crossentropy',\n", " optimizer='adam',\n", " metrics=['accuracy']\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Training the Model" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Epoch 1/20\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2025-01-31 11:54:53.974535: W external/local_xla/xla/tsl/framework/cpu_allocator_impl.cc:83] Allocation of 282597504 exceeds 10% of free system memory.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 241ms/step - accuracy: 0.4152 - loss: 1.4796\n", "Epoch 1: val_accuracy improved from -inf to 0.66405, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m61s\u001b[0m 251ms/step - accuracy: 0.4157 - loss: 1.4784 - val_accuracy: 0.6640 - val_loss: 0.8702\n", "Epoch 2/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 238ms/step - accuracy: 0.7215 - loss: 0.7513\n", "Epoch 2: val_accuracy improved from 0.66405 to 0.80786, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m58s\u001b[0m 248ms/step - accuracy: 0.7216 - loss: 0.7509 - val_accuracy: 0.8079 - val_loss: 0.5179\n", "Epoch 3/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 236ms/step - accuracy: 0.8334 - loss: 0.4516\n", "Epoch 3: val_accuracy improved from 0.80786 to 0.87390, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m57s\u001b[0m 245ms/step - accuracy: 0.8335 - loss: 0.4514 - val_accuracy: 0.8739 - val_loss: 0.3529\n", "Epoch 4/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 237ms/step - accuracy: 0.8858 - loss: 0.3141\n", "Epoch 4: val_accuracy improved from 0.87390 to 0.89028, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m58s\u001b[0m 246ms/step - accuracy: 0.8859 - loss: 0.3140 - val_accuracy: 0.8903 - val_loss: 0.3060\n", "Epoch 5/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 274ms/step - accuracy: 0.9219 - loss: 0.2212\n", "Epoch 5: val_accuracy improved from 0.89028 to 0.91771, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m66s\u001b[0m 282ms/step - accuracy: 0.9219 - loss: 0.2212 - val_accuracy: 0.9177 - val_loss: 0.2388\n", "Epoch 6/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 232ms/step - accuracy: 0.9372 - loss: 0.1705\n", "Epoch 6: val_accuracy improved from 0.91771 to 0.93609, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m56s\u001b[0m 240ms/step - accuracy: 0.9372 - loss: 0.1705 - val_accuracy: 0.9361 - val_loss: 0.2019\n", "Epoch 7/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 224ms/step - accuracy: 0.9511 - loss: 0.1382\n", "Epoch 7: val_accuracy did not improve from 0.93609\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m54s\u001b[0m 231ms/step - accuracy: 0.9511 - loss: 0.1382 - val_accuracy: 0.9254 - val_loss: 0.2217\n", "Epoch 8/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 225ms/step - accuracy: 0.9618 - loss: 0.1094\n", "Epoch 8: val_accuracy did not improve from 0.93609\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m55s\u001b[0m 232ms/step - accuracy: 0.9618 - loss: 0.1094 - val_accuracy: 0.9301 - val_loss: 0.2329\n", "Epoch 9/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 224ms/step - accuracy: 0.9613 - loss: 0.1121\n", "Epoch 9: val_accuracy improved from 0.93609 to 0.95166, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m54s\u001b[0m 231ms/step - accuracy: 0.9613 - loss: 0.1121 - val_accuracy: 0.9517 - val_loss: 0.1555\n", "Epoch 10/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 228ms/step - accuracy: 0.9778 - loss: 0.0632\n", "Epoch 10: val_accuracy did not improve from 0.95166\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m55s\u001b[0m 234ms/step - accuracy: 0.9778 - loss: 0.0632 - val_accuracy: 0.9445 - val_loss: 0.2164\n", "Epoch 11/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 245ms/step - accuracy: 0.9753 - loss: 0.0678\n", "Epoch 11: val_accuracy improved from 0.95166 to 0.95393, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m60s\u001b[0m 254ms/step - accuracy: 0.9753 - loss: 0.0678 - val_accuracy: 0.9539 - val_loss: 0.1431\n", "Epoch 12/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 229ms/step - accuracy: 0.9730 - loss: 0.0767\n", "Epoch 12: val_accuracy improved from 0.95393 to 0.96099, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m56s\u001b[0m 238ms/step - accuracy: 0.9730 - loss: 0.0766 - val_accuracy: 0.9610 - val_loss: 0.1470\n", "Epoch 13/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 227ms/step - accuracy: 0.9833 - loss: 0.0493\n", "Epoch 13: val_accuracy did not improve from 0.96099\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m55s\u001b[0m 235ms/step - accuracy: 0.9832 - loss: 0.0494 - val_accuracy: 0.9591 - val_loss: 0.1506\n", "Epoch 14/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 229ms/step - accuracy: 0.9835 - loss: 0.0516\n", "Epoch 14: val_accuracy improved from 0.96099 to 0.96471, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m56s\u001b[0m 237ms/step - accuracy: 0.9835 - loss: 0.0516 - val_accuracy: 0.9647 - val_loss: 0.1172\n", "Epoch 15/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 227ms/step - accuracy: 0.9898 - loss: 0.0331\n", "Epoch 15: val_accuracy improved from 0.96471 to 0.96951, saving model to best_model.keras\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m55s\u001b[0m 235ms/step - accuracy: 0.9898 - loss: 0.0331 - val_accuracy: 0.9695 - val_loss: 0.1228\n", "Epoch 16/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 231ms/step - accuracy: 0.9874 - loss: 0.0386\n", "Epoch 16: val_accuracy did not improve from 0.96951\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m56s\u001b[0m 239ms/step - accuracy: 0.9874 - loss: 0.0386 - val_accuracy: 0.9692 - val_loss: 0.1255\n", "Epoch 17/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 228ms/step - accuracy: 0.9862 - loss: 0.0423\n", "Epoch 17: val_accuracy did not improve from 0.96951\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m55s\u001b[0m 235ms/step - accuracy: 0.9862 - loss: 0.0423 - val_accuracy: 0.9594 - val_loss: 0.1685\n", "Epoch 18/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 225ms/step - accuracy: 0.9931 - loss: 0.0209\n", "Epoch 18: val_accuracy did not improve from 0.96951\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m55s\u001b[0m 233ms/step - accuracy: 0.9931 - loss: 0.0209 - val_accuracy: 0.9643 - val_loss: 0.1693\n", "Epoch 19/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 225ms/step - accuracy: 0.9893 - loss: 0.0331\n", "Epoch 19: val_accuracy did not improve from 0.96951\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m55s\u001b[0m 233ms/step - accuracy: 0.9893 - loss: 0.0331 - val_accuracy: 0.9658 - val_loss: 0.1554\n", "Epoch 20/20\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 222ms/step - accuracy: 0.9925 - loss: 0.0237\n", "Epoch 20: val_accuracy did not improve from 0.96951\n", "\u001b[1m235/235\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m54s\u001b[0m 231ms/step - accuracy: 0.9925 - loss: 0.0237 - val_accuracy: 0.9643 - val_loss: 0.1802\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "WARNING:absl:You are saving your model as an HDF5 file via `model.save()` or `keras.saving.save_model(model)`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')` or `keras.saving.save_model(model, 'my_model.keras')`. \n" ] }, { "ename": "PermissionError", "evalue": "[Errno 13] Permission denied: '/final'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mPermissionError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[15], line 9\u001b[0m\n\u001b[1;32m 1\u001b[0m history \u001b[38;5;241m=\u001b[39m model\u001b[38;5;241m.\u001b[39mfit(\n\u001b[1;32m 2\u001b[0m X_train, Y_train,\n\u001b[1;32m 3\u001b[0m validation_split\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.2\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 6\u001b[0m callbacks\u001b[38;5;241m=\u001b[39m[callback]\n\u001b[1;32m 7\u001b[0m )\n\u001b[0;32m----> 9\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msave\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m/final/final_model.h5\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSaved \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfinal_model.h5\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", "File \u001b[0;32m~/Documents/Task-8 Skin Cancer Detection/env/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py:122\u001b[0m, in \u001b[0;36mfilter_traceback.