{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"# Import Libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom sklearn.model_selection import train_test_split\n\nimport tensorflow as tf\nfrom tensorflow.keras import layers, models","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-08-13T18:36:42.154424Z","iopub.execute_input":"2023-08-13T18:36:42.155638Z","iopub.status.idle":"2023-08-13T18:36:42.161807Z","shell.execute_reply.started":"2023-08-13T18:36:42.155590Z","shell.execute_reply":"2023-08-13T18:36:42.160380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2  # or from PIL import Image\n\ndef preprocess_image(image_path):\n    # Load the image using OpenCV (or PIL)\n    image = cv2.imread(image_path)  # or Image.open(image_path)\n    \n    # Resize the image to a specific size (e.g., 32x32)\n    image = cv2.resize(image, (32, 32))  # or image.resize((32, 32))\n    \n    # Normalize pixel values to [0, 1]\n    image = image.astype('float32') / 255.0\n    \n    # Additional preprocessing steps if needed\n    \n    return image","metadata":{"execution":{"iopub.status.busy":"2023-08-13T18:36:42.163951Z","iopub.execute_input":"2023-08-13T18:36:42.164460Z","iopub.status.idle":"2023-08-13T18:36:42.175669Z","shell.execute_reply.started":"2023-08-13T18:36:42.164415Z","shell.execute_reply":"2023-08-13T18:36:42.174748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Get Dataset ","metadata":{}},{"cell_type":"code","source":"dataset_path = '/kaggle/input/cifar-10/sampleSubmission.csv'\ndata = pd.read_csv(dataset_path)\nprint(data.head())","metadata":{"execution":{"iopub.status.busy":"2023-08-13T18:36:42.177827Z","iopub.execute_input":"2023-08-13T18:36:42.178631Z","iopub.status.idle":"2023-08-13T18:36:42.276941Z","shell.execute_reply.started":"2023-08-13T18:36:42.178583Z","shell.execute_reply":"2023-08-13T18:36:42.275587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#  Preprocess the data","metadata":{}},{"cell_type":"code","source":"# Split the data into features (X) and labels (Y)\nX = data['id']\nY = data['label']\n\n# Split data for trainging and testing purpose\ntrain_image, test_image, train_labels, test_labels = train_test_split(X, Y, test_size=0.2, random_state=42)\n","metadata":{"execution":{"iopub.status.busy":"2023-08-13T18:36:42.279601Z","iopub.execute_input":"2023-08-13T18:36:42.280102Z","iopub.status.idle":"2023-08-13T18:36:42.337208Z","shell.execute_reply.started":"2023-08-13T18:36:42.280062Z","shell.execute_reply":"2023-08-13T18:36:42.335776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model Architecture","metadata":{}},{"cell_type":"code","source":"# Define the CNN model\nmodel = models.Sequential()\n\n# Convolutional and Pooling layers\nmodel.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3)))\nmodel.add(layers.MaxPooling2D((2, 2)))\nmodel.add(layers.Conv2D(64, (3, 3), activation='relu'))\nmodel.add(layers.MaxPooling2D((2, 2)))\nmodel.add(layers.Conv2D(128, (3, 3), activation='relu'))\nmodel.add(layers.MaxPooling2D((2, 2)))\n\n# Flatten layer\nmodel.add(layers.Flatten())\n\n# Fully connected layers\nmodel.add(layers.Dense(128, activation='relu'))\nmodel.add(layers.Dense(10, activation='softmax'))  # Assuming 10 classes\n\n# Compile the model\nmodel.compile(optimizer='adam',\n              loss='categorical_crossentropy',\n              metrics=['accuracy'])\n\n# Print a summary of the model architecture\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2023-08-13T18:36:42.339083Z","iopub.execute_input":"2023-08-13T18:36:42.339594Z","iopub.status.idle":"2023-08-13T18:36:42.571035Z","shell.execute_reply.started":"2023-08-13T18:36:42.339553Z","shell.execute_reply":"2023-08-13T18:36:42.569938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}