dezoe's picture
统一数据集名称为印制电路板焊接及装联缺陷多模态数据集
ebd360f verified
Raw History Blame Contribute Delete
12.3 kB
"""Produce source inventory, review sheets and an offline dataset browser."""
import collections
import hashlib
import html
import json
from pathlib import Path
from PIL import Image, ImageOps, ImageDraw
from knowledge import KNOWLEDGE
ROOT=Path(__file__).resolve().parents[1]
def save_json(path,obj):path.write_text(json.dumps(obj,ensure_ascii=False,indent=2)+'\n')
def sha(path):
h=hashlib.sha256()
with path.open('rb') as f:
for chunk in iter(lambda:f.read(4*1024*1024),b''):h.update(chunk)
return h.hexdigest()
def sources():
records=[
('led_reliability','Reliability of High-Power LEDs and Solder Pastes','https://www.kaggle.com/datasets/andreaszippelius/hellastudy-of-leds2','data/raw/led_reliability.zip','CC BY-NC-SA 4.0','Measured SAM cracking after thermal shock and initial X-ray voiding. Matched by LED type, solder, panel, device and cycle. Thresholds are selection rules, not acceptance criteria.'),
('led_reliability_paper','Investigations on High-Power LEDs and Solder Interconnects in Automotive Application: Part II—Reliability','https://d-nb.info/1376074273/34','data/raw/led_paper.pdf','CC BY-NC-ND 4.0 (article)','Schmid et al., IEEE TDMR 23(3), 2023, pp. 419–429. Study-level mechanisms; no independently confirmed per-device cause.'),
('ulger','Solder Joint Dataset','https://github.com/furkanulger/solder-joint-dataset','data/raw/ulger.zip','not_specified','Images are source-labelled crops. No data license found in the pinned repository.'),
('soldef','SolDef_AI','https://www.kaggle.com/datasets/mauriziocalabrese/soldef-ai-pcb-dataset-for-defect-detection','data/raw/soldef.zip','GPL 3 (publisher metadata)','Version 1. Cite Fontana et al., 2024, doi:10.3390/jmmp8030117.'),
('soldef_paper','SolDef_AI paper','https://mdpi-res.com/d_attachment/jmmp/jmmp-08-00117/article_deploy/jmmp-08-00117.pdf','data/raw/soldef_paper.pdf','CC BY 4.0 (article)','Pages 9-12 establish no_good=placement defect and poor_solder=insufficient solder. Article and dataset licenses differ.'),
('aim_smt','AIM SMT Troubleshooting Guide','https://www.aimsolder.com/sites/default/files/smt_ts.pdf','data/raw/aim_smt.pdf','not_specified','Manufacturer examples and class-level causes, not sample-specific manufacturing logs.'),
('aim_wave','AIM Wave Troubleshooting Guide','https://www.aimsolder.com/wp-content/uploads/Wave_ts.pdf','data/raw/aim_wave.pdf','not_specified','Manufacturer examples and class-level troubleshooting.'),
('kester_faq','Kester FAQ','https://www.kester.com/knowledge-base/faq','data/raw/kester_faq.html','not_specified','Supplementary background. No images counted from this page.'),
('calce_cracked','CALCE Cracked Solder','https://calce.umd.edu/cracked-solder','data/raw/cracked-solder.html','not_specified','Class-level reliability and fracture mechanisms.'),
('calce_void','CALCE Solder Joint Voids','https://calce.umd.edu/solder-joint-voids','data/raw/solder-joint-voids.html','not_specified','Supplementary background; not counted as image samples.'),
('calce_cold','CALCE Cold Solder','https://calce.umd.edu/cold-solder','data/raw/cold-solder.html','not_specified','Supplementary background.'),
('calce_insufficient','CALCE Insufficient Solder','https://calce.umd.edu/insufficient-solder','data/raw/insufficient-solder.html','not_specified','Supplementary background.'),
('calce_wetting','CALCE Poor Solderability','https://calce.umd.edu/poor-solderability-leads','data/raw/poor-solderability-leads.html','not_specified','Supplementary background.'),
('technolab','TechnoLab Soldering Defect Dictionary','https://solderdict.technolab.de/','data/raw/technolab_home.html','not_specified','Each admitted figure has a direct case-context link in cases.json; acceptable examples were excluded.'),
('technolab_cold','TechnoLab Cold Solder Joints','https://solderdict.technolab.de/smd-hmd/cold-solder-joints.php','data/raw/technolab_cold-solder-joints.html','not_specified','Broad terminology includes stress cracks; original wording retained in source context.'),
('technolab_opens','TechnoLab Opens','https://solderdict.technolab.de/smd-hmd/opens.php','data/raw/technolab_opens.html','not_specified','Open and lifted-lead figure contexts.'),
('technolab_separation','TechnoLab Metallization Separation','https://solderdict.technolab.de/smd-hmd/separation.php','data/raw/technolab_separation.html','not_specified','Detachment examples concern component termination metallization.'),
('technolab_alignment','TechnoLab Alignment','https://solderdict.technolab.de/smd-hmd/deficiencies-in-component-alignment.php','data/raw/technolab_deficiencies-in-component-alignment.html','not_specified','Acceptable, borderline and pre-solder examples excluded.'),
('bobwillis_lifting','Root Causes of Component Lifting','https://pcdandf.com/pcdesign/index.php/current-issue/240-database/14841-root-causes-of-component-lifting','data/raw/lifting.html','not_specified','Bob Willis, July 2020, figure 1a/1b.'),
('huanan_failure','PCBA焊点疲劳开裂失效分析','https://www.gdhnjc.com/companyInfo/69.html','data/raw/huanan_failure.html','not_specified','Source-reported case, optical/microsection/SEM/EDS evidence grouped into one sample. Not independently verified.'),
('hf_candidate','Soldering-Data-Tiny-1004-unsolder-area','https://huggingface.co/datasets/AndyLiu0104/Soldering-Data-Tiny-1004-unsolder-area','data/raw/hf_tiny.parquet','not_specified','10,481 128px candidates excluded from valid count: black padding, possible transformed repeats, unknown acquisition and ambiguous empty labels.'),
('nasa_archive','Historical NASA workmanship pictorial reference (mirror)','https://www.dotmana.com/weblog/wp-content/uploads/NASA_workmanship_standard_pictorial_reference.pdf','data/raw/nasa_smt.pdf','mixed_not_assessed','Historical reference only, not current acceptance standard; no samples counted. Downloaded from a third-party mirror.'),
]
out=[]
for sid,title,url,file,license,note in records:
p=ROOT/file
out.append(dict(id=sid,title=title,url=url,local_file=file,license_as_observed=license,note=note,
retrieved_date_utc='2026-09-21',sha256=sha(p),bytes=p.stat().st_size))
save_json(ROOT/'data/sources.json',out)
inventory=[]
for p in sorted((ROOT/'data/raw').rglob('*')):
if p.is_file() and p.suffix!='.part':inventory.append(dict(path=str(p.relative_to(ROOT)),bytes=p.stat().st_size,sha256=sha(p)))
save_json(ROOT/'data/raw_inventory.json',inventory)
def gallery(rows):
compact=[dict(id=r['id'],image='../'+r['image'],labels=r['labels_zh'],label_ids=r['labels'],
caption=r['caption_zh'],split=r['split'],source=r['source']['source_id'],url=r['source']['page_url'],
causes=r['root_cause']['possible_causes_zh'],repair=r['repair']['steps_zh'],
modality=r['source']['modality'],evidence=[dict(image='../'+e['image'],description=e['description']) for e in r.get('additional_evidence_images',[])],
rights=r['source']['rights_status'],size=f'{r["width"]}×{r["height"]}') for r in rows]
text='''<!doctype html><html lang="zh-CN"><meta charset="utf-8"><title>印制电路板焊接及装联缺陷多模态数据集</title>
<style>body{font:16px system-ui;margin:32px;background:#eef2f5;color:#182b3a}h1{margin-bottom:8px}header{position:sticky;top:0;background:#eef2f5;padding:8px 0;z-index:1}select,input,button{font:inherit;padding:8px;margin:4px}#grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(290px,1fr));gap:16px}.card{background:white;border-radius:8px;padding:14px}.card img{width:100%;height:240px;object-fit:contain;background:#17252c}.meta{font-size:13px;color:#516273}details{margin-top:12px}a{color:#126eaa}.tag{display:inline-block;background:#dcecf6;padding:3px 7px;margin:4px 3px 4px 0;border-radius:4px}</style>
<h1>印制电路板焊接及装联缺陷多模态数据集</h1><p>原始标签与中文弱监督文本。根因多为排查假设,维修建议未逐例验证。图片和资料按各自来源授权使用。</p>
<header><select id="cls"><option value="">全部类别</option></select><select id="split"><option value="">全部划分</option><option>train</option><option>validation</option><option>test</option></select><select id="source"><option value="">全部来源</option></select><input id="q" placeholder="搜索编号、描述"><button id="prev">上一页</button><button id="next">下一页</button><span id="count"></span></header><div id="grid"></div>
<script>const DATA=__DATA__;let page=0;const $=id=>document.getElementById(id);function esc(s){return String(s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]))}
for(const c of [...new Set(DATA.flatMap(r=>r.labels))].sort())$('cls').add(new Option(c,c));for(const s of [...new Set(DATA.map(r=>r.source))].sort())$('source').add(new Option(s,s));
function render(){const a=DATA.filter(r=>(!$('cls').value||r.labels.includes($('cls').value))&&(!$('split').value||r.split===$('split').value)&&(!$('source').value||r.source===$('source').value)&&(!$('q').value||(r.id+r.caption).includes($('q').value)));page=Math.max(0,Math.min(page,Math.ceil(a.length/36)-1));$('count').textContent=`${a.length} 条 · 第 ${page+1} 页`;$('grid').innerHTML=a.slice(page*36,(page+1)*36).map(r=>`<article class="card"><a href="${esc(r.image)}"><img loading="lazy" src="${esc(r.image)}"></a><div>${r.labels.map(x=>`<span class="tag">${esc(x)}</span>`).join('')}</div><p>${esc(r.caption)}</p><div class="meta">${esc(r.id)}<br>${esc(r.source)} · ${esc(r.modality)} · ${esc(r.split)} · ${r.size}<br>${esc(r.rights)}</div>${r.evidence.length?`<details><summary>同器件/案例附加证据</summary>${r.evidence.map(e=>`<p>${esc(e.description)}</p><a href="${esc(e.image)}"><img loading="lazy" src="${esc(e.image)}"></a>`).join('')}</details>`:''}<details><summary>可能根因与维修建议</summary><p>待验证原因:${esc(r.causes.join(';'))}</p><p>条件性建议:${esc(r.repair.join(';'))}</p><a href="${esc(r.url)}" target="_blank" rel="noreferrer">原始来源</a></details></article>`).join('')}
for(const id of ['cls','split','source','q'])$(id).addEventListener('input',()=>{page=0;render()});$('prev').onclick=()=>{page--;render()};$('next').onclick=()=>{page++;render()};render();</script></html>'''
(ROOT/'reports/gallery.html').write_text(text.replace('__DATA__',json.dumps(compact,ensure_ascii=False).replace('</','<\\/')))
def sheets(rows):
selected=[]
for label in KNOWLEDGE:
candidates=sorted((r for r in rows if label in r['labels']),key=lambda r:(r['source']['source_id'],r['id']))
# All rare-category figures, spread across sources for common categories.
if len(candidates)<=12:pick=candidates
else:
bysrc=collections.defaultdict(list)
for r in candidates:bysrc[r['source']['source_id']].append(r)
pick=[]
for src,rs in bysrc.items():pick+=rs[:2]
pick=pick[:12]
for r in pick:
if r['id'] not in {x['id'] for x in selected}:selected.append(r)
save_json(ROOT/'reports/review_selection.json',[dict(id=r['id'],image=r['image'],labels=r['labels'],source=r['source']) for r in selected])
for start in range(0,len(selected),20):
chunk=selected[start:start+20]; sheet=Image.new('RGB',(1250,math_rows(len(chunk))*235),'white');d=ImageDraw.Draw(sheet)
for i,r in enumerate(chunk):
x=(i%5)*250;y=(i//5)*235
im=Image.open(ROOT/r['image']);thumb=ImageOps.contain(im,(244,184));sheet.paste(thumb,(x,y))
d.text((x,y+187),f'{start+i} '+r['primary_label'][:26],fill='black')
d.text((x,y+202),r['source']['source_id'],fill='black')
d.text((x,y+217),r['id'][-12:],fill='black')
sheet.save(ROOT/f'reports/review_{start//20+1:02}.jpg',quality=92)
def math_rows(n):return (n+4)//5
if __name__=='__main__':
rows=[json.loads(x) for x in (ROOT/'data/annotations/samples.jsonl').read_text().splitlines()]
sources();gallery(rows);sheets(rows)
print('Wrote source inventory, offline gallery and review contact sheets.')