{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.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":13836,"databundleVersionId":1718836,"sourceType":"competition"}],"dockerImageVersionId":31236,"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\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\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","trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:39:06.203891Z","iopub.execute_input":"2025-12-24T16:39:06.204198Z","iopub.status.idle":"2025-12-24T16:39:29.387270Z","shell.execute_reply.started":"2025-12-24T16:39:06.204172Z","shell.execute_reply":"2025-12-24T16:39:29.386251Z"},"collapsed":true,"jupyter":{"outputs_hidden":true}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt \nimport seaborn as sns \nimport cv2 \n\nimport json","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:39:34.509878Z","iopub.execute_input":"2025-12-24T16:39:34.510777Z","iopub.status.idle":"2025-12-24T16:39:36.334983Z","shell.execute_reply.started":"2025-12-24T16:39:34.510745Z","shell.execute_reply":"2025-12-24T16:39:36.334422Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"base_dir = '/kaggle/input/cassava-leaf-disease-classification'\n\nwith open(os.path.join(base_dir, 'label_num_to_disease_map.json')) as file:\n    map_classes = json.loads(file.read())\n    map_classes = {int(k): v for k,v in map_classes.items()}\n\n\nprint('class_mapping')\nprint(json.dumps(map_classes, indent=1))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:39:36.336168Z","iopub.execute_input":"2025-12-24T16:39:36.336623Z","iopub.status.idle":"2025-12-24T16:39:36.346058Z","shell.execute_reply.started":"2025-12-24T16:39:36.336598Z","shell.execute_reply":"2025-12-24T16:39:36.345328Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train = pd.read_csv('/kaggle/input/cassava-leaf-disease-classification/train.csv')\ndf_train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:39:46.382080Z","iopub.execute_input":"2025-12-24T16:39:46.382338Z","iopub.status.idle":"2025-12-24T16:39:46.439037Z","shell.execute_reply.started":"2025-12-24T16:39:46.382317Z","shell.execute_reply":"2025-12-24T16:39:46.438418Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train['class_name'] = df_train['label'].map(map_classes)\ndf_train.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:39:46.879066Z","iopub.execute_input":"2025-12-24T16:39:46.879590Z","iopub.status.idle":"2025-12-24T16:39:46.892160Z","shell.execute_reply.started":"2025-12-24T16:39:46.879564Z","shell.execute_reply":"2025-12-24T16:39:46.891651Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_train['class_name'].value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:39:49.801534Z","iopub.execute_input":"2025-12-24T16:39:49.802213Z","iopub.status.idle":"2025-12-24T16:39:49.813996Z","shell.execute_reply.started":"2025-12-24T16:39:49.802187Z","shell.execute_reply":"2025-12-24T16:39:49.813325Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"clearly imbalanced dataset hai ","metadata":{}},{"cell_type":"code","source":"train_path = '/kaggle/input/cassava-leaf-disease-classification/train_images'","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:39:50.770759Z","iopub.execute_input":"2025-12-24T16:39:50.771055Z","iopub.status.idle":"2025-12-24T16:39:50.774724Z","shell.execute_reply.started":"2025-12-24T16:39:50.771027Z","shell.execute_reply":"2025-12-24T16:39:50.774028Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras\nfrom keras import Sequential, layers","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:39:51.350439Z","iopub.execute_input":"2025-12-24T16:39:51.350730Z","iopub.status.idle":"2025-12-24T16:40:04.633260Z","shell.execute_reply.started":"2025-12-24T16:39:51.350707Z","shell.execute_reply":"2025-12-24T16:40:04.632668Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nvalidation_split = .2\n\ntrain_df, val_df = train_test_split(\n    df_train, \n    test_size=validation_split,\n    stratify = df_train['label'],\n    random_state=2\n)\n\nprint(f'train_shape: {train_df.shape}')\nprint(f'val_shape: {val_df.shape}')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:40:04.634381Z","iopub.execute_input":"2025-12-24T16:40:04.634887Z","iopub.status.idle":"2025-12-24T16:40:04.763176Z","shell.execute_reply.started":"2025-12-24T16:40:04.634863Z","shell.execute_reply":"2025-12-24T16:40:04.762499Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def process_image(file_name, label):\n    file_path = tf.strings.join([train_path, '/', file_name])\n    image = tf.io.read_file(file_path)\n    image = tf.image.decode_jpeg(image, channels=3)\n    image = tf.image.resize(image, [224,224])\n    return image, label","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:40:16.711044Z","iopub.execute_input":"2025-12-24T16:40:16.711840Z","iopub.status.idle":"2025-12-24T16:40:16.716200Z","shell.execute_reply.started":"2025-12-24T16:40:16.711810Z","shell.execute_reply":"2025-12-24T16:40:16.715419Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"buffer_size=1000\ntrain_ds = tf.data.Dataset.from_tensor_slices((train_df['image_id'].values,\n                                             train_df['label'].values))\n\ntrain_ds = train_ds.map(process_image, num_parallel_calls=tf.data.AUTOTUNE)\n\ntrain_ds = train_ds.shuffle(buffer_size).batch(32).prefetch(tf.data.AUTOTUNE)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:40:17.177408Z","iopub.execute_input":"2025-12-24T16:40:17.178143Z","iopub.status.idle":"2025-12-24T16:40:17.975600Z","shell.execute_reply.started":"2025-12-24T16:40:17.178115Z","shell.execute_reply":"2025-12-24T16:40:17.974778Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_ds = tf.data.Dataset.from_tensor_slices((val_df['image_id'].values, \n                                             val_df['label'].values))\n\nval_ds = val_ds.map(process_image, num_parallel_calls=tf.data.AUTOTUNE)\n\nval_ds = val_ds.batch(32).prefetch(tf.data.AUTOTUNE)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:40:17.976833Z","iopub.execute_input":"2025-12-24T16:40:17.977080Z","iopub.status.idle":"2025-12-24T16:40:17.996861Z","shell.execute_reply.started":"2025-12-24T16:40:17.977059Z","shell.execute_reply":"2025-12-24T16:40:17.996135Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = Sequential()\n\nmodel.add(layers.Input(shape=(224,224,3)))\n\nmodel.add(layers.Rescaling(1/255.))\nmodel.add(layers.RandomZoom(0.1))\nmodel.add(layers.RandomFlip('horizontal'))\nmodel.add(layers.RandomShear(.1))\n\nmodel.add(layers.Conv2D(64, (3,3), activation='relu'))\nmodel.add(layers.Conv2D(64, (3,3), activation='relu'))\nmodel.add(layers.MaxPool2D())\n\nmodel.add(layers.Conv2D(128, (3,3), activation='relu'))\nmodel.add(layers.Conv2D(128, (3,3), activation='relu'))\nmodel.add(layers.MaxPool2D())\n\nmodel.add(layers.Conv2D(256, (3,3), activation='relu'))\nmodel.add(layers.Conv2D(256, (3,3), activation='relu'))\nmodel.add(layers.MaxPool2D())\n\nmodel.add(layers.Flatten())\n\nmodel.add(layers.Dense(64, activation='relu'))\nmodel.add(layers.Dense(128, activation='relu'))\nmodel.add(layers.Dense(256, activation='relu'))\nmodel.add(layers.Dense(64, activation='relu'))\nmodel.add(layers.Dense(5, activation='softmax'))\n\nmodel.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:40:22.686251Z","iopub.execute_input":"2025-12-24T16:40:22.686876Z","iopub.status.idle":"2025-12-24T16:40:24.216560Z","shell.execute_reply.started":"2025-12-24T16:40:22.686847Z","shell.execute_reply":"2025-12-24T16:40:24.215864Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:40:24.655353Z","iopub.execute_input":"2025-12-24T16:40:24.655710Z","iopub.status.idle":"2025-12-24T16:40:24.668987Z","shell.execute_reply.started":"2025-12-24T16:40:24.655683Z","shell.execute_reply":"2025-12-24T16:40:24.668297Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"checkpoint = tf.keras.callbacks.ModelCheckpoint(\n    'best_model_in_custom_cnn.keras',\n    monitor='val_accuracy',\n    save_best_only=True,\n    verbose=1\n)\n\ncallbacks=[checkpoint]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:40:25.135083Z","iopub.execute_input":"2025-12-24T16:40:25.135833Z","iopub.status.idle":"2025-12-24T16:40:25.139943Z","shell.execute_reply.started":"2025-12-24T16:40:25.135797Z","shell.execute_reply":"2025-12-24T16:40:25.139170Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"history = model.fit(train_ds, validation_data=val_ds, epochs=10, callbacks=callbacks)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:40:31.040923Z","iopub.execute_input":"2025-12-24T16:40:31.041695Z","iopub.status.idle":"2025-12-24T16:55:17.587937Z","shell.execute_reply.started":"2025-12-24T16:40:31.041660Z","shell.execute_reply":"2025-12-24T16:55:17.587300Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.plot(history.history['accuracy'], label='accuracy')\nplt.plot(history.history['val_accuracy'], label='val accuracy')\n\nplt.plot(history.history['loss'], label='loss')\nplt.plot(history.history['val_loss'], label='val loss')\nplt.legend()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:55:32.104159Z","iopub.execute_input":"2025-12-24T16:55:32.104471Z","iopub.status.idle":"2025-12-24T16:55:32.290160Z","shell.execute_reply.started":"2025-12-24T16:55:32.104444Z","shell.execute_reply":"2025-12-24T16:55:32.289476Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Transfer Learning ","metadata":{}},{"cell_type":"code","source":"base_model = tf.keras.applications.EfficientNetB0(\n    include_top=False,\n    weights='imagenet',\n    input_shape=(224,224,3)\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:55:44.909939Z","iopub.execute_input":"2025-12-24T16:55:44.910629Z","iopub.status.idle":"2025-12-24T16:55:47.960117Z","shell.execute_reply.started":"2025-12-24T16:55:44.910595Z","shell.execute_reply":"2025-12-24T16:55:47.959463Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"base_model.trainable = False","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:55:50.830695Z","iopub.execute_input":"2025-12-24T16:55:50.831502Z","iopub.status.idle":"2025-12-24T16:55:50.837392Z","shell.execute_reply.started":"2025-12-24T16:55:50.831471Z","shell.execute_reply":"2025-12-24T16:55:50.836621Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = Sequential([\n    layers.Input(shape=(224,224,3)),\n    layers.Lambda(tf.keras.applications.efficientnet.preprocess_input),\n\n\n    layers.RandomZoom(0.1),\n    layers.RandomFlip('horizontal'),\n    layers.RandomShear(.1),\n\n    base_model,\n\n    layers.GlobalAveragePooling2D(),\n    layers.Dense(64, activation='relu'),\n    layers.Dense(128, activation='relu'),\n    layers.Dense(256, activation='relu'),\n    layers.Dropout(.2),\n    layers.Dense(64, activation='relu'),\n    layers.Dense(5, activation='softmax'),\n])\n\nmodel.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:55:51.546970Z","iopub.execute_input":"2025-12-24T16:55:51.547258Z","iopub.status.idle":"2025-12-24T16:55:51.618465Z","shell.execute_reply.started":"2025-12-24T16:55:51.547233Z","shell.execute_reply":"2025-12-24T16:55:51.617778Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.compile(optimizer='adam', \n              loss='sparse_categorical_crossentropy', \n              metrics=['accuracy'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:55:56.021294Z","iopub.execute_input":"2025-12-24T16:55:56.022069Z","iopub.status.idle":"2025-12-24T16:55:56.030340Z","shell.execute_reply.started":"2025-12-24T16:55:56.022037Z","shell.execute_reply":"2025-12-24T16:55:56.029703Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"checkpoint = tf.keras.callbacks.ModelCheckpoint(\n    'best_model_in_transfer_learning.keras',\n    monitor='val_accuracy',\n    save_best_only=True,\n    verbose=1\n)\n\ncallbacks=[checkpoint]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:55:58.328397Z","iopub.execute_input":"2025-12-24T16:55:58.329134Z","iopub.status.idle":"2025-12-24T16:55:58.332651Z","shell.execute_reply.started":"2025-12-24T16:55:58.329106Z","shell.execute_reply":"2025-12-24T16:55:58.331882Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"history = model.fit(train_ds, validation_data=val_ds, epochs=15, callbacks=callbacks)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T16:55:59.344017Z","iopub.execute_input":"2025-12-24T16:55:59.344716Z","iopub.status.idle":"2025-12-24T17:06:11.423805Z","shell.execute_reply.started":"2025-12-24T16:55:59.344687Z","shell.execute_reply":"2025-12-24T17:06:11.423164Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.plot(history.history['accuracy'], label='accuracy')\nplt.plot(history.history['val_accuracy'], label='val accuracy')\n\nplt.plot(history.history['loss'], label='loss')\nplt.plot(history.history['val_loss'], label='val loss')\nplt.legend()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T17:06:11.425107Z","iopub.execute_input":"2025-12-24T17:06:11.425422Z","iopub.status.idle":"2025-12-24T17:06:11.578407Z","shell.execute_reply.started":"2025-12-24T17:06:11.425386Z","shell.execute_reply":"2025-12-24T17:06:11.577736Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# FIne tuning krna pdega","metadata":{}},{"cell_type":"code","source":"base_model = tf.keras.applications.EfficientNetB0(\n    include_top=False,\n    weights='imagenet',\n    input_shape=(224,224,3)\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T17:35:47.748072Z","iopub.execute_input":"2025-12-24T17:35:47.748572Z","iopub.status.idle":"2025-12-24T17:35:48.669106Z","shell.execute_reply.started":"2025-12-24T17:35:47.748544Z","shell.execute_reply":"2025-12-24T17:35:48.668511Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for layer in base_model.layers[:-3]:\n    layer.trainable = False\n\nfor layer in base_model.layers[-3:]:\n    layer.trainable = True\n\nmodel = Sequential([\n    layers.Input(shape=(224,224,3)),\n    layers.Lambda(tf.keras.applications.efficientnet.preprocess_input),\n\n\n    layers.RandomZoom(0.1),\n    layers.RandomFlip('horizontal'),\n    layers.RandomShear(.1),\n\n    base_model,\n\n    layers.GlobalAveragePooling2D(),\n    layers.Dense(64, activation='relu'),\n    layers.BatchNormalization(),\n    layers.Dropout(.2),\n    layers.Dense(128, activation='relu'),\n    layers.BatchNormalization(),\n    layers.Dropout(.2),\n    layers.Dense(256, activation='relu'),\n    layers.BatchNormalization(),\n    layers.Dropout(.2),\n    layers.Dense(64, activation='relu'),\n    layers.Dense(5, activation='softmax'),\n])\n\nmodel.summary()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T17:36:18.299926Z","iopub.execute_input":"2025-12-24T17:36:18.300208Z","iopub.status.idle":"2025-12-24T17:36:18.398134Z","shell.execute_reply.started":"2025-12-24T17:36:18.300184Z","shell.execute_reply":"2025-12-24T17:36:18.397601Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.compile(optimizer='rmsprop', \n              loss='sparse_categorical_crossentropy', \n              metrics=['accuracy'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T17:36:24.252952Z","iopub.execute_input":"2025-12-24T17:36:24.253954Z","iopub.status.idle":"2025-12-24T17:36:24.263061Z","shell.execute_reply.started":"2025-12-24T17:36:24.253925Z","shell.execute_reply":"2025-12-24T17:36:24.262451Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"checkpoint = tf.keras.callbacks.ModelCheckpoint(\n    'best_fine_tuned_model.keras',\n    monitor='val_accuracy',\n    save_best_only=True,\n    verbose=1\n)\n\ncallbacks=[checkpoint]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T17:36:28.878996Z","iopub.execute_input":"2025-12-24T17:36:28.879352Z","iopub.status.idle":"2025-12-24T17:36:28.885659Z","shell.execute_reply.started":"2025-12-24T17:36:28.879311Z","shell.execute_reply":"2025-12-24T17:36:28.884882Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"history = model.fit(train_ds, validation_data=val_ds, epochs=15, callbacks=callbacks)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T17:36:30.490917Z","iopub.execute_input":"2025-12-24T17:36:30.491203Z","iopub.status.idle":"2025-12-24T17:47:02.671292Z","shell.execute_reply.started":"2025-12-24T17:36:30.491179Z","shell.execute_reply":"2025-12-24T17:47:02.670546Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.plot(history.history['accuracy'], label='accuracy')\nplt.plot(history.history['val_accuracy'], label='val accuracy')\n\nplt.plot(history.history['loss'], label='loss')\nplt.plot(history.history['val_loss'], label='val loss')\nplt.legend()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T17:53:50.879317Z","iopub.execute_input":"2025-12-24T17:53:50.879923Z","iopub.status.idle":"2025-12-24T17:53:51.034340Z","shell.execute_reply.started":"2025-12-24T17:53:50.879891Z","shell.execute_reply":"2025-12-24T17:53:51.033430Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample = pd.read_csv('/kaggle/input/cassava-leaf-disease-classification/sample_submission.csv')\nsample.head(10)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T18:27:41.209880Z","iopub.execute_input":"2025-12-24T18:27:41.210641Z","iopub.status.idle":"2025-12-24T18:27:41.219203Z","shell.execute_reply.started":"2025-12-24T18:27:41.210611Z","shell.execute_reply":"2025-12-24T18:27:41.218622Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def parse_test_tfrecord(example):\n    feature_description = {\n        'image': tf.io.FixedLenFeature([], tf.string),\n    }\n\n    example = tf.io.parse_single_example(example, feature_description)\n\n    image = tf.io.decode_jpeg(example['image'], channels=3)\n    image = tf.image.resize(image, [224, 224])\n\n    return image\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T18:37:28.649532Z","iopub.execute_input":"2025-12-24T18:37:28.650141Z","iopub.status.idle":"2025-12-24T18:37:28.654310Z","shell.execute_reply.started":"2025-12-24T18:37:28.650116Z","shell.execute_reply":"2025-12-24T18:37:28.653554Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import glob\n\ntest_tfrecords = glob.glob(\n    \"/kaggle/input/cassava-leaf-disease-classification/test_tfrecords/*.tfrec\"\n)\n\ntest_ds = tf.data.TFRecordDataset(test_tfrecords)\ntest_ds = test_ds.map(parse_test_tfrecord, num_parallel_calls=tf.data.AUTOTUNE)\ntest_ds = test_ds.batch(32).prefetch(tf.data.AUTOTUNE)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T18:38:00.350532Z","iopub.execute_input":"2025-12-24T18:38:00.350838Z","iopub.status.idle":"2025-12-24T18:38:00.379633Z","shell.execute_reply.started":"2025-12-24T18:38:00.350804Z","shell.execute_reply":"2025-12-24T18:38:00.379077Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions = []\n\nfor images in test_ds:\n    preds = model.predict(images)\n    labels = np.argmax(preds, axis=1)\n    predictions.extend(labels)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T18:38:15.238597Z","iopub.execute_input":"2025-12-24T18:38:15.238923Z","iopub.status.idle":"2025-12-24T18:38:17.921602Z","shell.execute_reply.started":"2025-12-24T18:38:15.238879Z","shell.execute_reply":"2025-12-24T18:38:17.920944Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample = pd.read_csv(\n    \"/kaggle/input/cassava-leaf-disease-classification/sample_submission.csv\"\n)\n\nsample['label'] = predictions\nsample.to_csv(\"submission.csv\", index=False)\n\nsample.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T18:38:55.814342Z","iopub.execute_input":"2025-12-24T18:38:55.814675Z","iopub.status.idle":"2025-12-24T18:38:55.830763Z","shell.execute_reply.started":"2025-12-24T18:38:55.814646Z","shell.execute_reply":"2025-12-24T18:38:55.830197Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(len(predictions), len(sample))\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T18:39:48.301765Z","iopub.execute_input":"2025-12-24T18:39:48.302056Z","iopub.status.idle":"2025-12-24T18:39:48.306356Z","shell.execute_reply.started":"2025-12-24T18:39:48.302033Z","shell.execute_reply":"2025-12-24T18:39:48.305642Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"np.bincount(predictions)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T18:42:16.091301Z","iopub.execute_input":"2025-12-24T18:42:16.091938Z","iopub.status.idle":"2025-12-24T18:42:16.098035Z","shell.execute_reply.started":"2025-12-24T18:42:16.091906Z","shell.execute_reply":"2025-12-24T18:42:16.097066Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(preds.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-24T18:42:51.997415Z","iopub.execute_input":"2025-12-24T18:42:51.998053Z","iopub.status.idle":"2025-12-24T18:42:52.002045Z","shell.execute_reply.started":"2025-12-24T18:42:51.998028Z","shell.execute_reply":"2025-12-24T18:42:52.001499Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}