--- license: mit task_categories: - image-segmentation - object-detection language: - ar - fr tags: - coco - instance-segmentation - medicine - medication-boxes - mask-rcnn pretty_name: Medication Boxes (Arabic / Latin) size_categories: - n<1K --- # Medication Boxes — Arabic / Latin This dataset contains photos of medication boxes, with packaging text in Arabic and Latin script (French and others). It is annotated for **COCO instance segmentation** and was built for **MediSeG**, which segments each box so the text on it can be read afterwards. - **One class:** `1 = medicine_box` (`0 = background`) - **Format:** COCO JSON (polygons + bbox) - **Images:** original resolution, never resized ## Structure ``` train/ 540 images val/ 68 images test/ 68 images annotations/ instances_train.json instances_val.json instances_test.json ``` | Split | Images | Instances | |---|---:|---:| | train | 540 | 806 | | val | 68 | 121 | | test | 68 | 100 | | **Total** | **676** | **1027** | Each `images` entry also has three extra fields: `source`, `original_split` and `original_file`. ## Sources | Source | Images | Instances | Original annotation | |---|---:|---:|---| | `main_ar_fr` | 557 | 874 | YOLO-seg, 4-point polygons | | `medicine_packv2` | 119 | 153 | COCO polygons (24 drug classes merged into `medicine_box`) | The `drugs` source (1,068 images) was **left out** because it has bounding boxes only and no segmentation. ## Preparation - 80/10/10 split (seed 42), **grouped by source photo**. Near-duplicates (dHash of the object crop) go into the same split, which fixes the train/val/test leakage in the original splits (128 images affected). - Checks: no corrupted images, no invalid annotations, no empty masks, no exact duplicates (md5). - Validation: every split loads with `torchvision` `CocoDetection` + `wrap_dataset_for_transforms_v2`, and a `maskrcnn_resnet50_fpn(num_classes=2)` forward pass gives finite losses. ## Usage ```python from huggingface_hub import snapshot_download from torchvision.datasets import CocoDetection, wrap_dataset_for_transforms_v2 root = snapshot_download("ApyHTML19/Medication_Boxes_AR_Latin", repo_type="dataset") ds = CocoDetection(f"{root}/train", f"{root}/annotations/instances_train.json") ds = wrap_dataset_for_transforms_v2(ds, target_keys=("boxes", "labels", "masks")) img, target = ds[0] ``` ## Limitations - Small dataset (676 images), a single class, no per-drug labels. - The `main_ar_fr` polygons have 4 points, so masks are quadrilaterals that approximate the box outline.