haorancyf commited on
Commit
3a183ad
·
verified ·
1 Parent(s): 8935a7c

Upload 2 files

Browse files
README.md ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ tags:
4
+ - adaptive
5
+ - architecture
6
+ - jsonl
7
+ - leave-one-out
8
+ - mixup-cutmix
9
+ - pointcloud-text
10
+ - self-training
11
+ - standard
12
+ - stratified
13
+ ---
14
+
15
+ # dataset_055326048_architecture_pointcloud_text.py
16
+
17
+ ## Dataset Summary
18
+
19
+ A **architecture** dataset with **pointcloud text** modality, stored in **jsonl** format.
20
+
21
+ ## Preprocessing & Augmentation
22
+
23
+ - **Preprocessing**: standard
24
+ - **Augmentation**: mixup cutmix
25
+
26
+ ## Splits & Sampling
27
+
28
+ - **Split strategy**: leave one out
29
+ - **Sampling**: stratified
30
+
31
+ ## Quality & Labeling
32
+
33
+ - **Quality filtering**: adaptive
34
+ - **Labeling**: self training
35
+
36
+ ## Files
37
+
38
+ - `dataset_055326048_architecture_pointcloud_text.py` — main artifact of this repository
39
+
40
+ ## License
41
+
42
+ See the license field above.
dataset_055326048_architecture_pointcloud_text.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json, os, hashlib
2
+ from pathlib import Path
3
+
4
+ # architecture dataset processor
5
+ # modality: pointcloud_text, preprocessing: standard
6
+
7
+
8
+ # --- real data source: architecture ---
9
+ TV_DATASET = 'SUN397'
10
+ HF_CANDIDATES = []
11
+ IMAGE_FIELD = 'image'
12
+ TEXT_FIELD = None
13
+ LABEL_FIELD = 'label'
14
+ PROMPT_TEMPLATE = 'a photo of {label} architecture'
15
+ DATASET_URL = 'https://vision.princeton.edu/projects/2010/SUN/'
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) 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('architecture', s.get('text', ''))
119
+ item['domain'] = 'architecture'
120
+ out.append(item)
121
+
122
+ with open(os.path.join(dst, 'dataset.jsonl'), 'w') 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')