{"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":"none","dataSources":[{"sourceId":5441,"databundleVersionId":38425,"sourceType":"competition"}],"dockerImageVersionId":31259,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# Install required libraries\n!pip install albumentations --quiet\n!pip install opencv-python --quiet\n!pip install matplotlib --quiet\n\nimport os\nimport cv2\nimport zipfile\nimport albumentations as A\nimport matplotlib.pyplot as plt\nfrom tqdm import tqdm\n\n# -------------------------------\n# Step 1: Unzip the Dataset\n# -------------------------------\ndataset_dir = \"/kaggle/input/dogs-vs-cats-redux-kernels-edition\"\n\n# Extract train.zip\nwith zipfile.ZipFile(os.path.join(dataset_dir, \"train.zip\"), 'r') as zip_ref:\n    zip_ref.extractall(\"/kaggle/working/train/\")\n\nprint(\"Train data extracted!\")\n\n# -------------------------------\n# Step 2: Prepare Data Folders\n# -------------------------------\ntrain_folder = \"/kaggle/working/train/train\"\n\n# You should now see image files like cat.0.jpg, dog.0.jpg, etc.\nprint(\"Total images in train folder:\", len(os.listdir(train_folder)))\n\n# -------------------------------\n# Step 3: Load Images & Labels\n# -------------------------------\nimages = []\nlabels = []\n\nfor img_name in tqdm(os.listdir(train_folder)):\n    img_path = os.path.join(train_folder, img_name)\n    \n    # Read and resize\n    img = cv2.imread(img_path)\n    if img is None:\n        continue\n\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    img = cv2.resize(img, (128, 128))\n    images.append(img)\n    \n    # Label from filename\n    label = \"Cat\" if \"cat\" in img_name.lower() else \"Dog\"\n    labels.append(label)\n\nprint(\"Loaded Images:\", len(images))\n\n# -------------------------------\n# Step 4: Define Augmentations\n# -------------------------------\ntransform = A.Compose([\n    A.HorizontalFlip(p=0.5),\n    A.RandomBrightnessContrast(p=0.5),\n    A.Rotate(limit=30, p=0.5),\n    A.GaussNoise(p=0.3),\n    A.HueSaturationValue(p=0.5)\n])\n\n# -------------------------------\n# Step 5: Apply Augmentations\n# -------------------------------\naugmented_images = []\n\nfor img in tqdm(images):\n    augmented = transform(image=img)\n    augmented_images.append(augmented[\"image\"])\n\nprint(\"Augmentation completed!\")\n\n# -------------------------------\n# Step 6: Show Results\n# -------------------------------\nplt.figure(figsize=(12, 6))\nfor i in range(5):\n    # Original\n    plt.subplot(2, 5, i+1)\n    plt.imshow(images[i])\n    plt.title(\"Original\")\n    plt.axis('off')\n\n    # Augmented\n    plt.subplot(2, 5, i+6)\n    plt.imshow(augmented_images[i])\n    plt.title(\"Augmented\")\n    plt.axis('off')\n\nplt.show()\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-01-22T16:40:34.820036Z","iopub.execute_input":"2026-01-22T16:40:34.820466Z","iopub.status.idle":"2026-01-22T16:42:06.565367Z","shell.execute_reply.started":"2026-01-22T16:40:34.820372Z","shell.execute_reply":"2026-01-22T16:42:06.564090Z"}},"outputs":[],"execution_count":null}]}