Repository navigation
Import and export YOLO, COCO and Hugging Face datasets - #3
Merged
Merged
Conversation
A labelkit dataset is Apple's Create ML format and nothing more; these two commands are how it trades with everything else. - import: reads a YOLO, COCO or Hugging Face image-folder dataset (format detected, splits merged), copies its images in and merges its boxes. Built from ImageImporter and AnnotationMerge, so it never overwrites a file (a clashing name is renamed and its boxes follow), repeating it changes nothing, and a source with unusable boxes imports nothing unless --lenient. --names supplies class names for a source that only has numeric ids, which a first trial on a public YOLO download showed is common. - export: writes YOLO (images/, labels/, classes.txt, data.yaml), COCO (_annotations.coco.json) or a Hugging Face image dataset (metadata.jsonl plus a dataset card, ready for 'hf upload') into a new folder. Class ids follow the labels alphabetically; coordinates are written as short decimals. - docs/datasets.md: recipes for publishing on Hugging Face, keeping images in an R2/S3 bucket with annotations.json in git, and using a large model as a teacher to label data for a small Create ML model - README: a quick start that imports a public 8-image dataset The smoke test round-trips each format and checks a repeated import leaves the file byte-identical.
A metadata.jsonl row's file_name was joined to the folder and used if the file existed, so a row in an untrusted download could name a file outside the dataset (../../x.png, or an absolute path) and have it copied in. Rows are now resolved against the listing of the source folder, so only image files found under it are accepted; anything else is reported as missing. COCO and YOLO already resolved images through that listing.
A correctness review, a simplification pass and a trial with real tools found these before merging: - symlinked images were copied as links, leaving dangling files; the file a link points to is copied, under the dataset's name for it - a copy failing midway left earlier images behind, and a refused import still created its target folder; the folder is now created only when the import goes through, and a failed run removes what it copied - source images without boxes were copied in even without --negatives; they are left out and counted as withoutBoxes - overlapping same-class boxes within a source were dropped as duplicates; import now de-duplicates only against what the dataset already had - an image renamed on a first import (a.jpg -> a-2.jpg) was copied again on the next; the earlier copy is recognised by content - COCO file names that share a basename across folders resolved to one file; the path is now kept and resolved exactly - class names: trailing comments, quoted commas and colons, doubled quotes and lists wrapped over lines are read correctly, so labels round-trip - a YOLO class id of nan, 1e30, 1.5 or -1 crashed or was truncated; it is a reported error - COCO sizes recorded before an EXIF rotation distorted boxes; reported as a problem instead - a symlinked source folder is read; --into inside the source is refused - export: data.yaml no longer sets a relative path (YOLO tooling resolved it against its own datasets folder; verified loading with Ultralytics), a failed export removes its folder, hidden files don't make --out non-empty, and a file-name clash exits 1 rather than 64 - small cleanups from the simplification pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this does
Two commands let a labelkit dataset trade with the rest of the ecosystem:
labelkit import <source> --into <dataset>brings in a YOLO, COCO or Hugging Face image dataset.labelkit export <dataset> --format yolo|coco|huggingface --out <dir>writes one out.Plus
docs/datasets.mdwith recipes built on them: publishing on Hugging Face, keeping images in an R2/S3 bucket with onlyannotations.jsonin git, and using a large model as a teacher to label data for a small Create ML model.Why these formats and nothing more
A survey of what small computer-vision teams use (storage tools, dataset hubs, pricing, existing manifest conventions) pointed to: Hugging Face for both private and public sharing, a plain bucket with rclone for teams that keep data in-house, and DVC as something that already works. So labelkit converts formats and leaves transfer and credentials to the tools that own them. There is deliberately no S3 client, no token handling and no sync protocol here.
Behaviour worth reviewing
importis built from existing parts (ImageImporterfor file names,AnnotationMergefor boxes), so it inherits their guarantees: it never overwrites a file (a clashing name becomesa-2.jpgand its boxes follow), repeating it changes nothing, and a source with unusable boxes imports nothing unless--lenient.train/,valid/,test/come in together, since a Create ML dataset is one folder.--negatives, because in a downloaded dataset that can mean "negative" or "unlabelled".exportonly reads the dataset and refuses an--outthat is non-empty or is the dataset folder.trainand says so indata.yaml; splitting is left to YOLO tooling.metadata.jsonlneeds no side table. Import accepts names or ids, and bothcategoriesandcategory.Tried on a real dataset
I imported COCO8 (Ultralytics' 8-image YOLO sample) from its public zip: 8 images, 30 boxes,
validateclean, and the rendered boxes sit correctly on the objects. That trial found a gap, fixed here: the zip has no class names, so labels came in asclass_23.--names coco8.yamlnow supplies them. The README quick start uses exactly this dataset.How it was checked
swift test: 196 tests, 0 failures (21 new), including a round trip through each format and reading other tools' layouts (Ultralytics split folders, segmentation rows, COCO with images in a sibling folder, Hugging Face integer categories).scripts/smoke-scripted.shnow exports to each format, imports it back, and checks a repeated import leaves the file byte-identical.Not checked:
importdoes not read; it handles the image-folder layout only.Left for later
🤖 Generated with Claude Code