Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
362 changes: 362 additions & 0 deletions Assignment 3/Assignment3_Harsh/Assignment3_Harsh.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,362 @@
{
"metadata": {
"kernelspec": {
"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": "none",
"dataSources": [
{
"sourceId": 8077192,
"sourceType": "datasetVersion",
"datasetId": 4766889
}
],
"dockerImageVersionId": 31234,
"isInternetEnabled": false,
"language": "python",
"sourceType": "notebook",
"isGpuEnabled": false
},
"colab": {
"name": "notebook08af728a3c",
"provenance": [],
"gpuType": "T4"
},
"accelerator": "GPU"
},
"nbformat_minor": 0,
"nbformat": 4,
"cells": [
{
"source": [
"# IMPORTANT: RUN THIS CELL IN ORDER TO IMPORT YOUR KAGGLE DATA SOURCES,\n",
"# THEN FEEL FREE TO DELETE THIS CELL.\n",
"# NOTE: THIS NOTEBOOK ENVIRONMENT DIFFERS FROM KAGGLE'S PYTHON\n",
"# ENVIRONMENT SO THERE MAY BE MISSING LIBRARIES USED BY YOUR\n",
"# NOTEBOOK.\n",
"import kagglehub\n",
"raimiazeezbabatunde_candle_image_data_path = kagglehub.dataset_download('raimiazeezbabatunde/candle-image-data')\n",
"\n",
"print('Data source import complete.')\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "h96wK5A00qQn",
"outputId": "88fc15c0-8008-433f-eb0a-cd073a4d556b"
},
"cell_type": "code",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Using Colab cache for faster access to the 'candle-image-data' dataset.\n",
"Data source import complete.\n"
]
}
],
"execution_count": 15
},
{
"cell_type": "code",
"source": [
"import tensorflow as tf\n",
"tf.config.list_physical_devices('GPU')\n"
],
"metadata": {
"trusted": true,
"execution": {
"iopub.status.busy": "2026-01-03T12:24:45.663619Z",
"iopub.execute_input": "2026-01-03T12:24:45.664888Z",
"iopub.status.idle": "2026-01-03T12:24:45.672517Z",
"shell.execute_reply.started": "2026-01-03T12:24:45.664846Z",
"shell.execute_reply": "2026-01-03T12:24:45.671289Z"
},
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "SnlKA7DT0qQp",
"outputId": "e30c5da7-c5a0-448a-c41d-a17e21afa8c6"
},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]"
]
},
"metadata": {},
"execution_count": 16
}
],
"execution_count": 16
},
{
"cell_type": "code",
"source": [
"import os\n",
"os.listdir(\"/kaggle/input\")\n",
"os.listdir(\"/kaggle/input/candle-image-data\")\n"
],
"metadata": {
"trusted": true,
"execution": {
"iopub.status.busy": "2026-01-03T12:24:45.6748Z",
"iopub.execute_input": "2026-01-03T12:24:45.675235Z",
"iopub.status.idle": "2026-01-03T12:24:45.706538Z",
"shell.execute_reply.started": "2026-01-03T12:24:45.67519Z",
"shell.execute_reply": "2026-01-03T12:24:45.704819Z"
},
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "jXTJdCNQ0qQq",
"outputId": "9368f55f-ff21-40a9-d34a-81f745a72e98"
},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"['Test', 'Train']"
]
},
"metadata": {},
"execution_count": 17
}
],
"execution_count": 17
},
{
"cell_type": "code",
"source": [
"import tensorflow as tf\n",
"from tensorflow.keras.models import Sequential\n",
"from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Flatten, Dropout, BatchNormalization\n",
"from tensorflow.keras.preprocessing.image import ImageDataGenerator\n"
],
"metadata": {
"trusted": true,
"execution": {
"iopub.status.busy": "2026-01-03T12:24:45.70797Z",
"iopub.execute_input": "2026-01-03T12:24:45.708305Z",
"iopub.status.idle": "2026-01-03T12:24:45.728187Z",
"shell.execute_reply.started": "2026-01-03T12:24:45.708277Z",
"shell.execute_reply": "2026-01-03T12:24:45.726603Z"
},
"id": "LQ56anym0qQr"
},
"outputs": [],
"execution_count": 18
},
{
"cell_type": "code",
"source": [
"IMG_SIZE = (128, 128)\n",
"BATCH_SIZE = 32\n",
"EPOCHS = 5\n"
],
"metadata": {
"trusted": true,
"execution": {
"iopub.status.busy": "2026-01-03T12:24:45.731034Z",
"iopub.execute_input": "2026-01-03T12:24:45.731772Z",
"iopub.status.idle": "2026-01-03T12:24:45.759003Z",
"shell.execute_reply.started": "2026-01-03T12:24:45.731687Z",
"shell.execute_reply": "2026-01-03T12:24:45.757596Z"
},
"id": "rv2Gp1IE0qQr"
},
"outputs": [],
"execution_count": 19
},
{
"cell_type": "code",
"source": [
"train_datagen = ImageDataGenerator(\n",
" rescale=1./255,\n",
" rotation_range=5,\n",
" width_shift_range=0.05,\n",
" height_shift_range=0.05,\n",
" zoom_range=0.1,\n",
" brightness_range=[0.8, 1.2],\n",
" horizontal_flip=True\n",
")\n",
"\n",
"val_test_datagen = ImageDataGenerator(rescale=1./255)\n"
],
"metadata": {
"trusted": true,
"execution": {
"iopub.status.busy": "2026-01-03T12:24:45.760332Z",
"iopub.execute_input": "2026-01-03T12:24:45.760607Z",
"iopub.status.idle": "2026-01-03T12:24:45.794219Z",
"shell.execute_reply.started": "2026-01-03T12:24:45.760583Z",
"shell.execute_reply": "2026-01-03T12:24:45.792562Z"
},
"id": "F0Sa3vpm0qQs"
},
"outputs": [],
"execution_count": 20
},
{
"cell_type": "code",
"source": [
"DATASET_PATH = \"/kaggle/input/candle-image-data\"\n",
"\n",
"train_data = train_datagen.flow_from_directory(\n",
" DATASET_PATH + \"/Train\",\n",
" target_size=IMG_SIZE,\n",
" batch_size=BATCH_SIZE,\n",
" class_mode=\"binary\"\n",
")\n",
"\n",
"\n",
"\n",
"test_data = val_test_datagen.flow_from_directory(\n",
" DATASET_PATH + \"/Test\",\n",
" target_size=IMG_SIZE,\n",
" batch_size=BATCH_SIZE,\n",
" class_mode=\"binary\",\n",
" shuffle=False\n",
")\n",
"print(train_data.class_indices)\n",
"# {'DOWN': 0, 'UP': 1}\n"
],
"metadata": {
"trusted": true,
"execution": {
"iopub.status.busy": "2026-01-03T12:24:45.795754Z",
"iopub.execute_input": "2026-01-03T12:24:45.796462Z",
"iopub.status.idle": "2026-01-03T12:24:46.11179Z",
"shell.execute_reply.started": "2026-01-03T12:24:45.796412Z",
"shell.execute_reply": "2026-01-03T12:24:46.110248Z"
},
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "_spHZSmF0qQt",
"outputId": "0e367a75-13b8-41ae-b141-8259c18cb6e8"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Found 1433 images belonging to 2 classes.\n",
"Found 351 images belonging to 2 classes.\n",
"{'Down': 0, 'Up': 1}\n"
]
}
],
"execution_count": 21
},
{
"cell_type": "code",
"source": [
"model = Sequential([\n",
" Conv2D(32, (3,3), activation='relu', input_shape=(128,128,3)),\n",
" BatchNormalization(),\n",
" MaxPooling2D(2,2),\n",
"\n",
" Conv2D(64, (3,3), activation='relu'),\n",
" BatchNormalization(),\n",
" MaxPooling2D(2,2),\n",
"\n",
" Conv2D(128, (3,3), activation='relu'),\n",
" BatchNormalization(),\n",
" MaxPooling2D(2,2),\n",
"\n",
" Flatten(),\n",
" Dense(256, activation='relu'),\n",
" Dropout(0.5),\n",
"\n",
" Dense(1, activation='sigmoid') # UP / DOWN\n",
"])\n"
],
"metadata": {
"trusted": true,
"execution": {
"iopub.status.busy": "2026-01-03T12:24:46.113508Z",
"iopub.execute_input": "2026-01-03T12:24:46.113866Z",
"iopub.status.idle": "2026-01-03T12:24:46.263228Z",
"shell.execute_reply.started": "2026-01-03T12:24:46.113835Z",
"shell.execute_reply": "2026-01-03T12:24:46.262068Z"
},
"id": "xr7wQn7x0qQu"
},
"outputs": [],
"execution_count": 22
},
{
"cell_type": "code",
"source": [
"model.compile(\n",
" optimizer='adam',\n",
" loss='binary_crossentropy',\n",
" metrics=['accuracy']\n",
")\n",
"history = model.fit(\n",
" train_data,\n",
" epochs=EPOCHS,\n",
"\n",
")\n",
"test_loss, test_acc = model.evaluate(test_data)\n",
"print(\"Test Accuracy:\", test_acc)\n"
],
"metadata": {
"trusted": true,
"execution": {
"iopub.status.busy": "2026-01-03T12:24:46.264637Z",
"iopub.execute_input": "2026-01-03T12:24:46.264976Z",
"iopub.status.idle": "2026-01-03T12:25:38.447409Z",
"shell.execute_reply.started": "2026-01-03T12:24:46.264951Z",
"shell.execute_reply": "2026-01-03T12:25:38.446449Z"
},
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tNSajhCu0qQv",
"outputId": "2fe38300-ba44-475e-9980-af14087815a6"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Epoch 1/5\n",
"\u001b[1m45/45\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m22s\u001b[0m 357ms/step - accuracy: 0.5084 - loss: 3.5710\n",
"Epoch 2/5\n",
"\u001b[1m45/45\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 304ms/step - accuracy: 0.5315 - loss: 1.1040\n",
"Epoch 3/5\n",
"\u001b[1m45/45\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 307ms/step - accuracy: 0.5681 - loss: 0.7230\n",
"Epoch 4/5\n",
"\u001b[1m45/45\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 309ms/step - accuracy: 0.5705 - loss: 0.6868\n",
"Epoch 5/5\n",
"\u001b[1m45/45\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m14s\u001b[0m 305ms/step - accuracy: 0.5454 - loss: 0.6975\n",
"\u001b[1m11/11\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m5s\u001b[0m 313ms/step - accuracy: 0.7536 - loss: 9.8348\n",
"Test Accuracy: 0.4472934603691101\n"
]
}
],
"execution_count": 23
}
]
}
1 change: 1 addition & 0 deletions Assignment 3/Assignment3_Harsh/txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading