{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":71608,"databundleVersionId":7895811,"sourceType":"competition"}],"dockerImageVersionId":30664,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-03-12T02:32:11.835431Z","iopub.execute_input":"2024-03-12T02:32:11.836005Z","iopub.status.idle":"2024-03-12T02:32:11.841971Z","shell.execute_reply.started":"2024-03-12T02:32:11.835968Z","shell.execute_reply":"2024-03-12T02:32:11.840836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs('kaggle/Training')","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.844436Z","iopub.execute_input":"2024-03-12T02:32:11.844836Z","iopub.status.idle":"2024-03-12T02:32:11.854300Z","shell.execute_reply.started":"2024-03-12T02:32:11.844801Z","shell.execute_reply":"2024-03-12T02:32:11.853234Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs('kaggle/Test')","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.855593Z","iopub.execute_input":"2024-03-12T02:32:11.856434Z","iopub.status.idle":"2024-03-12T02:32:11.865543Z","shell.execute_reply.started":"2024-03-12T02:32:11.856394Z","shell.execute_reply":"2024-03-12T02:32:11.864605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv('/kaggle/input/aiml-general-championship/KCDH2024_Training_GroundTruth.csv')","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.868179Z","iopub.execute_input":"2024-03-12T02:32:11.868530Z","iopub.status.idle":"2024-03-12T02:32:11.903225Z","shell.execute_reply.started":"2024-03-12T02:32:11.868495Z","shell.execute_reply":"2024-03-12T02:32:11.902141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['image']=df['image'].apply(lambda x:x+'.jpg')","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.904715Z","iopub.execute_input":"2024-03-12T02:32:11.905304Z","iopub.status.idle":"2024-03-12T02:32:11.916018Z","shell.execute_reply.started":"2024-03-12T02:32:11.905272Z","shell.execute_reply":"2024-03-12T02:32:11.915131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.917160Z","iopub.execute_input":"2024-03-12T02:32:11.917547Z","iopub.status.idle":"2024-03-12T02:32:11.935573Z","shell.execute_reply.started":"2024-03-12T02:32:11.917516Z","shell.execute_reply":"2024-03-12T02:32:11.934732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs('kaggle/Training/MEL')\nos.makedirs('kaggle/Training/NV')\nos.makedirs('kaggle/Training/BCC')\nos.makedirs('kaggle/Training/AKIEC')\nos.makedirs('kaggle/Training/BKL')\nos.makedirs('kaggle/Training/DF')\nos.makedirs('kaggle/Training/VASC')","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.936680Z","iopub.execute_input":"2024-03-12T02:32:11.936947Z","iopub.status.idle":"2024-03-12T02:32:11.942475Z","shell.execute_reply.started":"2024-03-12T02:32:11.936922Z","shell.execute_reply":"2024-03-12T02:32:11.941599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"L=df.columns.values[1:8]","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.943666Z","iopub.execute_input":"2024-03-12T02:32:11.944499Z","iopub.status.idle":"2024-03-12T02:32:11.957120Z","shell.execute_reply.started":"2024-03-12T02:32:11.944465Z","shell.execute_reply":"2024-03-12T02:32:11.955936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in L:\n    os.makedirs(f'kaggle/Test/{i}')","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.958350Z","iopub.execute_input":"2024-03-12T02:32:11.958758Z","iopub.status.idle":"2024-03-12T02:32:11.967678Z","shell.execute_reply.started":"2024-03-12T02:32:11.958727Z","shell.execute_reply":"2024-03-12T02:32:11.966829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['image_url']=df['image'].apply(lambda x:'/kaggle/input/aiml-general-championship/KCDH2024_Training_Input_10K/KCDH2024_Training_Input_10K/'+x)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.970769Z","iopub.execute_input":"2024-03-12T02:32:11.971025Z","iopub.status.idle":"2024-03-12T02:32:11.982406Z","shell.execute_reply.started":"2024-03-12T02:32:11.971003Z","shell.execute_reply":"2024-03-12T02:32:11.981581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.983555Z","iopub.execute_input":"2024-03-12T02:32:11.983826Z","iopub.status.idle":"2024-03-12T02:32:11.992106Z","shell.execute_reply.started":"2024-03-12T02:32:11.983797Z","shell.execute_reply":"2024-03-12T02:32:11.991395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_MEL=df[df['MEL']==1]\ndf_MEL=df_MEL.sample(frac = 1)\nfor i in range(0,len(df_MEL)-51):\n    try:\n        shutil.copy(df_MEL.iloc[i]['image_url'], \"kaggle/Training/MEL/\"+ df_MEL.iloc[i]['image'])\n    except:\n        pass\nfor i in range(len(df_MEL)-51,len(df_MEL)-1):\n    try:\n        shutil.copy(df_MEL.iloc[i]['image_url'], \"kaggle/Test/MEL/\"+ df_MEL.iloc[i]['image'])\n    except:\n        pass","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:11.993107Z","iopub.execute_input":"2024-03-12T02:32:11.993339Z","iopub.status.idle":"2024-03-12T02:32:24.448040Z","shell.execute_reply.started":"2024-03-12T02:32:11.993319Z","shell.execute_reply":"2024-03-12T02:32:24.447257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_NV=df[df['NV']==1]\ndf_NV=df_NV.sample(frac = 1)\nfor i in range(0,len(df_NV)-200):\n    try:\n        shutil.copy(df_NV.iloc[i]['image_url'], \"kaggle/Training/NV/\"+ df_NV.iloc[i]['image'])\n    except:\n        pass\nfor i in range(len(df_NV)-200,len(df_NV)-1):\n    try:\n        shutil.copy(df_NV.iloc[i]['image_url'], \"kaggle/Test/NV/\"+ df_NV.iloc[i]['image'])\n    except:\n        pass","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:32:24.449097Z","iopub.execute_input":"2024-03-12T02:32:24.449391Z","iopub.status.idle":"2024-03-12T02:33:39.771615Z","shell.execute_reply.started":"2024-03-12T02:32:24.449366Z","shell.execute_reply":"2024-03-12T02:33:39.770756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_BKL=df[df['BKL']==1]\ndf_BKL=df_BKL.sample(frac = 1)\nfor i in range(0,len(df_BKL)-51):\n    try:\n        shutil.copy(df_BKL.iloc[i]['image_url'], \"kaggle/Training/BKL/\"+ df_BKL.iloc[i]['image'])\n    except:\n        pass\nfor i in range(len(df_BKL)-51,len(df_BKL)-1):\n    try:\n        shutil.copy(df_BKL.iloc[i]['image_url'], \"kaggle/Test/BKL/\"+ df_BKL.iloc[i]['image'])\n    except:\n        pass","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:33:39.772879Z","iopub.execute_input":"2024-03-12T02:33:39.773232Z","iopub.status.idle":"2024-03-12T02:33:52.143337Z","shell.execute_reply.started":"2024-03-12T02:33:39.773199Z","shell.execute_reply":"2024-03-12T02:33:52.142386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_BCC=df[df['BCC']==1]\ndf_BCC=df_BCC.sample(frac = 1)\nfor i in range(0,len(df_BCC)-31):\n    try:\n        shutil.copy(df_BCC.iloc[i]['image_url'], \"kaggle/Training/BCC/\"+ df_BCC.iloc[i]['image'])\n    except:\n        pass\nfor i in range(len(df_BCC)-31,len(df_BCC)-1):\n    try:\n        shutil.copy(df_BCC.iloc[i]['image_url'], \"kaggle/Test/BCC/\"+ df_BCC.iloc[i]['image'])\n    except:\n        pass","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:33:52.144514Z","iopub.execute_input":"2024-03-12T02:33:52.144780Z","iopub.status.idle":"2024-03-12T02:33:57.736693Z","shell.execute_reply.started":"2024-03-12T02:33:52.144757Z","shell.execute_reply":"2024-03-12T02:33:57.735792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_VASC=df[df['VASC']==1]\ndf_VASC=df_VASC.sample(frac = 1)\nfor i in range(0,len(df_VASC)-21):\n    try:\n        shutil.copy(df_VASC.iloc[i]['image_url'], \"kaggle/Training/VASC/\"+ df_VASC.iloc[i]['image'])\n    except:\n        pass\nfor i in range(len(df_VASC)-21,len(df_VASC)-1):\n    try:\n        shutil.copy(df_VASC.iloc[i]['image_url'], \"kaggle/Test/VASC/\"+ df_VASC.iloc[i]['image'])\n    except:\n        pass","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:33:57.737824Z","iopub.execute_input":"2024-03-12T02:33:57.738105Z","iopub.status.idle":"2024-03-12T02:33:59.284987Z","shell.execute_reply.started":"2024-03-12T02:33:57.738081Z","shell.execute_reply":"2024-03-12T02:33:59.284194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_DF=df[df['DF']==1]\ndf_DF=df_DF.sample(frac = 1)\nfor i in range(0,len(df_DF)-31):\n    try:\n        shutil.copy(df_DF.iloc[i]['image_url'], \"kaggle/Training/DF/\"+ df_DF.iloc[i]['image'])\n    except:\n        pass\nfor i in range(len(df_DF)-31,len(df_DF)-1):\n    try:\n        shutil.copy(df_DF.iloc[i]['image_url'], \"kaggle/Test/DF/\"+ df_DF.iloc[i]['image'])\n    except:\n        pass","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:33:59.286213Z","iopub.execute_input":"2024-03-12T02:33:59.286662Z","iopub.status.idle":"2024-03-12T02:34:00.590422Z","shell.execute_reply.started":"2024-03-12T02:33:59.286627Z","shell.execute_reply":"2024-03-12T02:34:00.589644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_AKIEC=df[df['AKIEC']==1]\ndf_AKIEC=df_AKIEC.sample(frac = 1)\nfor i in range(0,len(df_AKIEC)-31):\n    try:\n        shutil.copy(df_AKIEC.iloc[i]['image_url'], \"kaggle/Training/AKIEC/\"+ df_AKIEC.iloc[i]['image'])\n    except:\n        pass\nfor i in range(len(df_AKIEC)-31,len(df_AKIEC)-1):\n    try:\n        shutil.copy(df_AKIEC.iloc[i]['image_url'], \"kaggle/Test/AKIEC/\"+ df_AKIEC.iloc[i]['image'])\n    except:\n        pass","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:34:00.591593Z","iopub.execute_input":"2024-03-12T02:34:00.591862Z","iopub.status.idle":"2024-03-12T02:34:04.655149Z","shell.execute_reply.started":"2024-03-12T02:34:00.591838Z","shell.execute_reply":"2024-03-12T02:34:04.654356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**training model**","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.applications import DenseNet121\nfrom tensorflow.keras.layers import Dense, GlobalAveragePooling2D, Dropout\nfrom tensorflow.keras.models import Model\nfrom tensorflow.keras.callbacks import EarlyStopping","metadata":{"execution":{"iopub.status.busy":"2024-03-13T04:20:53.873752Z","iopub.execute_input":"2024-03-13T04:20:53.874384Z","iopub.status.idle":"2024-03-13T04:21:13.178018Z","shell.execute_reply.started":"2024-03-13T04:20:53.874339Z","shell.execute_reply":"2024-03-13T04:21:13.177032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define constants\nIMAGE_SIZE = 224\nBATCH_SIZE = 32\nNUM_CLASSES = 7\nEPOCHS = 24\nSTEPS_PER_EPOCH = 100","metadata":{"execution":{"iopub.status.busy":"2024-03-13T04:20:33.421741Z","iopub.execute_input":"2024-03-13T04:20:33.422076Z","iopub.status.idle":"2024-03-13T04:20:33.432852Z","shell.execute_reply.started":"2024-03-13T04:20:33.422048Z","shell.execute_reply":"2024-03-13T04:20:33.432083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define data directories\ntrain_dir = '/kaggle/working/kaggle/Training'\nval_dir = '/kaggle/working/kaggle/Test'","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:34:17.827225Z","iopub.execute_input":"2024-03-12T02:34:17.827490Z","iopub.status.idle":"2024-03-12T02:34:17.851387Z","shell.execute_reply.started":"2024-03-12T02:34:17.827456Z","shell.execute_reply":"2024-03-12T02:34:17.850493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Data preprocessing and augmentation\ntrain_datagen = ImageDataGenerator(\n    rescale=1./255,\n    rotation_range=20,\n    width_shift_range=0.2,\n    height_shift_range=0.2,\n    shear_range=0.2,\n    zoom_range=0.2,\n    horizontal_flip=True,\n    fill_mode='nearest'\n)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:34:17.852700Z","iopub.execute_input":"2024-03-12T02:34:17.853547Z","iopub.status.idle":"2024-03-12T02:34:17.864438Z","shell.execute_reply.started":"2024-03-12T02:34:17.853515Z","shell.execute_reply":"2024-03-12T02:34:17.863487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_datagen = ImageDataGenerator(rescale=1./255)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:34:17.868879Z","iopub.execute_input":"2024-03-12T02:34:17.869142Z","iopub.status.idle":"2024-03-12T02:34:17.873648Z","shell.execute_reply.started":"2024-03-12T02:34:17.869116Z","shell.execute_reply":"2024-03-12T02:34:17.872633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load and augment training data\ntrain_generator = train_datagen.flow_from_directory(\n    train_dir,\n    target_size=(IMAGE_SIZE, IMAGE_SIZE),\n    batch_size=BATCH_SIZE,\n    class_mode='categorical'\n)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:34:17.874912Z","iopub.execute_input":"2024-03-12T02:34:17.875521Z","iopub.status.idle":"2024-03-12T02:34:18.151846Z","shell.execute_reply.started":"2024-03-12T02:34:17.875488Z","shell.execute_reply":"2024-03-12T02:34:18.150902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load validation data without augmentation\nval_generator = val_datagen.flow_from_directory(\n    val_dir,\n    target_size=(IMAGE_SIZE, IMAGE_SIZE),\n    batch_size=BATCH_SIZE,\n    class_mode='categorical'\n)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:34:18.153103Z","iopub.execute_input":"2024-03-12T02:34:18.153370Z","iopub.status.idle":"2024-03-12T02:34:18.175088Z","shell.execute_reply.started":"2024-03-12T02:34:18.153346Z","shell.execute_reply":"2024-03-12T02:34:18.174236Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Load pre-trained MobileNet model\nbase_model = DenseNet121(weights='imagenet', include_top=False, input_shape=(IMAGE_SIZE, IMAGE_SIZE, 3))","metadata":{"execution":{"iopub.status.busy":"2024-03-13T04:21:13.179459Z","iopub.execute_input":"2024-03-13T04:21:13.179958Z","iopub.status.idle":"2024-03-13T04:21:17.343340Z","shell.execute_reply.started":"2024-03-13T04:21:13.179915Z","shell.execute_reply":"2024-03-13T04:21:17.342458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Add custom top layers\nx = base_model.output\nx = GlobalAveragePooling2D()(x)\nx = Dense(1024, activation='relu')(x)\nx = Dropout(0.5)(x) \nx = Dense(512, activation='relu')(x)\nx = Dropout(0.4)(x)\nx = Dense(256, activation='relu')(x)\nx = Dropout(0.5)(x)\nx = Dense(128, activation='relu')(x)\npredictions = Dense(NUM_CLASSES, activation='softmax')(x)","metadata":{"execution":{"iopub.status.busy":"2024-03-13T04:23:09.568866Z","iopub.execute_input":"2024-03-13T04:23:09.569344Z","iopub.status.idle":"2024-03-13T04:23:09.622558Z","shell.execute_reply.started":"2024-03-13T04:23:09.569311Z","shell.execute_reply":"2024-03-13T04:23:09.621713Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Combine base model with custom top layers\nmodel = Model(inputs=base_model.input, outputs=predictions)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:34:19.970790Z","iopub.execute_input":"2024-03-12T02:34:19.971106Z","iopub.status.idle":"2024-03-12T02:34:20.229118Z","shell.execute_reply.started":"2024-03-12T02:34:19.971078Z","shell.execute_reply":"2024-03-12T02:34:20.228132Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Freeze base layers\nfor layer in base_model.layers:\n    layer.trainable = False","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:34:20.230516Z","iopub.execute_input":"2024-03-12T02:34:20.230867Z","iopub.status.idle":"2024-03-12T02:34:20.238658Z","shell.execute_reply.started":"2024-03-12T02:34:20.230835Z","shell.execute_reply":"2024-03-12T02:34:20.237634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Compile the model\nmodel.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2024-03-12T02:34:20.239768Z","iopub.execute_input":"2024-03-12T02:34:20.240033Z","iopub.status.idle":"2024-03-12T02:34:20.260377Z","shell.execute_reply.started":"2024-03-12T02:34:20.240010Z","shell.execute_reply":"2024-03-12T02:34:20.259503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"early_stopping = EarlyStopping(monitor='val_loss', patience=5, restore_best_weights=True)","metadata":{"execution":{"iopub.status.busy":"2024-03-13T04:23:23.636541Z","iopub.execute_input":"2024-03-13T04:23:23.637401Z","iopub.status.idle":"2024-03-13T04:23:23.641620Z","shell.execute_reply.started":"2024-03-13T04:23:23.637365Z","shell.execute_reply":"2024-03-13T04:23:23.640726Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    train_generator,\n    steps_per_epoch=STEPS_PER_EPOCH,\n    epochs=EPOCHS,\n    validation_data=val_generator,\n    callbacks=[early_stopping]\n)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T16:58:08.567837Z","iopub.execute_input":"2024-03-12T16:58:08.568190Z","iopub.status.idle":"2024-03-12T16:58:08.594874Z","shell.execute_reply.started":"2024-03-12T16:58:08.568161Z","shell.execute_reply":"2024-03-12T16:58:08.593666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2024-03-12T03:01:07.719780Z","iopub.execute_input":"2024-03-12T03:01:07.720357Z","iopub.status.idle":"2024-03-12T03:01:07.724405Z","shell.execute_reply.started":"2024-03-12T03:01:07.720328Z","shell.execute_reply":"2024-03-12T03:01:07.723491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['accuracy'], label='Training Accuracy')\nplt.plot(history.history['val_accuracy'], label='Validation Accuracy')\nplt.xlabel('Epoch')\nplt.ylabel('Accuracy')\nplt.legend()\nplt.title('Training and Validation Accuracy')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-12T03:01:07.725643Z","iopub.execute_input":"2024-03-12T03:01:07.725995Z","iopub.status.idle":"2024-03-12T03:01:08.071889Z","shell.execute_reply.started":"2024-03-12T03:01:07.725963Z","shell.execute_reply":"2024-03-12T03:01:08.070993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(history.history['loss'], label='Training Loss')\nplt.plot(history.history['val_loss'], label='Validation Loss')\nplt.xlabel('Epoch')\nplt.ylabel('Loss')\nplt.legend()\nplt.title('Training and Validation Loss')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-03-12T03:01:08.073025Z","iopub.execute_input":"2024-03-12T03:01:08.073295Z","iopub.status.idle":"2024-03-12T03:01:08.375388Z","shell.execute_reply.started":"2024-03-12T03:01:08.073270Z","shell.execute_reply":"2024-03-12T03:01:08.374487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.preprocessing import image","metadata":{"execution":{"iopub.status.busy":"2024-03-12T03:01:08.376584Z","iopub.execute_input":"2024-03-12T03:01:08.376933Z","iopub.status.idle":"2024-03-12T03:01:08.381538Z","shell.execute_reply.started":"2024-03-12T03:01:08.376896Z","shell.execute_reply":"2024-03-12T03:01:08.380473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_path = \"/kaggle/input/aiml-general-championship/KCDH2024_Test_Input/KCDH2024_Test_Input/ISIC_0034524.jpg\"\nimg = image.load_img(img_path, target_size=(IMAGE_SIZE, IMAGE_SIZE))\nimg_array = image.img_to_array(img)\nimg_array = img_array / 255.0  # Normalize the image\nimg_array = np.expand_dims(img_array, axis=0)  # Add batch dimension\n\n# Predict the class probabilities\nprediction = model.predict(img_array)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T03:05:39.183929Z","iopub.execute_input":"2024-03-12T03:05:39.184318Z","iopub.status.idle":"2024-03-12T03:05:39.261234Z","shell.execute_reply.started":"2024-03-12T03:05:39.184288Z","shell.execute_reply":"2024-03-12T03:05:39.260502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_class = np.argmax(prediction)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T03:06:34.368954Z","iopub.execute_input":"2024-03-12T03:06:34.369749Z","iopub.status.idle":"2024-03-12T03:06:34.374319Z","shell.execute_reply.started":"2024-03-12T03:06:34.369716Z","shell.execute_reply":"2024-03-12T03:06:34.373281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction","metadata":{"execution":{"iopub.status.busy":"2024-03-12T03:05:49.840305Z","iopub.execute_input":"2024-03-12T03:05:49.840997Z","iopub.status.idle":"2024-03-12T03:05:49.847078Z","shell.execute_reply.started":"2024-03-12T03:05:49.840966Z","shell.execute_reply":"2024-03-12T03:05:49.845967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_class","metadata":{"execution":{"iopub.status.busy":"2024-03-12T03:06:45.063376Z","iopub.execute_input":"2024-03-12T03:06:45.063736Z","iopub.status.idle":"2024-03-12T03:06:45.069748Z","shell.execute_reply.started":"2024-03-12T03:06:45.063707Z","shell.execute_reply":"2024-03-12T03:06:45.068777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Path to the folder containing images for prediction\nfolder_path = '/kaggle/input/aiml-general-championship/KCDH2024_Test_Input/KCDH2024_Test_Input'\n\n# List to store predictions and image names\npredictions = []\nimage_names = []\n\n# Iterate through images in the folder\nfor img_name in os.listdir(folder_path):\n    try:\n        img_path = os.path.join(folder_path, img_name)\n        img = image.load_img(img_path, target_size=(IMAGE_SIZE, IMAGE_SIZE))\n        img_array = image.img_to_array(img)\n        img_array = img_array / 255.0  # Normalize the image\n        img_array = np.expand_dims(img_array, axis=0)  # Add batch dimension\n\n    # Predict the class probabilities\n        prediction = model.predict(img_array)\n    \n    # Get the predicted class label\n        predicted_class = np.argmax(prediction)\n    \n    # Append the prediction and image name to lists\n        predictions.append(predicted_class)\n        image_names.append(img_name)\n    except:\n        pass\n\n# Create a DataFrame to store predictions and image names\ndata = {'ID': image_names, 'CLASS': predictions}\ndf = pd.DataFrame(data)\n\n# Save the DataFrame to a CSV file\n#df.to_csv('predictions.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T16:55:43.183767Z","iopub.execute_input":"2024-03-12T16:55:43.184682Z","iopub.status.idle":"2024-03-12T16:55:43.220883Z","shell.execute_reply.started":"2024-03-12T16:55:43.184647Z","shell.execute_reply":"2024-03-12T16:55:43.219695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('predictions.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-03-12T03:14:10.378193Z","iopub.execute_input":"2024-03-12T03:14:10.378560Z","iopub.status.idle":"2024-03-12T03:14:10.389354Z","shell.execute_reply.started":"2024-03-12T03:14:10.378531Z","shell.execute_reply":"2024-03-12T03:14:10.388520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2024-03-12T03:18:57.452084Z","iopub.execute_input":"2024-03-12T03:18:57.452997Z","iopub.status.idle":"2024-03-12T03:18:57.463416Z","shell.execute_reply.started":"2024-03-12T03:18:57.452962Z","shell.execute_reply":"2024-03-12T03:18:57.462484Z"},"trusted":true},"execution_count":null,"outputs":[]}]}