--- pretty_name: KSDD2 (Kolektor Surface-Defect Dataset 2) — manual-download loader license: cc-by-nc-sa-4.0 tags: - computer-vision - image-classification - anomaly-detection - industrial-inspection - image-segmentation task_categories: - image-classification - image-segmentation configs: - config_name: image_only description: "Flat train/test folders with images only (no labels)." - config_name: classification_from_list description: "Flat train/test + defect_list.txt (or .csv) ⇒ labels." - config_name: classification_from_pyb description: "Flat train/test + split_weakly_*.pyb ⇒ labels (auto union)." - config_name: classification description: "ok/ and defect/ subfolders ⇒ labels." - config_name: with_mask description: "classification + optional mask_path matched by name from masks folders." --- # KSDD2 (manual-download loader) This repo provides a **manual-download loading script** for **Kolektor Surface-Defect Dataset 2 (KSDD2)**. No images are hosted here. Users must download KSDD2 from the **official page** and load locally via `load_dataset(..., data_dir=...)`. - Official page (license & download): https://www.vicos.si/resources/kolektorsdd2/ - Dataset license: **CC BY-NC-SA 4.0** (non‑commercial; attribution; share‑alike). For commercial usage, follow the authors’ instructions on the official page. > **What this loader does:** read your local KSDD2 folder, return a standard **DatasetDict** with images and metadata, without moving or copying files. --- ## Recommended environment (important) This dataset card uses a **custom loading script** (`trust_remote_code=True`). Newer versions of `datasets` (v4.x) **do not execute** loading scripts from the Hub. To load this dataset from the Hub script, please install the **tested versions**: ```bash pip install "datasets==3.2.0" "huggingface_hub<0.27" ``` If you must use newer releases, consider the built‑in `imagefolder` loader (labels/masks & pyb auto‑labeling will not be available), or run a local helper to produce Arrow/Parquet then `load_from_disk`. For best UX, we recommend the tested versions above. > Windows note: you may see a harmless warning about symlinks from `huggingface_hub`. It can be ignored, or disable via `HF_HUB_DISABLE_SYMLINK_WARNING=1`, or enable Windows Developer Mode / run as admin. --- ## Features by config | Config | Features | When to use | |----------------------------|-------------------------------------------|------------------------------------------------------------------------------| | `image_only` | `{"image", "path"}` | You have **flat** `train/` and `test/` (images only), no labels yet. | | `classification_from_list` | `{"image", "label", "path"}` | Flat folders + you provide `defect_list.txt` (one filename per line). | | `classification_from_pyb` | `{"image", "label", "path"}` | Flat folders + you have `split_weakly_*.pyb` files (labels **auto‑derived**). | | `classification` | `{"image", "label", "path"}` | Your data is already split into `ok/` and `defect/` subfolders. | | `with_mask` | `{"image", "label", "path", "mask_path"}` | Same as `classification`, and you also have a masks folder with same names. | `label` is a `ClassLabel` with `["good", "defect"]`. `mask_path` is a string (empty if not found). --- ## Folder layouts (examples) ### A) Flat layout (no subfolders under split) ``` KSDD2/ train/*.png|jpg test/*.png|jpg split_weakly_0.pyb split_weakly_16.pyb ... ``` ### B) Labeled subfolders ``` KSDD2/ train/ ok/*.png|jpg defect/*.png|jpg [masks | masks_defect | ground_truth | gt | label | labels]/*.png # optional, for with_mask test/ ok/*.png|jpg defect/*.png|jpg [masks | masks_defect | ground_truth | gt | label | labels]/*.png ``` --- ## Quickstart > All snippets below assume the **tested versions** mentioned above and `trust_remote_code=True`. ### 1) Flat, images only ```python from datasets import load_dataset ds = load_dataset("OliverOnHF/ksdd2", name="image_only", data_dir=r"", trust_remote_code=True) print(ds) print(ds["train"][0]) # {"image": ..., "path": "..."} ``` ### 2) Flat + auto labels from pyb ```python ds = load_dataset("OliverOnHF/ksdd2", name="classification_from_pyb", data_dir=r"", trust_remote_code=True) print(ds["train"].features) # ClassLabel(names=['good','defect']) print(ds["train"][0]) # {"image": ..., "label": 0/1, "path": "..."} ``` **How it works:** the loader scans all `split_weakly_*.pyb` next to your `train/` and `test/`, extracts filename strings and/or numeric IDs, matches them to your image basenames (e.g. `10023` → `10023.png`), and takes the **union** across all pyb files: if a name appears in any pyb, it is labeled as `defect`. ### 3) Flat + your defect list Place a `defect_list.txt` (or `.csv`) **inside each split**: ``` KSDD2/ train/ defect_list.txt # one filename per line; comments (#) and blanks ignored test/ defect_list.txt ``` Then: ```python ds = load_dataset("OliverOnHF/ksdd2", name="classification_from_list", data_dir=r"", trust_remote_code=True) ``` ### 4) Labeled subfolders ```python ds = load_dataset("OliverOnHF/ksdd2", name="classification", data_dir=r"", trust_remote_code=True) ``` ### 5) Labeled subfolders + masks ```python ds = load_dataset("OliverOnHF/ksdd2", name="with_mask", data_dir=r"", trust_remote_code=True) ``` The loader looks up masks by **same filename** under any of: `masks`, `masks_defect`, `ground_truth`, `gt`, `label`, `labels`. If not found, `mask_path` is an empty string. --- ## Troubleshooting - **“Dataset scripts are no longer supported”** or cannot `trust_remote_code`: use the tested versions shown above (`datasets==3.2.0`, `huggingface_hub<0.27`). - **“Cannot find class folders … expect ok and defect”**: you selected `classification`/`with_mask` but your layout is flat. Use `classification_from_pyb` / `classification_from_list`, or reorganize into `ok/` and `defect/`. - **No labels produced in `classification_from_pyb`**: make sure `split_weakly_*.pyb` sits next to `train/` and `test/`, and that image basenames contain numeric IDs or exact names referenced by the pyb files. - **Windows symlink warning from `huggingface_hub`**: harmless; can be ignored. --- ## License - **Dataset (KSDD2)**: CC BY-NC-SA 4.0 — see the official KSDD2 page. This repo **does not redistribute** any images. - **Loader code in this repo**: MIT (see `LICENSE`). ## Citation Please cite KSDD2 as requested by the authors on the official page.