{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":59093,"databundleVersionId":7469972,"sourceType":"competition"}],"dockerImageVersionId":30919,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.076203Z","iopub.execute_input":"2025-04-05T11:32:29.076624Z","iopub.status.idle":"2025-04-05T11:32:29.080867Z","shell.execute_reply.started":"2025-04-05T11:32:29.076589Z","shell.execute_reply":"2025-04-05T11:32:29.079787Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"BASE_PATH = \"/kaggle/input/hms-harmful-brain-activity-classification\"\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.081977Z","iopub.execute_input":"2025-04-05T11:32:29.082259Z","iopub.status.idle":"2025-04-05T11:32:29.096534Z","shell.execute_reply.started":"2025-04-05T11:32:29.082230Z","shell.execute_reply":"2025-04-05T11:32:29.095510Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.listdir(\"/kaggle/input/\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.098580Z","iopub.execute_input":"2025-04-05T11:32:29.098778Z","iopub.status.idle":"2025-04-05T11:32:29.111185Z","shell.execute_reply.started":"2025-04-05T11:32:29.098760Z","shell.execute_reply":"2025-04-05T11:32:29.110236Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.listdir(\"/kaggle/input/hms-harmful-brain-activity-classification\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.112660Z","iopub.execute_input":"2025-04-05T11:32:29.113000Z","iopub.status.idle":"2025-04-05T11:32:29.127838Z","shell.execute_reply.started":"2025-04-05T11:32:29.112967Z","shell.execute_reply":"2025-04-05T11:32:29.126799Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"eeg_path = BASE_PATH+\"/\"+\"train_eegs\"\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.128603Z","iopub.execute_input":"2025-04-05T11:32:29.128818Z","iopub.status.idle":"2025-04-05T11:32:29.134119Z","shell.execute_reply.started":"2025-04-05T11:32:29.128798Z","shell.execute_reply":"2025-04-05T11:32:29.133306Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.listdir(eeg_path)[:10]\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.135044Z","iopub.execute_input":"2025-04-05T11:32:29.135311Z","iopub.status.idle":"2025-04-05T11:32:29.154002Z","shell.execute_reply.started":"2025-04-05T11:32:29.135291Z","shell.execute_reply":"2025-04-05T11:32:29.153246Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.154747Z","iopub.execute_input":"2025-04-05T11:32:29.154986Z","iopub.status.idle":"2025-04-05T11:32:29.158469Z","shell.execute_reply.started":"2025-04-05T11:32:29.154965Z","shell.execute_reply":"2025-04-05T11:32:29.157689Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pd.read_parquet(eeg_path+\"/\"+os.listdir(eeg_path)[0])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.159347Z","iopub.execute_input":"2025-04-05T11:32:29.159574Z","iopub.status.idle":"2025-04-05T11:32:29.198443Z","shell.execute_reply.started":"2025-04-05T11:32:29.159555Z","shell.execute_reply":"2025-04-05T11:32:29.197637Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv(BASE_PATH+\"/train.csv\")\nprint('Train shape', train.shape )\ndisplay( train.head() )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.200915Z","iopub.execute_input":"2025-04-05T11:32:29.201201Z","iopub.status.idle":"2025-04-05T11:32:29.340573Z","shell.execute_reply.started":"2025-04-05T11:32:29.201179Z","shell.execute_reply":"2025-04-05T11:32:29.339690Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pywt\nprint(\"The wavelet functions we can use:\")\nprint(pywt.wavelist())\n\nUSE_WAVELET = None #or \"db8\" or anything below","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.342647Z","iopub.execute_input":"2025-04-05T11:32:29.342907Z","iopub.status.idle":"2025-04-05T11:32:29.347790Z","shell.execute_reply.started":"2025-04-05T11:32:29.342868Z","shell.execute_reply":"2025-04-05T11:32:29.347015Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# DENOISE FUNCTION\ndef maddest(d, axis=None):\n    return np.mean(np.absolute(d - np.mean(d, axis)), axis)\n\ndef denoise(x, wavelet='haar', level=1):    \n    coeff = pywt.wavedec(x, wavelet, mode=\"per\")\n    sigma = (1/0.6745) * maddest(coeff[-level])\n\n    uthresh = sigma * np.sqrt(2*np.log(len(x)))\n    coeff[1:] = (pywt.threshold(i, value=uthresh, mode='hard') for i in coeff[1:])\n\n    ret=pywt.waverec(coeff, wavelet, mode='per')\n    \n    return ret","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.349048Z","iopub.execute_input":"2025-04-05T11:32:29.349365Z","iopub.status.idle":"2025-04-05T11:32:29.363853Z","shell.execute_reply.started":"2025-04-05T11:32:29.349337Z","shell.execute_reply":"2025-04-05T11:32:29.362863Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import librosa\nimport numpy as np","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.364773Z","iopub.execute_input":"2025-04-05T11:32:29.365108Z","iopub.status.idle":"2025-04-05T11:32:29.377729Z","shell.execute_reply.started":"2025-04-05T11:32:29.365077Z","shell.execute_reply":"2025-04-05T11:32:29.376936Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def spectrogram_from_eeg(parquet_path, display=False):\n    parquet_path = BASE_PATH+\"/train_eegs/\"+str(parquet_path)+\".parquet\"\n    # LOAD MIDDLE 50 SECONDS OF EEG SERIES\n    eeg = pd.read_parquet(parquet_path)\n    middle = (len(eeg)-10_000)//2\n    eeg = eeg.iloc[middle:middle+10_000]\n    \n    # VARIABLE TO HOLD SPECTROGRAM\n    img = np.zeros((128,256,4),dtype='float32')\n    \n    if display: plt.figure(figsize=(10,7))\n    signals = []\n    for k in range(4):\n        COLS = FEATS[k]\n        \n        for kk in range(4):\n        \n            # COMPUTE PAIR DIFFERENCES\n            x = eeg[COLS[kk]].values - eeg[COLS[kk+1]].values\n\n            # FILL NANS\n            m = np.nanmean(x)\n            if np.isnan(x).mean()<1: x = np.nan_to_num(x,nan=m)\n            else: x[:] = 0\n\n            # DENOISE\n            if USE_WAVELET:\n                x = denoise(x, wavelet=USE_WAVELET)\n            signals.append(x)\n\n            # RAW SPECTROGRAM\n            mel_spec = librosa.feature.melspectrogram(y=x, sr=200, hop_length=len(x)//256, \n                  n_fft=1024, n_mels=128, fmin=0, fmax=20, win_length=128)\n\n            # LOG TRANSFORM\n            width = (mel_spec.shape[1]//32)*32\n            mel_spec_db = librosa.power_to_db(mel_spec, ref=np.max).astype(np.float32)[:,:width]\n\n            # STANDARDIZE TO -1 TO 1\n            mel_spec_db = (mel_spec_db+40)/40 \n            img[:,:,k] += mel_spec_db\n                \n        # AVERAGE THE 4 MONTAGE DIFFERENCES\n        img[:,:,k] /= 4.0\n        \n        if display:\n            plt.subplot(2,2,k+1)\n            plt.imshow(img[:,:,k],aspect='auto',origin='lower')\n            plt.title(f'EEG {eeg_id} - Spectrogram {NAMES[k]}')\n            \n    if display: \n        plt.show()\n        plt.figure(figsize=(10,5))\n        offset = 0\n        for k in range(4):\n            if k>0: offset -= signals[3-k].min()\n            plt.plot(range(10_000),signals[k]+offset,label=NAMES[3-k])\n            offset += signals[3-k].max()\n        plt.legend()\n        plt.title(f'EEG {eeg_id} Signals')\n        plt.show()\n        print(); print('#'*25); print()\n        \n    return img","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.378548Z","iopub.execute_input":"2025-04-05T11:32:29.378784Z","iopub.status.idle":"2025-04-05T11:32:29.389316Z","shell.execute_reply.started":"2025-04-05T11:32:29.378765Z","shell.execute_reply":"2025-04-05T11:32:29.388536Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"NAMES = ['LL','LP','RP','RR']\n\nFEATS = [['Fp1','F7','T3','T5','O1'],\n         ['Fp1','F3','C3','P3','O1'],\n         ['Fp2','F8','T4','T6','O2'],\n         ['Fp2','F4','C4','P4','O2']]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.390088Z","iopub.execute_input":"2025-04-05T11:32:29.390343Z","iopub.status.idle":"2025-04-05T11:32:29.406879Z","shell.execute_reply.started":"2025-04-05T11:32:29.390319Z","shell.execute_reply":"2025-04-05T11:32:29.405984Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"csv = pd.read_csv(BASE_PATH+\"/train.csv\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.407810Z","iopub.execute_input":"2025-04-05T11:32:29.408144Z","iopub.status.idle":"2025-04-05T11:32:29.528221Z","shell.execute_reply.started":"2025-04-05T11:32:29.408113Z","shell.execute_reply":"2025-04-05T11:32:29.527364Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"unique_eeg_ids_df = csv.drop_duplicates(subset='eeg_id')\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.529015Z","iopub.execute_input":"2025-04-05T11:32:29.529325Z","iopub.status.idle":"2025-04-05T11:32:29.536708Z","shell.execute_reply.started":"2025-04-05T11:32:29.529295Z","shell.execute_reply":"2025-04-05T11:32:29.535897Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"unique_eeg_ids_df = unique_eeg_ids_df[['eeg_id', 'expert_consensus']]\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.537802Z","iopub.execute_input":"2025-04-05T11:32:29.538120Z","iopub.status.idle":"2025-04-05T11:32:29.548533Z","shell.execute_reply.started":"2025-04-05T11:32:29.538088Z","shell.execute_reply":"2025-04-05T11:32:29.547651Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"unique_values = unique_eeg_ids_df['expert_consensus'].unique()\nprint(unique_values)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.549435Z","iopub.execute_input":"2025-04-05T11:32:29.549717Z","iopub.status.idle":"2025-04-05T11:32:29.563707Z","shell.execute_reply.started":"2025-04-05T11:32:29.549687Z","shell.execute_reply":"2025-04-05T11:32:29.562966Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labels = {0:\"Seizure\",1:\"GPD\",2:\"LRDA\",3:\"LPD\",4:\"GRDA\",5:\"Other\"}\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.564442Z","iopub.execute_input":"2025-04-05T11:32:29.564654Z","iopub.status.idle":"2025-04-05T11:32:29.575400Z","shell.execute_reply.started":"2025-04-05T11:32:29.564634Z","shell.execute_reply":"2025-04-05T11:32:29.574602Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras import layers, models\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.576330Z","iopub.execute_input":"2025-04-05T11:32:29.576861Z","iopub.status.idle":"2025-04-05T11:32:29.588196Z","shell.execute_reply.started":"2025-04-05T11:32:29.576831Z","shell.execute_reply":"2025-04-05T11:32:29.587280Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras import models, layers\n\nmodel = models.Sequential([\n    layers.Conv3D(64, (3, 3, 3), activation='relu', padding='same', input_shape=(128, 256, 4, 1)),\n    layers.BatchNormalization(),\n    layers.Conv3D(64, (3, 3, 3), activation='relu', padding='same'),\n    layers.MaxPooling3D((2, 2, 1)),\n\n    layers.Conv3D(128, (3, 3, 3), activation='relu', padding='same'),\n    layers.BatchNormalization(),\n    layers.Conv3D(128, (3, 3, 3), activation='relu', padding='same'),\n    layers.MaxPooling3D((2, 2, 1)),\n\n    layers.Conv3D(256, (3, 3, 3), activation='relu', padding='same'),\n    layers.BatchNormalization(),\n    layers.Conv3D(256, (3, 3, 3), activation='relu', padding='same'),\n\n    layers.GlobalAveragePooling3D(),\n\n    layers.Dense(1024, activation='relu'),\n    layers.Dropout(0.5),\n    layers.Dense(512, activation='relu'),\n    layers.Dropout(0.3),\n    layers.Dense(6, activation='softmax')\n])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.589161Z","iopub.execute_input":"2025-04-05T11:32:29.589433Z","iopub.status.idle":"2025-04-05T11:32:29.713400Z","shell.execute_reply.started":"2025-04-05T11:32:29.589408Z","shell.execute_reply":"2025-04-05T11:32:29.712420Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Invert the labels dictionary to map string labels to their numeric values\nlabel_map = {v: k for k, v in labels.items()}\n\n# Replace the string values in the expert_consensus column with their numeric values\nunique_eeg_ids_df['expert_consensus'] = unique_eeg_ids_df['expert_consensus'].map(label_map)\nunique_eeg_ids_df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.714235Z","iopub.execute_input":"2025-04-05T11:32:29.714518Z","iopub.status.idle":"2025-04-05T11:32:29.725655Z","shell.execute_reply.started":"2025-04-05T11:32:29.714481Z","shell.execute_reply":"2025-04-05T11:32:29.724891Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.726513Z","iopub.execute_input":"2025-04-05T11:32:29.726786Z","iopub.status.idle":"2025-04-05T11:32:29.741624Z","shell.execute_reply.started":"2025-04-05T11:32:29.726760Z","shell.execute_reply":"2025-04-05T11:32:29.740748Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Önce eğitim ve geri kalan verileri (validasyon + test) ayıralım\ntrain_df, rest_df = train_test_split(unique_eeg_ids_df, test_size=0.2, random_state=42) # %30 test + validasyon\n\n# Geri kalan verileri validasyon ve test olarak ayıralım\nval_df, test_df = train_test_split(rest_df, test_size=1/2, random_state=42) # %30'un 1/3'ü test, 2/3'ü validasyon","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.742602Z","iopub.execute_input":"2025-04-05T11:32:29.742873Z","iopub.status.idle":"2025-04-05T11:32:29.760160Z","shell.execute_reply.started":"2025-04-05T11:32:29.742847Z","shell.execute_reply":"2025-04-05T11:32:29.759324Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import keras.utils\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.760992Z","iopub.execute_input":"2025-04-05T11:32:29.761325Z","iopub.status.idle":"2025-04-05T11:32:29.766970Z","shell.execute_reply.started":"2025-04-05T11:32:29.761295Z","shell.execute_reply":"2025-04-05T11:32:29.766137Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class EEGDataGenerator(keras.utils.Sequence):\n    \"\"\"\n    Data generator for EEG spectrograms for Keras.\n    Converts EEG IDs to spectrograms using the provided function and returns batches.\n    \"\"\"\n    \n    def __init__(self, dataframe, spectrogram_function, batch_size=32, \n                 shuffle=True, seed=None, is_test=False):\n        \"\"\"\n        Initialize the data generator.\n        \n        Args:\n            dataframe (pd.DataFrame): DataFrame containing 'eeg_id' and 'expert_consensus' columns\n            spectrogram_function (callable): Function that converts eeg_id to spectrogram array\n            batch_size (int): Size of batches to generate\n            shuffle (bool): Whether to shuffle the data after each epoch\n            seed (int): Random seed for reproducibility\n            is_test (bool): If True, don't return labels (for prediction)\n        \"\"\"\n        self.df = dataframe.copy()\n        self.batch_size = batch_size\n        self.spectrogram_function = spectrogram_function\n        self.shuffle = shuffle\n        self.seed = seed\n        self.is_test = is_test\n        \n        # Generate indices\n        self.indices = np.arange(len(self.df))\n        \n        # Class mapping if needed\n        self.classes = sorted(self.df['expert_consensus'].unique())\n        self.class_indices = {cls: i for i, cls in enumerate(self.classes)}\n        \n        # Initial shuffle\n        if self.shuffle:\n            np.random.seed(self.seed)\n            np.random.shuffle(self.indices)\n    \n    def __len__(self):\n        \"\"\"Denotes the number of batches per epoch\"\"\"\n        return int(np.ceil(len(self.df) / self.batch_size))\n    \n    def __getitem__(self, index):\n        \"\"\"Generate one batch of data\"\"\"\n        # Generate indices of the batch\n        batch_indices = self.indices[index * self.batch_size:(index + 1) * self.batch_size]\n        \n        # Get batch data\n        batch_df = self.df.iloc[batch_indices]\n        \n        # Generate spectrograms\n        batch_x = np.array([\n            self.spectrogram_function(eeg_id) \n            for eeg_id in batch_df['eeg_id']\n        ])\n        \n        if self.is_test:\n            return batch_x\n        \n        # Generate labels (one-hot encoded)\n        batch_y = np.array([\n            self.class_indices[label] \n            for label in batch_df['expert_consensus']\n        ])\n        \n        return batch_x, tf.keras.utils.to_categorical(batch_y, num_classes=len(self.classes))\n    \n    def on_epoch_end(self):\n        \"\"\"Updates indices after each epoch\"\"\"\n        if self.shuffle:\n            np.random.seed(self.seed)\n            np.random.shuffle(self.indices)\n\n\ndef create_eeg_generators(train_df, val_df, test_df, spectrogram_from_eeg, \n                          batch_size=32, seed=42):\n    \"\"\"\n    Create train, validation, and test generators for EEG data.\n    \n    Args:\n        train_df (pd.DataFrame): Training data with 'eeg_id' and 'expert_consensus' columns\n        val_df (pd.DataFrame): Validation data with 'eeg_id' and 'expert_consensus' columns\n        test_df (pd.DataFrame): Test data with 'eeg_id' column\n        spectrogram_from_eeg (callable): Function to convert eeg_id to spectrogram\n        batch_size (int): Batch size for generators\n        seed (int): Random seed for reproducibility\n        \n    Returns:\n        tuple: (train_generator, val_generator, test_generator)\n    \"\"\"\n    # Create generators\n    train_generator = EEGDataGenerator(\n        dataframe=train_df,\n        spectrogram_function=spectrogram_from_eeg,\n        batch_size=batch_size,\n        shuffle=True,\n        seed=seed,\n        is_test=False\n    )\n    \n    val_generator = EEGDataGenerator(\n        dataframe=val_df,\n        spectrogram_function=spectrogram_from_eeg,\n        batch_size=batch_size,\n        shuffle=False,\n        seed=seed,\n        is_test=False\n    )\n    \n    test_generator = EEGDataGenerator(\n        dataframe=test_df,\n        spectrogram_function=spectrogram_from_eeg,\n        batch_size=batch_size,\n        shuffle=False,\n        seed=seed,\n        is_test=True\n    )\n    \n    return train_generator, val_generator, test_generator","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.767843Z","iopub.execute_input":"2025-04-05T11:32:29.768144Z","iopub.status.idle":"2025-04-05T11:32:29.783020Z","shell.execute_reply.started":"2025-04-05T11:32:29.768115Z","shell.execute_reply":"2025-04-05T11:32:29.782284Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"BATCH_SIZE = 16\nLEARNING_RATE = 0.001","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.787090Z","iopub.execute_input":"2025-04-05T11:32:29.787363Z","iopub.status.idle":"2025-04-05T11:32:29.798537Z","shell.execute_reply.started":"2025-04-05T11:32:29.787337Z","shell.execute_reply":"2025-04-05T11:32:29.797778Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_generator, val_generator, test_generator = create_eeg_generators(train_df, val_df, test_df, spectrogram_from_eeg, \n                          batch_size=BATCH_SIZE, seed=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.799752Z","iopub.execute_input":"2025-04-05T11:32:29.800119Z","iopub.status.idle":"2025-04-05T11:32:29.814109Z","shell.execute_reply.started":"2025-04-05T11:32:29.800087Z","shell.execute_reply":"2025-04-05T11:32:29.813237Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from tensorflow.keras.optimizers import Adam\n\noptimizer = Adam(learning_rate=LEARNING_RATE)\n\nmodel.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.814981Z","iopub.execute_input":"2025-04-05T11:32:29.815317Z","iopub.status.idle":"2025-04-05T11:32:29.830640Z","shell.execute_reply.started":"2025-04-05T11:32:29.815287Z","shell.execute_reply":"2025-04-05T11:32:29.829807Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.summary()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.831549Z","iopub.execute_input":"2025-04-05T11:32:29.831888Z","iopub.status.idle":"2025-04-05T11:32:29.860444Z","shell.execute_reply.started":"2025-04-05T11:32:29.831856Z","shell.execute_reply":"2025-04-05T11:32:29.859653Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tensorflow as tf\nprint(\"GPU Available:\", tf.config.list_physical_devices('GPU'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.861676Z","iopub.execute_input":"2025-04-05T11:32:29.861982Z","iopub.status.idle":"2025-04-05T11:32:29.866844Z","shell.execute_reply.started":"2025-04-05T11:32:29.861951Z","shell.execute_reply":"2025-04-05T11:32:29.866099Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Model eğitimine başlanıyor.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.867636Z","iopub.execute_input":"2025-04-05T11:32:29.867901Z","iopub.status.idle":"2025-04-05T11:32:29.881409Z","shell.execute_reply.started":"2025-04-05T11:32:29.867848Z","shell.execute_reply":"2025-04-05T11:32:29.880371Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Train the model\nhistory = model.fit(\n    train_generator,\n    validation_data=val_generator,\n    epochs=10\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-05T11:32:29.882393Z","iopub.execute_input":"2025-04-05T11:32:29.882634Z","execution_failed":"2025-04-05T11:35:37.563Z"}},"outputs":[],"execution_count":null}]}