pills_inside_bottles / pills_inside_bottles.py
guowenxin
Update modified script
3427d84
raw
history blame contribute delete
No virus
3.01 kB
"""The dataset contains 13,955 imgaes of pills inside medication bottles,
which are from a top down view. They are labeled with 20 distinct National
Drug Code (NDC) and each image is associated with an image id. The dataset
is split into train, test, and validation sets. """
import os
from typing import List
import datasets
_CITATION = """\
@InProceedings{University of Michigan - Deep Blue Data,
title = {Images of pills inside medication bottles dataset},
author={Lester, C. A., Al Kontar, R., Chen, Q.},
year={2022}
}
"""
_DESCRIPTION = """\
This dataset contains pills images inside medication bottles from a top down view, with National Drug Code (NDC) and image id.
"""
_HOMEPAGE = "https://deepblue.lib.umich.edu/data/concern/data_sets/6d56zw997?locale=en#items_display"
_LICENSE = "CC BY 4.0"
_URLS = {
"dataset": "https://deepblue.lib.umich.edu/data/downloads/rr171x63c",
}
class NewDataset(datasets.GeneratorBasedBuilder):
"""The dataset contains train, test, and validation data for pills images inside medication bottles"""
_URLS = _URLS
VERSION = datasets.Version("1.1.0")
def _info(self):
features = datasets.Features(
{
"image": datasets.Image(),
"id": datasets.Value("string"),
"ndc": datasets.Value("string")
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
data_dir = dl_manager.download_and_extract(self._URLS["dataset"])
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath": os.path.join(data_dir, "NLM20/train")},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"filepath": os.path.join(data_dir, "NLM20/test")},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"filepath": os.path.join(data_dir, "NLM20/valid")},
),
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, filepath):
for ndc in os.listdir(filepath):
ndc_path = os.path.join(filepath, ndc)
if os.path.isdir(ndc_path):
for image_file in os.listdir(ndc_path):
image_path = os.path.join(ndc_path, image_file)
image_id = os.path.splitext(image_file)[0]
yield image_id, {
"image": image_path,
"id": image_id,
"ndc": ndc,
}