{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "QPiHdvpiuDQr" }, "outputs": [], "source": [ "import os\n", "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "Ly8qZqcguSiY", "outputId": "70d017a7-f8e9-41a7-8636-0ab436690cc3" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dataset URL: https://www.kaggle.com/datasets/masoudnickparvar/brain-tumor-mri-dataset\n", "License(s): CC0-1.0\n", "Downloading brain-tumor-mri-dataset.zip to /content\n", "100% 148M/149M [00:07<00:00, 22.3MB/s]\n", "100% 149M/149M [00:07<00:00, 19.7MB/s]\n" ] } ], "source": [ "! kaggle datasets download -d masoudnickparvar/brain-tumor-mri-dataset --unzip" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "OFjx-K5tuhqU" }, "outputs": [], "source": [ "def get_class_paths(path):\n", " classes = []\n", " class_paths = []\n", "\n", " # Iterate through dictionaries in the training path\n", " for label in os.listdir(path):\n", " label_path = os.path.join(path, label)\n", "\n", " # Check if it is a directory\n", " if os.path.isdir(label_path):\n", " # Iterate through images in the label directory\n", " for image in os.listdir(label_path):\n", " image_path = os.path.join(label_path, image)\n", "\n", " # Add class and path to respective lists\n", " classes.append(label)\n", " class_paths.append(image_path)\n", "\n", " # Create a dataframe with the collected data\n", " df = pd.DataFrame({\n", " 'Class Path': class_paths,\n", " 'Class': classes\n", " })\n", "\n", " return df" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "gqCxUnmVvX1u" }, "outputs": [], "source": [ "tr_df = get_class_paths(\"/content/Training\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 424 }, "id": "qIKDmOSHveKK", "outputId": "e42f3899-b5fb-4b48-db3c-677fb548a71b" }, "outputs": [ { "data": { "application/vnd.google.colaboratory.intrinsic+json": { "summary": "{\n \"name\": \"tr_df\",\n \"rows\": 5712,\n \"fields\": [\n {\n \"column\": \"Class Path\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 5712,\n \"samples\": [\n \"/content/Training/notumor/Tr-no_0138.jpg\",\n \"/content/Training/pituitary/Tr-pi_0058.jpg\",\n \"/content/Training/glioma/Tr-gl_0669.jpg\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Class\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 4,\n \"samples\": [\n \"notumor\",\n \"meningioma\",\n \"glioma\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}", "type": "dataframe", "variable_name": "tr_df" }, "text/html": [ "\n", "
\n", " | Class Path | \n", "Class | \n", "
---|---|---|
0 | \n", "/content/Training/glioma/Tr-gl_0038.jpg | \n", "glioma | \n", "
1 | \n", "/content/Training/glioma/Tr-gl_0358.jpg | \n", "glioma | \n", "
2 | \n", "/content/Training/glioma/Tr-gl_0132.jpg | \n", "glioma | \n", "
3 | \n", "/content/Training/glioma/Tr-gl_0459.jpg | \n", "glioma | \n", "
4 | \n", "/content/Training/glioma/Tr-gl_0155.jpg | \n", "glioma | \n", "
... | \n", "... | \n", "... | \n", "
5707 | \n", "/content/Training/meningioma/Tr-me_0411.jpg | \n", "meningioma | \n", "
5708 | \n", "/content/Training/meningioma/Tr-me_0606.jpg | \n", "meningioma | \n", "
5709 | \n", "/content/Training/meningioma/Tr-me_0729.jpg | \n", "meningioma | \n", "
5710 | \n", "/content/Training/meningioma/Tr-me_1110.jpg | \n", "meningioma | \n", "
5711 | \n", "/content/Training/meningioma/Tr-me_0561.jpg | \n", "meningioma | \n", "
5712 rows × 2 columns
\n", "\n", " | Class Path | \n", "Class | \n", "
---|---|---|
0 | \n", "/content/Testing/glioma/Te-gl_0268.jpg | \n", "glioma | \n", "
1 | \n", "/content/Testing/glioma/Te-gl_0264.jpg | \n", "glioma | \n", "
2 | \n", "/content/Testing/glioma/Te-gl_0291.jpg | \n", "glioma | \n", "
3 | \n", "/content/Testing/glioma/Te-gl_0015.jpg | \n", "glioma | \n", "
4 | \n", "/content/Testing/glioma/Te-gl_0267.jpg | \n", "glioma | \n", "
... | \n", "... | \n", "... | \n", "
1306 | \n", "/content/Testing/meningioma/Te-me_0050.jpg | \n", "meningioma | \n", "
1307 | \n", "/content/Testing/meningioma/Te-me_0150.jpg | \n", "meningioma | \n", "
1308 | \n", "/content/Testing/meningioma/Te-me_0061.jpg | \n", "meningioma | \n", "
1309 | \n", "/content/Testing/meningioma/Te-me_0278.jpg | \n", "meningioma | \n", "
1310 | \n", "/content/Testing/meningioma/Te-me_0140.jpg | \n", "meningioma | \n", "
1311 rows × 2 columns
\n", "\n", " | Class Path | \n", "Class | \n", "
---|---|---|
284 | \n", "/content/Testing/glioma/Te-gl_0106.jpg | \n", "glioma | \n", "
116 | \n", "/content/Testing/glioma/Te-gl_0277.jpg | \n", "glioma | \n", "
669 | \n", "/content/Testing/notumor/Te-no_0386.jpg | \n", "notumor | \n", "
119 | \n", "/content/Testing/glioma/Te-gl_0058.jpg | \n", "glioma | \n", "
1053 | \n", "/content/Testing/meningioma/Te-me_0023.jpg | \n", "meningioma | \n", "
... | \n", "... | \n", "... | \n", "
118 | \n", "/content/Testing/glioma/Te-gl_0269.jpg | \n", "glioma | \n", "
628 | \n", "/content/Testing/notumor/Te-no_0165.jpg | \n", "notumor | \n", "
1005 | \n", "/content/Testing/meningioma/Te-me_0201.jpg | \n", "meningioma | \n", "
391 | \n", "/content/Testing/notumor/Te-no_0080.jpg | \n", "notumor | \n", "
154 | \n", "/content/Testing/glioma/Te-gl_0237.jpg | \n", "glioma | \n", "
655 rows × 2 columns
\n", "\n", " | Class Path | \n", "Class | \n", "
---|---|---|
1304 | \n", "/content/Testing/meningioma/Te-me_0231.jpg | \n", "meningioma | \n", "
1114 | \n", "/content/Testing/meningioma/Te-me_0290.jpg | \n", "meningioma | \n", "
213 | \n", "/content/Testing/glioma/Te-gl_0145.jpg | \n", "glioma | \n", "
550 | \n", "/content/Testing/notumor/Te-no_0287.jpg | \n", "notumor | \n", "
1267 | \n", "/content/Testing/meningioma/Te-me_0236.jpg | \n", "meningioma | \n", "
... | \n", "... | \n", "... | \n", "
1184 | \n", "/content/Testing/meningioma/Te-me_0139.jpg | \n", "meningioma | \n", "
152 | \n", "/content/Testing/glioma/Te-gl_0155.jpg | \n", "glioma | \n", "
199 | \n", "/content/Testing/glioma/Te-glTr_0002.jpg | \n", "glioma | \n", "
963 | \n", "/content/Testing/pituitary/Te-pi_0065.jpg | \n", "pituitary | \n", "
39 | \n", "/content/Testing/glioma/Te-gl_0201.jpg | \n", "glioma | \n", "
656 rows × 2 columns
\n", "