{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "a333665e-77ee-43af-b539-8b2bc87c008c", "metadata": {}, "outputs": [], "source": [ "import json\n", "import pandas as pd\n", "from pathlib import Path\n", "from PIL import Image, ImageDraw, ImageFile\n", "import cv2\n", "import io \n", "import base64\n", "import numpy as np\n", "from pycocotools.coco import COCO\n", "import os\n", "import matplotlib.pyplot as plt\n", "import matplotlib.patches as patches\n", "from PIL import Image\n", "ImageFile.LOAD_TRUNCATED_IMAGES = True\n", "\n", "import utils\n", "\n", "dataset_dir = './mskf_0/'\n", "train_df, train_coco_data = utils.split_to_df(dataset_dir, 'train/')\n", "valid_df, valid_coco_data = utils.split_to_df(dataset_dir, 'valid')" ] }, { "cell_type": "code", "execution_count": 2, "id": "0e0d5a99-4eba-49d4-931b-0128691631b1", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "{'id': 1,\n", " 'license': 1,\n", " 'file_name': 'S0505210301_M_png.rf.e47187e88c167fad1db290b0214e2175.jpg',\n", " 'height': 512,\n", " 'width': 512,\n", " 'date_captured': '2024-05-08T06:13:06+00:00'}" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_coco_data['images'][0]" ] }, { "cell_type": "code", "execution_count": 3, "id": "df660d83-5afb-4b7c-83e4-f1f9d68577cd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 2, 3, 4, 5])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.unique(train_df['category_id'])" ] }, { "cell_type": "code", "execution_count": 4, "id": "51f26d8d-0116-48fe-8cea-d070350df333", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "{'image_id': array([], dtype=object),\n", " 'category_id': array([], dtype=object),\n", " 'bbox': array([], dtype=object),\n", " 'area': array([], dtype=object),\n", " 'segmentation': array([], dtype=object),\n", " 'iscrowd': array([], dtype=object),\n", " 'width': array([], dtype=object),\n", " 'height': array([], dtype=object),\n", " 'observation': array([], dtype=object),\n", " 'image': array([], dtype=object),\n", " 'annot_id': array([], dtype=object)}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "unique_types = {col: train_df[col].apply(type).unique() for col in train_df.columns}\n", "unique_types" ] }, { "cell_type": "code", "execution_count": 5, "id": "6f464df1-9e86-47ed-a8c6-d5116a71085e", "metadata": { "scrolled": true }, "outputs": [], "source": [ "# train_df.head(20)" ] }, { "cell_type": "code", "execution_count": 6, "id": "3f4afc2a-2ee4-458d-95c0-19e8497653da", "metadata": { "scrolled": true }, "outputs": [], "source": [ "from collections import defaultdict\n", "from datasets import Dataset, Features, Sequence\n", "import datasets\n", "from io import BytesIO\n", "\n", "cats_to_colours = { 1:('central-ring', (1,252,214)), \n", " 2:('other', (255,128,1)),\n", " 3:('read-out-streak', (20, 77, 158)), \n", " 4:('smoke-ring', (159,21,100)),\n", " 5:('star-loop', (255, 188, 248))}\n", "\n", "train_dataset=utils.df_to_dataset_dict(train_df, train_coco_data, cats_to_colours)\n", "valid_dataset=utils.df_to_dataset_dict(valid_df, valid_coco_data, cats_to_colours)" ] }, { "cell_type": "code", "execution_count": 7, "id": "e3ed2ab1-8632-4e49-a661-c306554bd010", "metadata": { "scrolled": true }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6ebf9675899e4ffcbcb3ebebbe7d6147", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Uploading the dataset shards: 0%| | 0/1 [00:00