{"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":"nvidiaTeslaT4","dataSources":[{"sourceId":45867,"databundleVersionId":6924515,"sourceType":"competition"}],"dockerImageVersionId":30588,"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","execution":{"iopub.status.busy":"2023-12-03T09:34:47.085572Z","iopub.execute_input":"2023-12-03T09:34:47.086174Z","iopub.status.idle":"2023-12-03T09:34:47.641638Z","shell.execute_reply.started":"2023-12-03T09:34:47.08614Z","shell.execute_reply":"2023-12-03T09:34:47.640734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Import Required Libraries\nimport glob\nimport os\nimport matplotlib.pyplot as plt\nimport cv2\nfrom tqdm import tqdm","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:34:47.748267Z","iopub.execute_input":"2023-12-03T09:34:47.748681Z","iopub.status.idle":"2023-12-03T09:34:47.965031Z","shell.execute_reply.started":"2023-12-03T09:34:47.748654Z","shell.execute_reply":"2023-12-03T09:34:47.964245Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_frame_train = pd.read_csv(\"/kaggle/input/UBC-OCEAN/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:34:48.544808Z","iopub.execute_input":"2023-12-03T09:34:48.545662Z","iopub.status.idle":"2023-12-03T09:34:48.567394Z","shell.execute_reply.started":"2023-12-03T09:34:48.545629Z","shell.execute_reply":"2023-12-03T09:34:48.566647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_frame_train","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:34:49.356564Z","iopub.execute_input":"2023-12-03T09:34:49.356906Z","iopub.status.idle":"2023-12-03T09:34:49.378796Z","shell.execute_reply.started":"2023-12-03T09:34:49.356879Z","shell.execute_reply":"2023-12-03T09:34:49.377892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_labels = data_frame_train.label.unique()","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:34:50.562187Z","iopub.execute_input":"2023-12-03T09:34:50.562526Z","iopub.status.idle":"2023-12-03T09:34:50.571667Z","shell.execute_reply.started":"2023-12-03T09:34:50.562499Z","shell.execute_reply":"2023-12-03T09:34:50.570754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"Length of target or independent variable :\",len(data_frame_train.label.unique()))","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:34:51.505753Z","iopub.execute_input":"2023-12-03T09:34:51.506104Z","iopub.status.idle":"2023-12-03T09:34:51.511596Z","shell.execute_reply.started":"2023-12-03T09:34:51.506072Z","shell.execute_reply":"2023-12-03T09:34:51.510662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list_of_images = os.listdir(\"/kaggle/input/UBC-OCEAN/train_thumbnails\")","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:34:53.607723Z","iopub.execute_input":"2023-12-03T09:34:53.608099Z","iopub.status.idle":"2023-12-03T09:34:53.613192Z","shell.execute_reply.started":"2023-12-03T09:34:53.608067Z","shell.execute_reply":"2023-12-03T09:34:53.612265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = cv2.imread(f\"/kaggle/input/UBC-OCEAN/train_thumbnails/{list_of_images[2]}\")\n\nimage = cv2.resize(image,(250,250))\nimage.shape\n# list_of_images","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:34:54.404255Z","iopub.execute_input":"2023-12-03T09:34:54.404608Z","iopub.status.idle":"2023-12-03T09:34:54.699875Z","shell.execute_reply.started":"2023-12-03T09:34:54.404577Z","shell.execute_reply":"2023-12-03T09:34:54.698958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# image = cv2.imread('/kaggle/input/UBC-OCEAN/train_thumbnails/_thumbnail.png')","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:52:53.577866Z","iopub.execute_input":"2023-12-03T09:52:53.578597Z","iopub.status.idle":"2023-12-03T09:52:53.585156Z","shell.execute_reply.started":"2023-12-03T09:52:53.578562Z","shell.execute_reply":"2023-12-03T09:52:53.584306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Making Separate Folders for Each of the Target Variable\n# 1. To Reduce The Size of image,for easy training and reading\n# 2. Storing it 5 different folders according to its category\n# 3. Normalising the image and converting in gray format in order to reduce processing time\n# 4. If not getting required result then we may try image augmentation like rotation,flip,extra\n","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:34:56.969369Z","iopub.execute_input":"2023-12-03T09:34:56.969732Z","iopub.status.idle":"2023-12-03T09:34:56.974051Z","shell.execute_reply.started":"2023-12-03T09:34:56.969702Z","shell.execute_reply":"2023-12-03T09:34:56.973217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in target_labels:\n    os.makedirs(f\"/kaggle/working/{i}_train_images\")","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:34:57.47839Z","iopub.execute_input":"2023-12-03T09:34:57.478757Z","iopub.status.idle":"2023-12-03T09:34:57.483283Z","shell.execute_reply.started":"2023-12-03T09:34:57.478728Z","shell.execute_reply":"2023-12-03T09:34:57.482472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def text2id(image_name):\n    img_id = image_name.split(\"_\")\n    return img_id[0]","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:34:59.954017Z","iopub.execute_input":"2023-12-03T09:34:59.954655Z","iopub.status.idle":"2023-12-03T09:34:59.959017Z","shell.execute_reply.started":"2023-12-03T09:34:59.954619Z","shell.execute_reply":"2023-12-03T09:34:59.958084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"int(text2id(list_of_images[0]))","metadata":{"execution":{"iopub.status.busy":"2023-12-03T09:35:00.941205Z","iopub.execute_input":"2023-12-03T09:35:00.941946Z","iopub.status.idle":"2023-12-03T09:35:00.947693Z","shell.execute_reply.started":"2023-12-03T09:35:00.941911Z","shell.execute_reply":"2023-12-03T09:35:00.94667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(list_of_images)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:06:18.872517Z","iopub.execute_input":"2023-12-03T10:06:18.873154Z","iopub.status.idle":"2023-12-03T10:06:18.879083Z","shell.execute_reply.started":"2023-12-03T10:06:18.87312Z","shell.execute_reply":"2023-12-03T10:06:18.878192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for num,label in tqdm(enumerate((data_frame_train.label))):\n    lst = []\n    try:\n        img = cv2.imread(f\"/kaggle/input/UBC-OCEAN/train_thumbnails/{data_frame_train.image_id[num]}_thumbnail.png\")\n        print(f\"/kaggle/input/UBC-OCEAN/train_thumbnails/{data_frame_train.image_id[num]}_thumbnail.png\")\n        img = cv2.resize(img,(250,250))\n        cv2.imwrite(f\"/kaggle/working/{label}_train_images/{data_frame_train.image_id[num]}_thumbnail.png\",img)  \n    except:\n        lst.append(data_frame_train.image_id[num])","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:01:34.01418Z","iopub.execute_input":"2023-12-03T10:01:34.014596Z","iopub.status.idle":"2023-12-03T10:03:05.566873Z","shell.execute_reply.started":"2023-12-03T10:01:34.014564Z","shell.execute_reply":"2023-12-03T10:03:05.566006Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# len(os.listdir(\"/kaggle/working/EC_train_images\"))","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:11:30.95907Z","iopub.execute_input":"2023-12-03T10:11:30.959825Z","iopub.status.idle":"2023-12-03T10:11:30.963664Z","shell.execute_reply.started":"2023-12-03T10:11:30.959788Z","shell.execute_reply":"2023-12-03T10:11:30.962695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\nimport PIL\nimport tensorflow as tf\n\nfrom tensorflow import keras\nfrom tensorflow.keras import layers\nfrom tensorflow.keras.models import Sequential","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:42:06.090157Z","iopub.execute_input":"2023-12-03T10:42:06.090563Z","iopub.status.idle":"2023-12-03T10:42:18.536853Z","shell.execute_reply.started":"2023-12-03T10:42:06.090531Z","shell.execute_reply":"2023-12-03T10:42:18.535859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_ds = tf.keras.utils.image_dataset_from_directory(\n  \"/kaggle/working/\",\n  validation_split=0.2,\n  subset=\"training\",\n  seed=123,\n  image_size=(250, 250),\n  batch_size=20)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T11:11:58.216817Z","iopub.execute_input":"2023-12-03T11:11:58.217172Z","iopub.status.idle":"2023-12-03T11:11:58.273308Z","shell.execute_reply.started":"2023-12-03T11:11:58.217143Z","shell.execute_reply":"2023-12-03T11:11:58.272461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_ds = tf.keras.utils.image_dataset_from_directory(\n  \"/kaggle/working/\",\n  validation_split=0.2,\n  subset=\"validation\",\n  seed=123,\n  image_size=(250, 250),\n  batch_size=20)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T11:11:59.638801Z","iopub.execute_input":"2023-12-03T11:11:59.639181Z","iopub.status.idle":"2023-12-03T11:11:59.693361Z","shell.execute_reply.started":"2023-12-03T11:11:59.639149Z","shell.execute_reply":"2023-12-03T11:11:59.692491Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_names = train_ds.class_names\nprint(class_names)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T11:12:00.813944Z","iopub.execute_input":"2023-12-03T11:12:00.814293Z","iopub.status.idle":"2023-12-03T11:12:00.819305Z","shell.execute_reply.started":"2023-12-03T11:12:00.814266Z","shell.execute_reply":"2023-12-03T11:12:00.818331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nplt.figure(figsize=(10, 10))\nfor images, labels in train_ds.take(1):\n    for i in range(9):\n        ax = plt.subplot(3, 3, i + 1)\n        plt.imshow(images[i].numpy().astype(\"uint8\"))\n        plt.title(class_names[labels[i]])\n        plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:48:49.454761Z","iopub.execute_input":"2023-12-03T10:48:49.455709Z","iopub.status.idle":"2023-12-03T10:48:50.873233Z","shell.execute_reply.started":"2023-12-03T10:48:49.455674Z","shell.execute_reply":"2023-12-03T10:48:50.872308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for image_batch, labels_batch in train_ds:\n    print(image_batch.shape)\n    print(labels_batch.shape)\n    break","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:50:02.982854Z","iopub.execute_input":"2023-12-03T10:50:02.983835Z","iopub.status.idle":"2023-12-03T10:50:03.149253Z","shell.execute_reply.started":"2023-12-03T10:50:02.983795Z","shell.execute_reply":"2023-12-03T10:50:03.148313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AUTOTUNE = tf.data.AUTOTUNE\n\ntrain_ds = train_ds.cache().shuffle(1000).prefetch(buffer_size=AUTOTUNE)\nval_ds = val_ds.cache().prefetch(buffer_size=AUTOTUNE)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:50:22.263401Z","iopub.execute_input":"2023-12-03T10:50:22.264322Z","iopub.status.idle":"2023-12-03T10:50:22.279266Z","shell.execute_reply.started":"2023-12-03T10:50:22.264286Z","shell.execute_reply":"2023-12-03T10:50:22.278207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"normalization_layer = layers.Rescaling(1./255)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:50:36.786209Z","iopub.execute_input":"2023-12-03T10:50:36.786912Z","iopub.status.idle":"2023-12-03T10:50:36.809267Z","shell.execute_reply.started":"2023-12-03T10:50:36.786865Z","shell.execute_reply":"2023-12-03T10:50:36.808375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"normalized_ds = train_ds.map(lambda x, y: (normalization_layer(x), y))\nimage_batch, labels_batch = next(iter(normalized_ds))\nfirst_image = image_batch[0]\n# Notice the pixel values are now in `[0,1]`.\nprint(np.min(first_image), np.max(first_image))","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:50:53.559973Z","iopub.execute_input":"2023-12-03T10:50:53.560853Z","iopub.status.idle":"2023-12-03T10:50:54.004737Z","shell.execute_reply.started":"2023-12-03T10:50:53.560816Z","shell.execute_reply":"2023-12-03T10:50:54.003821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_classes = len(class_names)\n\nmodel = Sequential([\n  layers.Rescaling(1./255, input_shape=(250, 250, 3)),\n  layers.Conv2D(16, 3, padding='same', activation='relu'),\n  layers.MaxPooling2D(),\n  layers.Conv2D(32, 3, padding='same', activation='relu'),\n  layers.MaxPooling2D(),\n  layers.Conv2D(64, 3, padding='same', activation='relu'),\n  layers.MaxPooling2D(),\n  layers.Flatten(),\n  layers.Dense(128, activation='relu'),\n  layers.Dense(num_classes)\n])","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:51:36.112897Z","iopub.execute_input":"2023-12-03T10:51:36.113244Z","iopub.status.idle":"2023-12-03T10:51:36.247387Z","shell.execute_reply.started":"2023-12-03T10:51:36.113218Z","shell.execute_reply":"2023-12-03T10:51:36.24659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer='adam',\n              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n              metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:51:54.001141Z","iopub.execute_input":"2023-12-03T10:51:54.002111Z","iopub.status.idle":"2023-12-03T10:51:54.013933Z","shell.execute_reply.started":"2023-12-03T10:51:54.002073Z","shell.execute_reply":"2023-12-03T10:51:54.012966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"jupyter":{"source_hidden":true}},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:52:05.888407Z","iopub.execute_input":"2023-12-03T10:52:05.888823Z","iopub.status.idle":"2023-12-03T10:52:05.920621Z","shell.execute_reply.started":"2023-12-03T10:52:05.888793Z","shell.execute_reply":"2023-12-03T10:52:05.919943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs=10\nhistory = model.fit(\n  train_ds,\n  validation_data=val_ds,\n  epochs=epochs\n)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:52:17.736995Z","iopub.execute_input":"2023-12-03T10:52:17.737371Z","iopub.status.idle":"2023-12-03T10:52:34.670792Z","shell.execute_reply.started":"2023-12-03T10:52:17.737341Z","shell.execute_reply":"2023-12-03T10:52:34.669751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"acc = history.history['accuracy']\nval_acc = history.history['val_accuracy']\n\nloss = history.history['loss']\nval_loss = history.history['val_loss']\n\nepochs_range = range(epochs)\n\nplt.figure(figsize=(8, 8))\nplt.subplot(1, 2, 1)\nplt.plot(epochs_range, acc, label='Training Accuracy')\nplt.plot(epochs_range, val_acc, label='Validation Accuracy')\nplt.legend(loc='lower right')\nplt.title('Training and Validation Accuracy')\n\nplt.subplot(1, 2, 2)\nplt.plot(epochs_range, loss, label='Training Loss')\nplt.plot(epochs_range, val_loss, label='Validation Loss')\nplt.legend(loc='upper right')\nplt.title('Training and Validation Loss')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:53:56.588263Z","iopub.execute_input":"2023-12-03T10:53:56.589242Z","iopub.status.idle":"2023-12-03T10:53:57.1006Z","shell.execute_reply.started":"2023-12-03T10:53:56.589204Z","shell.execute_reply":"2023-12-03T10:53:57.099612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_augmentation = keras.Sequential(\n  [\n    layers.RandomFlip(\"horizontal\",\n                      input_shape=(250,\n                                  250,\n                                  3)),\n    layers.RandomRotation(0.1),\n    layers.RandomZoom(0.1),\n  ]\n)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:54:37.92722Z","iopub.execute_input":"2023-12-03T10:54:37.927934Z","iopub.status.idle":"2023-12-03T10:54:38.104908Z","shell.execute_reply.started":"2023-12-03T10:54:37.927885Z","shell.execute_reply":"2023-12-03T10:54:38.10405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 10))\nfor images, _ in train_ds.take(1):\n    for i in range(9):\n        augmented_images = data_augmentation(images)\n        ax = plt.subplot(3, 3, i + 1)\n        plt.imshow(augmented_images[0].numpy().astype(\"uint8\"))\n        plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:55:03.021599Z","iopub.execute_input":"2023-12-03T10:55:03.022412Z","iopub.status.idle":"2023-12-03T10:55:03.986246Z","shell.execute_reply.started":"2023-12-03T10:55:03.022378Z","shell.execute_reply":"2023-12-03T10:55:03.98538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential([\n  data_augmentation,\n  layers.Rescaling(1./255),\n  layers.Conv2D(16, 3, padding='same', activation='relu'),\n  layers.MaxPooling2D(),\n  layers.Conv2D(32, 3, padding='same', activation='relu'),\n  layers.MaxPooling2D(),\n  layers.Conv2D(64, 3, padding='same', activation='relu'),\n  layers.MaxPooling2D(),\n  layers.Dropout(0.2),\n  layers.Flatten(),\n  layers.Dense(128, activation='relu'),\n  layers.Dense(num_classes, name=\"outputs\")\n])","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:55:28.103078Z","iopub.execute_input":"2023-12-03T10:55:28.103918Z","iopub.status.idle":"2023-12-03T10:55:28.604597Z","shell.execute_reply.started":"2023-12-03T10:55:28.103877Z","shell.execute_reply":"2023-12-03T10:55:28.603768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(optimizer='adam',\n              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),\n              metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:55:42.435677Z","iopub.execute_input":"2023-12-03T10:55:42.436672Z","iopub.status.idle":"2023-12-03T10:55:42.448201Z","shell.execute_reply.started":"2023-12-03T10:55:42.436637Z","shell.execute_reply":"2023-12-03T10:55:42.447358Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:55:54.412835Z","iopub.execute_input":"2023-12-03T10:55:54.413178Z","iopub.status.idle":"2023-12-03T10:55:54.448184Z","shell.execute_reply.started":"2023-12-03T10:55:54.413151Z","shell.execute_reply":"2023-12-03T10:55:54.447294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"epochs = 15\nhistory = model.fit(\n  train_ds,\n  validation_data=val_ds,\n  epochs=epochs\n)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:56:07.673726Z","iopub.execute_input":"2023-12-03T10:56:07.674306Z","iopub.status.idle":"2023-12-03T10:56:20.982304Z","shell.execute_reply.started":"2023-12-03T10:56:07.674272Z","shell.execute_reply":"2023-12-03T10:56:20.981211Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"acc = history.history['accuracy']\nval_acc = history.history['val_accuracy']\n\nloss = history.history['loss']\nval_loss = history.history['val_loss']\n\nepochs_range = range(epochs)\n\nplt.figure(figsize=(8, 8))\nplt.subplot(1, 2, 1)\nplt.plot(epochs_range, acc, label='Training Accuracy')\nplt.plot(epochs_range, val_acc, label='Validation Accuracy')\nplt.legend(loc='lower right')\nplt.title('Training and Validation Accuracy')\n\nplt.subplot(1, 2, 2)\nplt.plot(epochs_range, loss, label='Training Loss')\nplt.plot(epochs_range, val_loss, label='Validation Loss')\nplt.legend(loc='upper right')\nplt.title('Training and Validation Loss')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-03T10:56:39.301371Z","iopub.execute_input":"2023-12-03T10:56:39.301788Z","iopub.status.idle":"2023-12-03T10:56:39.78805Z","shell.execute_reply.started":"2023-12-03T10:56:39.301754Z","shell.execute_reply":"2023-12-03T10:56:39.78711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = cv2.imread(\"/kaggle/input/UBC-OCEAN/test_thumbnails/41_thumbnail.png\")\nimg = cv2.resize(img,(250,250))\n# img = tf.keras.utils.load_img(\n#     \"/kaggle/input/UBC-OCEAN/test_thumbnails/41_thumbnail.png\", target_size=(250, 250)\n# )\nimg_array = tf.keras.utils.img_to_array(img)\nimg_array = tf.expand_dims(img_array, 0) # Create a batch\n\nmodel.predict(img_array)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T11:10:49.408687Z","iopub.execute_input":"2023-12-03T11:10:49.409546Z","iopub.status.idle":"2023-12-03T11:10:49.627845Z","shell.execute_reply.started":"2023-12-03T11:10:49.409497Z","shell.execute_reply":"2023-12-03T11:10:49.626865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_names = train_ds.class_names\nprint(class_names)","metadata":{"execution":{"iopub.status.busy":"2023-12-03T11:12:17.877854Z","iopub.execute_input":"2023-12-03T11:12:17.878236Z","iopub.status.idle":"2023-12-03T11:12:17.88334Z","shell.execute_reply.started":"2023-12-03T11:12:17.878207Z","shell.execute_reply":"2023-12-03T11:12:17.882207Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}