OUTLAW83 gwenxin commited on
Commit
2126aee
·
verified ·
0 Parent(s):

Duplicate from gwenxin/pills_inside_bottles

Browse files

Co-authored-by: Wenxin Guo <gwenxin@users.noreply.huggingface.co>

Files changed (3) hide show
  1. .gitattributes +55 -0
  2. README.md +128 -0
  3. pills_inside_bottles.py +98 -0
.gitattributes ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.lz4 filter=lfs diff=lfs merge=lfs -text
12
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
13
+ *.model filter=lfs diff=lfs merge=lfs -text
14
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
15
+ *.npy filter=lfs diff=lfs merge=lfs -text
16
+ *.npz filter=lfs diff=lfs merge=lfs -text
17
+ *.onnx filter=lfs diff=lfs merge=lfs -text
18
+ *.ot filter=lfs diff=lfs merge=lfs -text
19
+ *.parquet filter=lfs diff=lfs merge=lfs -text
20
+ *.pb filter=lfs diff=lfs merge=lfs -text
21
+ *.pickle filter=lfs diff=lfs merge=lfs -text
22
+ *.pkl filter=lfs diff=lfs merge=lfs -text
23
+ *.pt filter=lfs diff=lfs merge=lfs -text
24
+ *.pth filter=lfs diff=lfs merge=lfs -text
25
+ *.rar filter=lfs diff=lfs merge=lfs -text
26
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
27
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
29
+ *.tar filter=lfs diff=lfs merge=lfs -text
30
+ *.tflite filter=lfs diff=lfs merge=lfs -text
31
+ *.tgz filter=lfs diff=lfs merge=lfs -text
32
+ *.wasm filter=lfs diff=lfs merge=lfs -text
33
+ *.xz filter=lfs diff=lfs merge=lfs -text
34
+ *.zip filter=lfs diff=lfs merge=lfs -text
35
+ *.zst filter=lfs diff=lfs merge=lfs -text
36
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
37
+ # Audio files - uncompressed
38
+ *.pcm filter=lfs diff=lfs merge=lfs -text
39
+ *.sam filter=lfs diff=lfs merge=lfs -text
40
+ *.raw filter=lfs diff=lfs merge=lfs -text
41
+ # Audio files - compressed
42
+ *.aac filter=lfs diff=lfs merge=lfs -text
43
+ *.flac filter=lfs diff=lfs merge=lfs -text
44
+ *.mp3 filter=lfs diff=lfs merge=lfs -text
45
+ *.ogg filter=lfs diff=lfs merge=lfs -text
46
+ *.wav filter=lfs diff=lfs merge=lfs -text
47
+ # Image files - uncompressed
48
+ *.bmp filter=lfs diff=lfs merge=lfs -text
49
+ *.gif filter=lfs diff=lfs merge=lfs -text
50
+ *.png filter=lfs diff=lfs merge=lfs -text
51
+ *.tiff filter=lfs diff=lfs merge=lfs -text
52
+ # Image files - compressed
53
+ *.jpg filter=lfs diff=lfs merge=lfs -text
54
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
55
+ *.webp filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: cc-by-4.0
5
+ license_link: https://creativecommons.org/licenses/by/4.0/
6
+ tags:
7
+ - image-classification
8
+ pretty_name: pills-inside-bottles
9
+ size_categories:
10
+ - "10K<n<100K"
11
+ dataset_info:
12
+ features:
13
+ - name: image
14
+ dtype: image
15
+ - name: ndc
16
+ dtype: string
17
+ - name: id
18
+ dtype: string
19
+ splits:
20
+ - name: train
21
+ num_examples: 8393
22
+ - name: test
23
+ num_examples: 2786
24
+ - name: validation
25
+ num_examples: 2776
26
+ download_size: 13955
27
+ dataset_size: 13955
28
+
29
+ ---
30
+
31
+ # Dataset Card for Pills Inside Bottles
32
+
33
+ The dataset contains 13,955 imgaes of pills inside medication bottles, their National Drug Code (NDC), and image id.
34
+
35
+
36
+ ## Dataset Details
37
+
38
+ ### Dataset Description
39
+
40
+ 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.
41
+
42
+ - **License:** [cc-by-4.0](https://creativecommons.org/licenses/by/4.0/)
43
+
44
+ ### Dataset Sources
45
+
46
+ - **Homepage:** [Images of pills inside medication bottles dataset](https://deepblue.lib.umich.edu/data/concern/data_sets/6d56zw997#read_me_display)
47
+ - **Paper:** [Performance evaluation of a prescription medication image classification model: an observational cohort](https://www.nature.com/articles/s41746-021-00483-8)
48
+
49
+
50
+ ## Uses
51
+
52
+ ### Direct Use
53
+
54
+ The dataset can be used to train image classification models, which might be helpful for identifying pills automatically to increase efficiency and reduce dispensing error of pills in pharmacy.
55
+
56
+ ### Example Use Case
57
+
58
+ Here is a link to an [example use case](https://colab.research.google.com/drive/1UPaAnVacx3ZpOy_koWFwWIluhVZYOdhT?usp=sharing) of this dataset, which trained supervised models to predict the national drug code for each image. The highest accuracy obtained is about 97% using EfficientNetV2M as the pre-train model and Support Vector Machines as the supervised learning algorithm.
59
+
60
+
61
+
62
+ ## Dataset Structure
63
+
64
+ ### Data Instances
65
+
66
+ Each data instance contains the following features: _image_, _ndc_, and _id_.
67
+
68
+ An example from the train set looks like the following:
69
+ ```
70
+ {'image': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=1284x960>,
71
+ 'ndc': '29159',
72
+ 'id': '00378-3855'}
73
+ ```
74
+
75
+ ### Data Fields
76
+
77
+ - 'image': a image of pills inside a medication bottle
78
+ - 'ndc': National Drug Code
79
+ - 'id': unique image id
80
+
81
+ ### Data Splits
82
+
83
+ The dataset has 3 splits: _train_, _validation_, and _test_. The splits contain disjoint sets of images as well as their corresponding NDCs and IDs. The following table contains the number of images in each split and the percentages.
84
+
85
+ | Dataset Split | Number of Instances in Split | Percent |
86
+ | ------------- | ---------------------------- | ------------- |
87
+ | Train | 8,393 | 60.1% |
88
+ | Validation | 2,786 | 20.0% |
89
+ | Test | 2,776 | 19.9% |
90
+
91
+
92
+ ## Dataset Creation
93
+
94
+ ### Curation Rationale
95
+
96
+ The data is collected for training image classification model to facillitate work in pharmacy.
97
+
98
+ ### Source Data
99
+
100
+ #### Data Collection and Processing
101
+
102
+ The data is collected by a group of researchers, including Lester, C. A., Al Kontar, R., and Chen, Q., whose paper, "Performance Evaluation of a Prescription Medication Image
103
+ Classification Model: An Observational Cohort", is published in 2022.
104
+
105
+ #### Who are the source data producers?
106
+
107
+ According to Lester et. al, the dataset is produced by a commercial medication dispensing robot used at a mail-order pharmacy from a top-down view (Lester et. al, 6).
108
+
109
+ ## Bias, Risks, and Limitations
110
+
111
+ The researchers of the original paper only released part of their data. Therefore, the model performance might be influenced negatively due to insufficient training data.
112
+
113
+
114
+ ## Citation
115
+
116
+ **BibTeX:**
117
+ ```
118
+ @InProceedings{University of Michigan - Deep Blue Data,
119
+ title = {Images of pills inside medication bottles dataset},
120
+ author={Lester, C. A., Al Kontar, R., Chen, Q.},
121
+ year={2022}
122
+ }
123
+ ```
124
+
125
+ ## More Information
126
+
127
+ This dataset contain all information from the source data. The only change made is to rearrange the structure by extracting the file names, which correspond to NDC and image id, and put them into separated columns.
128
+
pills_inside_bottles.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ """The dataset contains 13,955 imgaes of pills inside medication bottles,
3
+ which are from a top down view. They are labeled with 20 distinct National
4
+ Drug Code (NDC) and each image is associated with an image id. The dataset
5
+ is split into train, test, and validation sets. """
6
+
7
+
8
+ import os
9
+ from typing import List
10
+
11
+ import datasets
12
+
13
+
14
+ _CITATION = """\
15
+ @InProceedings{University of Michigan - Deep Blue Data,
16
+ title = {Images of pills inside medication bottles dataset},
17
+ author={Lester, C. A., Al Kontar, R., Chen, Q.},
18
+ year={2022}
19
+ }
20
+ """
21
+
22
+
23
+ _DESCRIPTION = """\
24
+ This dataset contains pills images inside medication bottles from a top down view, with National Drug Code (NDC) and image id.
25
+ """
26
+
27
+
28
+ _HOMEPAGE = "https://deepblue.lib.umich.edu/data/concern/data_sets/6d56zw997?locale=en#items_display"
29
+
30
+
31
+ _LICENSE = "CC BY 4.0"
32
+
33
+
34
+ _URLS = {
35
+ "dataset": "https://deepblue.lib.umich.edu/data/downloads/rr171x63c",
36
+ }
37
+
38
+
39
+
40
+ class NewDataset(datasets.GeneratorBasedBuilder):
41
+ """The dataset contains train, test, and validation data for pills images inside medication bottles"""
42
+ _URLS = _URLS
43
+ VERSION = datasets.Version("1.1.0")
44
+
45
+ def _info(self):
46
+
47
+ features = datasets.Features(
48
+ {
49
+ "image": datasets.Image(),
50
+ "id": datasets.Value("string"),
51
+ "ndc": datasets.Value("string")
52
+ }
53
+ )
54
+
55
+ return datasets.DatasetInfo(
56
+ description=_DESCRIPTION,
57
+ features=features,
58
+ homepage=_HOMEPAGE,
59
+ license=_LICENSE,
60
+ citation=_CITATION,
61
+ )
62
+
63
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
64
+
65
+ data_dir = dl_manager.download_and_extract(self._URLS["dataset"])
66
+
67
+ return [
68
+ datasets.SplitGenerator(
69
+ name=datasets.Split.TRAIN,
70
+ gen_kwargs={"filepath": os.path.join(data_dir, "NLM20/train")},
71
+ ),
72
+ datasets.SplitGenerator(
73
+ name=datasets.Split.TEST,
74
+ gen_kwargs={"filepath": os.path.join(data_dir, "NLM20/test")},
75
+ ),
76
+ datasets.SplitGenerator(
77
+ name=datasets.Split.VALIDATION,
78
+ gen_kwargs={"filepath": os.path.join(data_dir, "NLM20/valid")},
79
+ ),
80
+ ]
81
+
82
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
83
+ def _generate_examples(self, filepath):
84
+
85
+ for ndc in os.listdir(filepath):
86
+ ndc_path = os.path.join(filepath, ndc)
87
+ if os.path.isdir(ndc_path):
88
+ for image_file in os.listdir(ndc_path):
89
+ image_path = os.path.join(ndc_path, image_file)
90
+ image_id = os.path.splitext(image_file)[0]
91
+ yield image_id, {
92
+ "image": image_path,
93
+ "id": image_id,
94
+ "ndc": ndc,
95
+ }
96
+
97
+
98
+