Commit 975e121e authored by dulanthaM's avatar dulanthaM

getting data completed

parent b79a6926
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "Y2jOdgL3j-o8"
},
"source": [
"# 🟨 Getting the Data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "lDXyIngTMaXf",
"outputId": "eb920137-7143-4c2c-e43e-a0aa82d93b49"
},
"outputs": [],
"source": [
"from google.colab import drive\n",
"drive.mount('/content/drive')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "t-ZDw43fiy-1"
},
"outputs": [],
"source": [
"data_location = '/content/drive/MyDrive/RP_SmartFarmer/Dulantha Madhushan - Nutrient deficiency/Dataset/Dificiency Data.rar'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "widI8pNLhUci",
"outputId": "13c35bb6-dd84-4ffd-f585-402d31aeaa41"
},
"outputs": [],
"source": [
"!pip install patool"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 105
},
"id": "U-MmiQnjF9gG",
"outputId": "3d634674-631e-4ed7-d8d7-708c1f9050f5"
},
"outputs": [],
"source": [
"import patoolib\n",
"patoolib.extract_archive(data_location, outdir=\"/content\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "_YdAEKT6GSoX",
"outputId": "4fdd684c-a8b2-4fa3-ee3e-91cd0c9ec280"
},
"outputs": [],
"source": [
"import os\n",
"for dirpath , dirnames , filenames in os.walk(\"Dificiency Data\"):\n",
" print(f\"There are {len(dirnames)} directories and {len(filenames)} images in '{dirpath}'.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "gLo3FV6OGVP0",
"outputId": "c9f815fd-004f-44d5-dba0-745f657c09fb"
},
"outputs": [],
"source": [
"train_dir = \"Dificiency Data/Trainig\"\n",
"test_dir = \"Dificiency Data/Testing\"\n",
"\n",
"#lets get the class names\n",
"import pathlib\n",
"import numpy as np\n",
"\n",
"data_dir = pathlib.Path(train_dir)\n",
"class_names = np.array(sorted([item.name for item in data_dir.glob('*')]))\n",
"print(class_names)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "vVCpvSuKlGG1"
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import matplotlib.image as mpimg\n",
"import random\n",
"import os\n",
"\n",
"def view_random_image(target_dir , target_class):\n",
" target_folder = target_dir+\"/\"+target_class\n",
" random_image = random.sample(os.listdir(target_folder) ,1)\n",
"\n",
" img = mpimg.imread(target_folder+\"/\"+random_image[0])\n",
" plt.imshow(img)\n",
" plt.title(target_class)\n",
" plt.axis(\"off\")\n",
"\n",
" print(f\"Image Shape:{img.shape}\") \n",
"\n",
" return img"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tVx10O9CGXn2",
"outputId": "173a0a39-9cfa-4f76-cf91-9e67e7da54d0"
},
"outputs": [],
"source": [
"import random\n",
"img = view_random_image(target_dir=train_dir , \n",
" target_class = random.choice(class_names))"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"collapsed_sections": [
"Y2jOdgL3j-o8",
"HvDEsB_fj7_7",
"RFJbEeyUlUgn",
"z_3CSlVYgcU7",
"gx3orjVQMLLt"
],
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment