{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Import libraries\n", "import pandas as pd\n", "import os\n", "from pathlib import Path\n", "import shutil\n", "from sklearn.model_selection import train_test_split\n", "from tqdm.notebook import tqdm\n", "import cv2\n", "import yaml\n", "import matplotlib.pyplot as plt\n", "from ultralytics import YOLO\n", "import multiprocessing" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Set up directoris for training a yolo model\n", "\n", "# Images directories\n", "DATASET_DIR = Path('datasets/dataset')\n", "IMAGES_DIR = 'images'\n", "TRAIN_IMAGES_DIR = 'train'\n", "VAL_IMAGES_DIR = 'val'\n", "TEST_IMAGES_DIR = 'test'\n", "\n", "# Labels directories\n", "LABELS_DIR = 'labels'\n", "TRAIN_LABELS_DIR = LABELS_DIR + '/train'\n", "VAL_LABELS_DIR = LABELS_DIR +'/val'\n", "TEST_LABELS_DIR = LABELS_DIR +'/ test'" ] }, { "cell_type": "code", "execution_count": 7, "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", "
Image_IDclassconfidenceyminxminymaxxmaximage_pathclass_id
0id_u3q6jdck4j.jpgTrophozoite1.071212417371270images\\id_u3q6jdck4j.jpg0
1id_a6cl90trri.jpgTrophozoite1.055815666001604images\\id_a6cl90trri.jpg0
2id_qvc2le9sm8.jpgTrophozoite1.01317278814482914images\\id_qvc2le9sm8.jpg0
3id_w8xnbd5rvm.jpgTrophozoite1.0925174410411823images\\id_w8xnbd5rvm.jpg0
4id_6dop09rk02.jpgNEG1.00000images\\id_6dop09rk02.jpg2
\n", "
" ], "text/plain": [ " Image_ID class confidence ymin xmin ymax xmax \\\n", "0 id_u3q6jdck4j.jpg Trophozoite 1.0 712 1241 737 1270 \n", "1 id_a6cl90trri.jpg Trophozoite 1.0 558 1566 600 1604 \n", "2 id_qvc2le9sm8.jpg Trophozoite 1.0 1317 2788 1448 2914 \n", "3 id_w8xnbd5rvm.jpg Trophozoite 1.0 925 1744 1041 1823 \n", "4 id_6dop09rk02.jpg NEG 1.0 0 0 0 0 \n", "\n", " image_path class_id \n", "0 images\\id_u3q6jdck4j.jpg 0 \n", "1 images\\id_a6cl90trri.jpg 0 \n", "2 images\\id_qvc2le9sm8.jpg 0 \n", "3 images\\id_w8xnbd5rvm.jpg 0 \n", "4 images\\id_6dop09rk02.jpg 2 " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Load train and test files\n", "train = pd.read_csv('Train.csv')\n", "test = pd.read_csv('Test.csv')\n", "ss = pd.read_csv('SampleSubmission.csv')\n", "\n", "# Add an image_path column\n", "train['image_path'] = [Path('images/' + x) for x in train.Image_ID]\n", "test['image_path'] = [Path('images/' + x) for x in test.Image_ID]\n", "\n", "# Map str classes to ints (label encoding targets)\n", "train['class_id'] = train['class'].map({'Trophozoite': 0, 'WBC': 1, 'NEG': 2})\n", "\n", "# Preview the head of the train set\n", "train.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "total", "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.10.12" } }, "nbformat": 4, "nbformat_minor": 2 }