{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "461dee1b-62d6-43fc-bbef-42db7566dcbf", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: kagglehub in c:\\users\\singh\\anaconda3\\lib\\site-packages (0.3.4)\n", "Requirement already satisfied: packaging in c:\\users\\singh\\anaconda3\\lib\\site-packages (from kagglehub) (23.1)\n", "Requirement already satisfied: requests in c:\\users\\singh\\anaconda3\\lib\\site-packages (from kagglehub) (2.31.0)\n", "Requirement already satisfied: tqdm in c:\\users\\singh\\anaconda3\\lib\\site-packages (from kagglehub) (4.65.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\singh\\anaconda3\\lib\\site-packages (from requests->kagglehub) (2.0.4)\n", "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\singh\\anaconda3\\lib\\site-packages (from requests->kagglehub) (3.4)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\singh\\anaconda3\\lib\\site-packages (from requests->kagglehub) (2.0.7)\n", "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\singh\\anaconda3\\lib\\site-packages (from requests->kagglehub) (2024.2.2)\n", "Requirement already satisfied: colorama in c:\\users\\singh\\anaconda3\\lib\\site-packages (from tqdm->kagglehub) (0.4.6)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install kagglehub" ] }, { "cell_type": "code", "execution_count": 9, "id": "c3c7d28b-6d74-42d4-9d78-9f964e4b77ef", "metadata": {}, "outputs": [], "source": [ "import kagglehub" ] }, { "cell_type": "code", "execution_count": 10, "id": "81c6b0c6-86ba-47b5-bc64-36cb1d679f2f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Warning: Looks like you're using an outdated `kagglehub` version, please consider updating (latest version: 0.3.6)\n" ] } ], "source": [ "path=kagglehub.dataset_download(\"rahmasleam/flowers-dataset\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "691fb5cf-aeb1-4fe1-ac65-a0de6b1a66a4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'C:\\\\Users\\\\Singh\\\\.cache\\\\kagglehub\\\\datasets\\\\rahmasleam\\\\flowers-dataset\\\\versions\\\\1'" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "path" ] }, { "cell_type": "code", "execution_count": 12, "id": "a7bd6c4b-a1f2-49fe-9d3b-78fe019bdd27", "metadata": {}, "outputs": [], "source": [ "import os\n", "import cv2" ] }, { "cell_type": "code", "execution_count": 31, "id": "c9b20532-6f16-424d-9c21-c5aa51b538dd", "metadata": {}, "outputs": [], "source": [ "folders=os.listdir(r\"C:\\Users\\Singh\\Downloads\\flower_photos\") # List all folders in the \"flower_photos\" directory." ] }, { "cell_type": "code", "execution_count": 32, "id": "bcd17c4d-bb28-445b-bb20-d6c6c7e082bd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "folders" ] }, { "cell_type": "code", "execution_count": 33, "id": "a8bb7124-8d25-4ab2-b9f7-efc04eda887f", "metadata": {}, "outputs": [], "source": [ "features=[]\n", "class_labels=[]\n", "for folder in folders:\n", " for images in os.listdir(r\"C:\\Users\\Singh\\Downloads\\flower_photos\\{}\".format(folder)):\n", " img=cv2.imread(r\"C:\\Users\\Singh\\Downloads\\flower_photos\\{}\\{}\".format(folder,images),0)# array repress\n", " img=cv2.resize(img,(50,50))#resizing the image\n", " img=img.flatten()#flattening the image\n", " features.append(img)# appending each flatten image in list\n", " class_labels.append(folder)#appending each class label to list" ] }, { "cell_type": "code", "execution_count": 34, "id": "cc21daf6-98bc-4c23-aff3-c25f66b559c4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "633" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(os.listdir(r\"C:\\Users\\Singh\\Downloads\\flower_photos\\daisy\")) # Count the number of images in the \"daisy\" folder inside \"flower_photos.\"" ] }, { "cell_type": "code", "execution_count": 35, "id": "cfe72f36-3a96-43ef-a7c8-68b9fa5a5ef5", "metadata": {}, "outputs": [], "source": [ "img1=cv2.imread(r\"C:\\Users\\Singh\\Downloads\\flower_photos\\daisy\\5547758_eea9edfd54_n.jpg\",0) # Load an image from the \"daisy\" folder in grayscale mode (0 indicates grayscale)." ] }, { "cell_type": "code", "execution_count": 36, "id": "72e3d4b8-dd96-432a-a88a-48edccb7d999", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[112, 106, 102, ..., 48, 50, 52],\n", " [128, 121, 117, ..., 49, 50, 52],\n", " [136, 129, 124, ..., 51, 51, 53],\n", " ...,\n", " [250, 251, 252, ..., 21, 20, 19],\n", " [248, 250, 250, ..., 23, 22, 21],\n", " [251, 252, 249, ..., 25, 25, 24]], dtype=uint8)" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img1" ] }, { "cell_type": "code", "execution_count": 37, "id": "261e6f19-30bc-4e15-9134-3debdcb235f8", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(232, 320)" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img1.shape # Get the shape (dimensions) of the grayscale image." ] }, { "cell_type": "code", "execution_count": 38, "id": "9227807f-3552-472e-90c1-7ff1a68c07cc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3670" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(features) # Get the number of features collected so far (assuming `features` is a list or similar)." ] }, { "cell_type": "code", "execution_count": 39, "id": "13569c16-3939-4617-bbe8-e69f153cb2fa", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3670" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(class_labels) # Get the number of class labels collected so far (assuming `class_labels` is a list or similar)." ] }, { "cell_type": "code", "execution_count": 42, "id": "3615aff7-79ad-472f-86f6-2dbb19db6c87", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 43, "id": "526870d5-168a-4dff-b8e1-dbf509ad5cf2", "metadata": {}, "outputs": [], "source": [ "final_data=pd.DataFrame(features) # Convert the `features` list or array into a pandas DataFrame." ] }, { "cell_type": "code", "execution_count": 44, "id": "01fb54b7-cbe8-43e6-81e7-40247b42d522", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(3670, 2500)" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_data.shape" ] }, { "cell_type": "code", "execution_count": 45, "id": "4b914cdc-da32-4e76-bc5f-41f1899d6320", "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 46, "id": "c8a7ad09-21d0-47c4-b553-00e95bdfc8b3", "metadata": {}, "outputs": [], "source": [ "final_data=final_data.astype(np.uint8) # Convert all data in the DataFrame to `uint8` data type for storage efficiency." ] }, { "cell_type": "code", "execution_count": 47, "id": "41441478-1e01-4799-aa77-ca3c51c6be91", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | 0 | \n", "1 | \n", "2 | \n", "3 | \n", "4 | \n", "5 | \n", "6 | \n", "7 | \n", "8 | \n", "9 | \n", "... | \n", "2490 | \n", "2491 | \n", "2492 | \n", "2493 | \n", "2494 | \n", "2495 | \n", "2496 | \n", "2497 | \n", "2498 | \n", "2499 | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "143 | \n", "149 | \n", "160 | \n", "169 | \n", "167 | \n", "167 | \n", "145 | \n", "144 | \n", "144 | \n", "159 | \n", "... | \n", "171 | \n", "174 | \n", "168 | \n", "149 | \n", "134 | \n", "128 | \n", "137 | \n", "137 | \n", "131 | \n", "127 | \n", "
1 | \n", "224 | \n", "222 | \n", "216 | \n", "232 | \n", "228 | \n", "75 | \n", "85 | \n", "80 | \n", "182 | \n", "185 | \n", "... | \n", "120 | \n", "116 | \n", "107 | \n", "110 | \n", "108 | \n", "156 | \n", "169 | \n", "141 | \n", "125 | \n", "172 | \n", "
2 | \n", "108 | \n", "81 | \n", "97 | \n", "84 | \n", "102 | \n", "120 | \n", "108 | \n", "106 | \n", "140 | \n", "128 | \n", "... | \n", "38 | \n", "44 | \n", "27 | \n", "26 | \n", "26 | \n", "27 | \n", "27 | \n", "31 | \n", "36 | \n", "40 | \n", "
3 | \n", "26 | \n", "25 | \n", "26 | \n", "29 | \n", "32 | \n", "35 | \n", "37 | \n", "38 | \n", "38 | \n", "40 | \n", "... | \n", "18 | \n", "16 | \n", "15 | \n", "16 | \n", "21 | \n", "18 | \n", "24 | \n", "16 | \n", "20 | \n", "23 | \n", "
4 | \n", "20 | \n", "21 | \n", "36 | \n", "45 | \n", "46 | \n", "45 | \n", "40 | \n", "42 | \n", "37 | \n", "56 | \n", "... | \n", "26 | \n", "42 | \n", "48 | \n", "42 | \n", "26 | \n", "25 | \n", "31 | \n", "39 | \n", "27 | \n", "35 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
3665 | \n", "212 | \n", "189 | \n", "186 | \n", "212 | \n", "47 | \n", "82 | \n", "116 | \n", "131 | \n", "82 | \n", "79 | \n", "... | \n", "83 | \n", "103 | \n", "114 | \n", "40 | \n", "7 | \n", "30 | \n", "30 | \n", "86 | \n", "194 | \n", "215 | \n", "
3666 | \n", "135 | \n", "126 | \n", "129 | \n", "131 | \n", "119 | \n", "141 | \n", "135 | \n", "128 | \n", "132 | \n", "136 | \n", "... | \n", "48 | \n", "53 | \n", "60 | \n", "58 | \n", "54 | \n", "41 | \n", "48 | \n", "84 | \n", "132 | \n", "120 | \n", "
3667 | \n", "88 | \n", "72 | \n", "78 | \n", "97 | \n", "57 | \n", "77 | \n", "91 | \n", "79 | \n", "46 | \n", "77 | \n", "... | \n", "83 | \n", "71 | \n", "81 | \n", "89 | \n", "91 | \n", "91 | \n", "87 | \n", "103 | \n", "80 | \n", "80 | \n", "
3668 | \n", "157 | \n", "189 | \n", "169 | \n", "132 | \n", "174 | \n", "162 | \n", "185 | \n", "174 | \n", "122 | \n", "160 | \n", "... | \n", "57 | \n", "152 | \n", "193 | \n", "74 | \n", "23 | \n", "18 | \n", "8 | \n", "12 | \n", "19 | \n", "45 | \n", "
3669 | \n", "49 | \n", "62 | \n", "118 | \n", "122 | \n", "75 | \n", "164 | \n", "127 | \n", "98 | \n", "74 | \n", "78 | \n", "... | \n", "98 | \n", "146 | \n", "80 | \n", "45 | \n", "63 | \n", "47 | \n", "91 | \n", "56 | \n", "76 | \n", "57 | \n", "
3670 rows × 2500 columns
\n", "\n", " | 0 | \n", "1 | \n", "2 | \n", "3 | \n", "4 | \n", "5 | \n", "6 | \n", "7 | \n", "8 | \n", "9 | \n", "... | \n", "2491 | \n", "2492 | \n", "2493 | \n", "2494 | \n", "2495 | \n", "2496 | \n", "2497 | \n", "2498 | \n", "2499 | \n", "class_labels | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "143 | \n", "149 | \n", "160 | \n", "169 | \n", "167 | \n", "167 | \n", "145 | \n", "144 | \n", "144 | \n", "159 | \n", "... | \n", "174 | \n", "168 | \n", "149 | \n", "134 | \n", "128 | \n", "137 | \n", "137 | \n", "131 | \n", "127 | \n", "daisy | \n", "
1 | \n", "224 | \n", "222 | \n", "216 | \n", "232 | \n", "228 | \n", "75 | \n", "85 | \n", "80 | \n", "182 | \n", "185 | \n", "... | \n", "116 | \n", "107 | \n", "110 | \n", "108 | \n", "156 | \n", "169 | \n", "141 | \n", "125 | \n", "172 | \n", "daisy | \n", "
2 | \n", "108 | \n", "81 | \n", "97 | \n", "84 | \n", "102 | \n", "120 | \n", "108 | \n", "106 | \n", "140 | \n", "128 | \n", "... | \n", "44 | \n", "27 | \n", "26 | \n", "26 | \n", "27 | \n", "27 | \n", "31 | \n", "36 | \n", "40 | \n", "daisy | \n", "
3 | \n", "26 | \n", "25 | \n", "26 | \n", "29 | \n", "32 | \n", "35 | \n", "37 | \n", "38 | \n", "38 | \n", "40 | \n", "... | \n", "16 | \n", "15 | \n", "16 | \n", "21 | \n", "18 | \n", "24 | \n", "16 | \n", "20 | \n", "23 | \n", "daisy | \n", "
4 | \n", "20 | \n", "21 | \n", "36 | \n", "45 | \n", "46 | \n", "45 | \n", "40 | \n", "42 | \n", "37 | \n", "56 | \n", "... | \n", "42 | \n", "48 | \n", "42 | \n", "26 | \n", "25 | \n", "31 | \n", "39 | \n", "27 | \n", "35 | \n", "daisy | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
3665 | \n", "212 | \n", "189 | \n", "186 | \n", "212 | \n", "47 | \n", "82 | \n", "116 | \n", "131 | \n", "82 | \n", "79 | \n", "... | \n", "103 | \n", "114 | \n", "40 | \n", "7 | \n", "30 | \n", "30 | \n", "86 | \n", "194 | \n", "215 | \n", "tulips | \n", "
3666 | \n", "135 | \n", "126 | \n", "129 | \n", "131 | \n", "119 | \n", "141 | \n", "135 | \n", "128 | \n", "132 | \n", "136 | \n", "... | \n", "53 | \n", "60 | \n", "58 | \n", "54 | \n", "41 | \n", "48 | \n", "84 | \n", "132 | \n", "120 | \n", "tulips | \n", "
3667 | \n", "88 | \n", "72 | \n", "78 | \n", "97 | \n", "57 | \n", "77 | \n", "91 | \n", "79 | \n", "46 | \n", "77 | \n", "... | \n", "71 | \n", "81 | \n", "89 | \n", "91 | \n", "91 | \n", "87 | \n", "103 | \n", "80 | \n", "80 | \n", "tulips | \n", "
3668 | \n", "157 | \n", "189 | \n", "169 | \n", "132 | \n", "174 | \n", "162 | \n", "185 | \n", "174 | \n", "122 | \n", "160 | \n", "... | \n", "152 | \n", "193 | \n", "74 | \n", "23 | \n", "18 | \n", "8 | \n", "12 | \n", "19 | \n", "45 | \n", "tulips | \n", "
3669 | \n", "49 | \n", "62 | \n", "118 | \n", "122 | \n", "75 | \n", "164 | \n", "127 | \n", "98 | \n", "74 | \n", "78 | \n", "... | \n", "146 | \n", "80 | \n", "45 | \n", "63 | \n", "47 | \n", "91 | \n", "56 | \n", "76 | \n", "57 | \n", "tulips | \n", "
3670 rows × 2501 columns
\n", "