{ "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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123456789...2490249124922493249424952496249724982499
0143149160169167167145144144159...171174168149134128137137131127
1224222216232228758580182185...120116107110108156169141125172
2108819784102120108106140128...38442726262727313640
326252629323537383840...18161516211824162023
420213645464540423756...26424842262531392735
..................................................................
366521218918621247821161318279...83103114407303086194215
3666135126129131119141135128132136...4853605854414884132120
366788727897577791794677...837181899191871038080
3668157189169132174162185174122160...571521937423188121945
3669496211812275164127987478...981468045634791567657
\n", "

3670 rows × 2500 columns

\n", "
" ], "text/plain": [ " 0 1 2 3 4 5 6 7 8 9 ... 2490 \\\n", "0 143 149 160 169 167 167 145 144 144 159 ... 171 \n", "1 224 222 216 232 228 75 85 80 182 185 ... 120 \n", "2 108 81 97 84 102 120 108 106 140 128 ... 38 \n", "3 26 25 26 29 32 35 37 38 38 40 ... 18 \n", "4 20 21 36 45 46 45 40 42 37 56 ... 26 \n", "... ... ... ... ... ... ... ... ... ... ... ... ... \n", "3665 212 189 186 212 47 82 116 131 82 79 ... 83 \n", "3666 135 126 129 131 119 141 135 128 132 136 ... 48 \n", "3667 88 72 78 97 57 77 91 79 46 77 ... 83 \n", "3668 157 189 169 132 174 162 185 174 122 160 ... 57 \n", "3669 49 62 118 122 75 164 127 98 74 78 ... 98 \n", "\n", " 2491 2492 2493 2494 2495 2496 2497 2498 2499 \n", "0 174 168 149 134 128 137 137 131 127 \n", "1 116 107 110 108 156 169 141 125 172 \n", "2 44 27 26 26 27 27 31 36 40 \n", "3 16 15 16 21 18 24 16 20 23 \n", "4 42 48 42 26 25 31 39 27 35 \n", "... ... ... ... ... ... ... ... ... ... \n", "3665 103 114 40 7 30 30 86 194 215 \n", "3666 53 60 58 54 41 48 84 132 120 \n", "3667 71 81 89 91 91 87 103 80 80 \n", "3668 152 193 74 23 18 8 12 19 45 \n", "3669 146 80 45 63 47 91 56 76 57 \n", "\n", "[3670 rows x 2500 columns]" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_data " ] }, { "cell_type": "code", "execution_count": 48, "id": "b1f089c9-df2f-4d7c-b3ba-a3ef75d22256", "metadata": {}, "outputs": [], "source": [ "final_data[\"class_labels\"]=class_labels # Add a new column \"class_labels\" to the DataFrame with the collected class labels." ] }, { "cell_type": "code", "execution_count": 49, "id": "583cecc9-cb99-4bc9-93e5-ab67de226bd3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123456789...249124922493249424952496249724982499class_labels
0143149160169167167145144144159...174168149134128137137131127daisy
1224222216232228758580182185...116107110108156169141125172daisy
2108819784102120108106140128...442726262727313640daisy
326252629323537383840...161516211824162023daisy
420213645464540423756...424842262531392735daisy
..................................................................
366521218918621247821161318279...103114407303086194215tulips
3666135126129131119141135128132136...53605854414884132120tulips
366788727897577791794677...7181899191871038080tulips
3668157189169132174162185174122160...1521937423188121945tulips
3669496211812275164127987478...1468045634791567657tulips
\n", "

3670 rows × 2501 columns

\n", "
" ], "text/plain": [ " 0 1 2 3 4 5 6 7 8 9 ... 2491 2492 2493 \\\n", "0 143 149 160 169 167 167 145 144 144 159 ... 174 168 149 \n", "1 224 222 216 232 228 75 85 80 182 185 ... 116 107 110 \n", "2 108 81 97 84 102 120 108 106 140 128 ... 44 27 26 \n", "3 26 25 26 29 32 35 37 38 38 40 ... 16 15 16 \n", "4 20 21 36 45 46 45 40 42 37 56 ... 42 48 42 \n", "... ... ... ... ... ... ... ... ... ... ... ... ... ... ... \n", "3665 212 189 186 212 47 82 116 131 82 79 ... 103 114 40 \n", "3666 135 126 129 131 119 141 135 128 132 136 ... 53 60 58 \n", "3667 88 72 78 97 57 77 91 79 46 77 ... 71 81 89 \n", "3668 157 189 169 132 174 162 185 174 122 160 ... 152 193 74 \n", "3669 49 62 118 122 75 164 127 98 74 78 ... 146 80 45 \n", "\n", " 2494 2495 2496 2497 2498 2499 class_labels \n", "0 134 128 137 137 131 127 daisy \n", "1 108 156 169 141 125 172 daisy \n", "2 26 27 27 31 36 40 daisy \n", "3 21 18 24 16 20 23 daisy \n", "4 26 25 31 39 27 35 daisy \n", "... ... ... ... ... ... ... ... \n", "3665 7 30 30 86 194 215 tulips \n", "3666 54 41 48 84 132 120 tulips \n", "3667 91 91 87 103 80 80 tulips \n", "3668 23 18 8 12 19 45 tulips \n", "3669 63 47 91 56 76 57 tulips \n", "\n", "[3670 rows x 2501 columns]" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_data # Display the entire DataFrame to examine its structure and data." ] }, { "cell_type": "code", "execution_count": 50, "id": "4bd4960b-0677-40bd-8256-73ed2fb70114", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 3670 entries, 0 to 3669\n", "Columns: 2501 entries, 0 to class_labels\n", "dtypes: object(1), uint8(2500)\n", "memory usage: 8.8+ MB\n" ] } ], "source": [ "final_data.info() # Display detailed information about the DataFrame, including column types and memory usage." ] }, { "cell_type": "code", "execution_count": null, "id": "b95f3573-f73a-468e-b12c-a605c93c6ded", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "bab6163f-9907-4cce-9e21-c37eabb6b5a0", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 5 }