Upload 4 files
Browse files- README.md +55 -0
- dataset.py +130 -0
- dataset_infos.json +26 -0
- metadata_sample.jsonl +24 -0
README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- dataset
|
| 5 |
+
- wildlife
|
| 6 |
+
- image-depth
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
# Wildlife Image Depth Data Notes
|
| 10 |
+
|
| 11 |
+
## Dataset summary
|
| 12 |
+
|
| 13 |
+
This repository contains a preparation pipeline and a small metadata sample for **Wildlife** work with **Image Depth** inputs. It does not claim to be a complete benchmark release; the loader documents how source data is normalized and validated.
|
| 14 |
+
|
| 15 |
+
## Included material
|
| 16 |
+
|
| 17 |
+
- `dataset.py` — loading, cleaning, and split preparation code.
|
| 18 |
+
- `dataset_infos.json` — schema and split metadata.
|
| 19 |
+
- `metadata_sample.jsonl` — small, human-readable records for checking the schema.
|
| 20 |
+
- `README.md` — data card and usage notes.
|
| 21 |
+
|
| 22 |
+
## Processing choices
|
| 23 |
+
|
| 24 |
+
| Stage | Setting |
|
| 25 |
+
|---|---|
|
| 26 |
+
| Storage format | parquet |
|
| 27 |
+
| Preprocessing | adaptive |
|
| 28 |
+
| Augmentation | mixup cutmix |
|
| 29 |
+
| Split strategy | stratified 90 10 |
|
| 30 |
+
| Sampling | random |
|
| 31 |
+
| Quality checks | adaptive |
|
| 32 |
+
| Labeling | manual |
|
| 33 |
+
|
| 34 |
+
## Validation checklist
|
| 35 |
+
|
| 36 |
+
Before using the prepared data, verify source licenses, duplicates across splits, missing values, label balance, and modality-specific corruption. Record the source version and every filtering rule so a later run can reproduce the same rows.
|
| 37 |
+
|
| 38 |
+
## Intended use
|
| 39 |
+
|
| 40 |
+
The repository is suitable for testing the data pipeline, adapting it to a documented source, and preparing controlled research splits. Release status: **metadata sample; full source data not bundled**. The sample is for schema inspection only and should not be reported as a full training corpus.
|
| 41 |
+
|
| 42 |
+
## Risks and limitations
|
| 43 |
+
|
| 44 |
+
The loader cannot guarantee that an external source is representative, correctly licensed, or free of sensitive information. Users remain responsible for source review, privacy checks, and bias analysis before training or redistribution.
|
| 45 |
+
|
| 46 |
+
## Files
|
| 47 |
+
|
| 48 |
+
- `dataset.py` — primary artifact
|
| 49 |
+
- `README.md` — this documentation
|
| 50 |
+
- `dataset_infos.json` — schema metadata
|
| 51 |
+
- `metadata_sample.jsonl` — schema sample
|
| 52 |
+
|
| 53 |
+
## License
|
| 54 |
+
|
| 55 |
+
Released under **mit**. Review the source-data terms separately when this repository is used with external datasets.
|
dataset.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json, os, hashlib
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
# wildlife dataset processor
|
| 5 |
+
# modality: image_depth, preprocessing: adaptive
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# --- real data source: wildlife ---
|
| 9 |
+
TV_DATASET = 'OxfordIIITPet'
|
| 10 |
+
HF_CANDIDATES = []
|
| 11 |
+
IMAGE_FIELD = 'image'
|
| 12 |
+
TEXT_FIELD = None
|
| 13 |
+
LABEL_FIELD = 'label'
|
| 14 |
+
PROMPT_TEMPLATE = 'a photo of a {label} in the wild'
|
| 15 |
+
DATASET_URL = 'https://www.kaggle.com/c/dog-breed-identification'
|
| 16 |
+
|
| 17 |
+
def fetch_real_samples(max_samples=5000, cache_dir='./_cache'):
|
| 18 |
+
# 本地没有数据时自动下载真实公开数据集: torchvision -> HuggingFace -> 手动说明
|
| 19 |
+
out = []
|
| 20 |
+
if TV_DATASET is not None:
|
| 21 |
+
try:
|
| 22 |
+
import torchvision
|
| 23 |
+
ctor = getattr(torchvision.datasets, TV_DATASET)
|
| 24 |
+
try:
|
| 25 |
+
ds = ctor(root=cache_dir, split='train', download=True)
|
| 26 |
+
except TypeError:
|
| 27 |
+
try:
|
| 28 |
+
ds = ctor(root=cache_dir, train=True, download=True)
|
| 29 |
+
except TypeError:
|
| 30 |
+
ds = ctor(root=cache_dir, download=True)
|
| 31 |
+
classes = getattr(ds, 'classes', None)
|
| 32 |
+
os.makedirs(os.path.join(cache_dir, 'tv'), exist_ok=True)
|
| 33 |
+
for i, item in enumerate(ds):
|
| 34 |
+
if len(out) >= max_samples:
|
| 35 |
+
break
|
| 36 |
+
img, label = item[0], item[1]
|
| 37 |
+
name = classes[label] if classes else str(label)
|
| 38 |
+
p = os.path.join(cache_dir, 'tv', str(i) + '.png')
|
| 39 |
+
try:
|
| 40 |
+
img.save(p)
|
| 41 |
+
except Exception:
|
| 42 |
+
continue
|
| 43 |
+
out.append({'image': p, 'text': PROMPT_TEMPLATE.format(label=name)})
|
| 44 |
+
if out:
|
| 45 |
+
return out
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print('torchvision load failed:', e)
|
| 48 |
+
for repo in HF_CANDIDATES:
|
| 49 |
+
try:
|
| 50 |
+
from datasets import load_dataset
|
| 51 |
+
try:
|
| 52 |
+
ds = load_dataset(repo, split='train', streaming=True)
|
| 53 |
+
except Exception:
|
| 54 |
+
ds = load_dataset(repo, split='train')
|
| 55 |
+
img_dir = os.path.join(cache_dir, 'hf_images')
|
| 56 |
+
os.makedirs(img_dir, exist_ok=True)
|
| 57 |
+
for i, ex in enumerate(ds):
|
| 58 |
+
if len(out) >= max_samples:
|
| 59 |
+
break
|
| 60 |
+
txt = None
|
| 61 |
+
if TEXT_FIELD is not None and TEXT_FIELD in ex:
|
| 62 |
+
v = ex[TEXT_FIELD]
|
| 63 |
+
txt = v if isinstance(v, str) else ' '.join(map(str, v if isinstance(v, (list, tuple)) else [v]))
|
| 64 |
+
if txt is None and LABEL_FIELD in ex:
|
| 65 |
+
txt = PROMPT_TEMPLATE.format(label=ex[LABEL_FIELD])
|
| 66 |
+
if txt is None:
|
| 67 |
+
continue
|
| 68 |
+
if IMAGE_FIELD not in ex or ex[IMAGE_FIELD] is None:
|
| 69 |
+
continue
|
| 70 |
+
p = os.path.join(img_dir, str(i) + '.jpg')
|
| 71 |
+
try:
|
| 72 |
+
ex[IMAGE_FIELD].convert('RGB').save(p)
|
| 73 |
+
except Exception:
|
| 74 |
+
continue
|
| 75 |
+
out.append({'image': p, 'text': txt})
|
| 76 |
+
if out:
|
| 77 |
+
return out
|
| 78 |
+
except Exception as e:
|
| 79 |
+
print('HF load failed for', repo, ':', e)
|
| 80 |
+
print('Automatic download failed. Please get the data manually from:')
|
| 81 |
+
print(' ' + DATASET_URL)
|
| 82 |
+
return out
|
| 83 |
+
|
| 84 |
+
def build_dataset(src, dst, sz=224):
|
| 85 |
+
samples = []
|
| 86 |
+
for f in Path(src).glob('*.jsonl'):
|
| 87 |
+
with open(f, encoding="utf-8") as fp:
|
| 88 |
+
for line in fp:
|
| 89 |
+
if line.strip():
|
| 90 |
+
samples.append(json.loads(line))
|
| 91 |
+
|
| 92 |
+
if not samples:
|
| 93 |
+
samples = fetch_real_samples()
|
| 94 |
+
|
| 95 |
+
# dedup
|
| 96 |
+
seen = set()
|
| 97 |
+
unique = []
|
| 98 |
+
for s in samples:
|
| 99 |
+
fp = s.get('image', s.get('audio', ''))
|
| 100 |
+
if fp and os.path.exists(fp):
|
| 101 |
+
h = hashlib.md5(open(fp, 'rb').read()).hexdigest()
|
| 102 |
+
if h not in seen:
|
| 103 |
+
seen.add(h)
|
| 104 |
+
unique.append(s)
|
| 105 |
+
else:
|
| 106 |
+
unique.append(s)
|
| 107 |
+
|
| 108 |
+
os.makedirs(dst, exist_ok=True)
|
| 109 |
+
out = []
|
| 110 |
+
for s in unique:
|
| 111 |
+
item = {}
|
| 112 |
+
if 'image' in s:
|
| 113 |
+
from PIL import Image
|
| 114 |
+
img = Image.open(s['image']).convert('RGB').resize((sz, sz))
|
| 115 |
+
p = os.path.join(dst, os.path.basename(s['image']))
|
| 116 |
+
img.save(p, 'JPEG', quality=95)
|
| 117 |
+
item['image'] = p
|
| 118 |
+
item['text'] = s.get('wildlife', s.get('text', ''))
|
| 119 |
+
item['domain'] = 'wildlife'
|
| 120 |
+
out.append(item)
|
| 121 |
+
|
| 122 |
+
with open(os.path.join(dst, 'dataset.jsonl'), 'w', encoding="utf-8") as f:
|
| 123 |
+
for d in out:
|
| 124 |
+
f.write(json.dumps(d, ensure_ascii=False) + '\n')
|
| 125 |
+
return out
|
| 126 |
+
|
| 127 |
+
if __name__ == '__main__':
|
| 128 |
+
import sys
|
| 129 |
+
result = build_dataset(sys.argv[1], sys.argv[2])
|
| 130 |
+
print(f'Processed {len(result)} samples')
|
dataset_infos.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"description": "Metadata sample and preparation pipeline for wildlife / image_depth data",
|
| 3 |
+
"features": {
|
| 4 |
+
"id": {
|
| 5 |
+
"dtype": "string"
|
| 6 |
+
},
|
| 7 |
+
"description": {
|
| 8 |
+
"dtype": "string"
|
| 9 |
+
},
|
| 10 |
+
"label": {
|
| 11 |
+
"dtype": "int64"
|
| 12 |
+
},
|
| 13 |
+
"domain": {
|
| 14 |
+
"dtype": "string"
|
| 15 |
+
},
|
| 16 |
+
"modality": {
|
| 17 |
+
"dtype": "string"
|
| 18 |
+
}
|
| 19 |
+
},
|
| 20 |
+
"splits": {
|
| 21 |
+
"sample": {
|
| 22 |
+
"num_examples": 24
|
| 23 |
+
}
|
| 24 |
+
},
|
| 25 |
+
"release_status": "metadata sample; full source data not bundled"
|
| 26 |
+
}
|
metadata_sample.jsonl
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"id": "sample-001", "description": "schema validation example", "label": 0, "domain": "wildlife", "modality": "image_depth"}
|
| 2 |
+
{"id": "sample-002", "description": "quality-control example", "label": 1, "domain": "wildlife", "modality": "image_depth"}
|
| 3 |
+
{"id": "sample-003", "description": "split inspection example", "label": 2, "domain": "wildlife", "modality": "image_depth"}
|
| 4 |
+
{"id": "sample-004", "description": "label review example", "label": 3, "domain": "wildlife", "modality": "image_depth"}
|
| 5 |
+
{"id": "sample-005", "description": "deduplication example", "label": 0, "domain": "wildlife", "modality": "image_depth"}
|
| 6 |
+
{"id": "sample-006", "description": "format conversion example", "label": 1, "domain": "wildlife", "modality": "image_depth"}
|
| 7 |
+
{"id": "sample-007", "description": "schema validation example", "label": 2, "domain": "wildlife", "modality": "image_depth"}
|
| 8 |
+
{"id": "sample-008", "description": "quality-control example", "label": 3, "domain": "wildlife", "modality": "image_depth"}
|
| 9 |
+
{"id": "sample-009", "description": "split inspection example", "label": 0, "domain": "wildlife", "modality": "image_depth"}
|
| 10 |
+
{"id": "sample-010", "description": "label review example", "label": 1, "domain": "wildlife", "modality": "image_depth"}
|
| 11 |
+
{"id": "sample-011", "description": "deduplication example", "label": 2, "domain": "wildlife", "modality": "image_depth"}
|
| 12 |
+
{"id": "sample-012", "description": "format conversion example", "label": 3, "domain": "wildlife", "modality": "image_depth"}
|
| 13 |
+
{"id": "sample-013", "description": "schema validation example", "label": 0, "domain": "wildlife", "modality": "image_depth"}
|
| 14 |
+
{"id": "sample-014", "description": "quality-control example", "label": 1, "domain": "wildlife", "modality": "image_depth"}
|
| 15 |
+
{"id": "sample-015", "description": "split inspection example", "label": 2, "domain": "wildlife", "modality": "image_depth"}
|
| 16 |
+
{"id": "sample-016", "description": "label review example", "label": 3, "domain": "wildlife", "modality": "image_depth"}
|
| 17 |
+
{"id": "sample-017", "description": "deduplication example", "label": 0, "domain": "wildlife", "modality": "image_depth"}
|
| 18 |
+
{"id": "sample-018", "description": "format conversion example", "label": 1, "domain": "wildlife", "modality": "image_depth"}
|
| 19 |
+
{"id": "sample-019", "description": "schema validation example", "label": 2, "domain": "wildlife", "modality": "image_depth"}
|
| 20 |
+
{"id": "sample-020", "description": "quality-control example", "label": 3, "domain": "wildlife", "modality": "image_depth"}
|
| 21 |
+
{"id": "sample-021", "description": "split inspection example", "label": 0, "domain": "wildlife", "modality": "image_depth"}
|
| 22 |
+
{"id": "sample-022", "description": "label review example", "label": 1, "domain": "wildlife", "modality": "image_depth"}
|
| 23 |
+
{"id": "sample-023", "description": "deduplication example", "label": 2, "domain": "wildlife", "modality": "image_depth"}
|
| 24 |
+
{"id": "sample-024", "description": "format conversion example", "label": 3, "domain": "wildlife", "modality": "image_depth"}
|