Xray36-COCO-v1 / scripts /inspect_exported_samples.cjs
nnvff's picture
Upload complete validated Xray36 dataset, 23 image shards and provenance
ad5619c verified
Raw History Blame Contribute Delete
2.83 kB
const fs=require('fs');
const path=require('path');
const {chromium}=require('/tmp/xray-html-qa-mm5lvqo6/node_modules/playwright');
const root='/home/hmbao/datasets/Xray36_COCO_v1';
(async()=>{
const pageText=fs.readFileSync(path.join(root,'reports/quality_report.html'),'utf8');
const data=JSON.parse(pageText.match(/<script id="report-data" type="application\/json">([\s\S]*?)<\/script>/)[1]);
const report=JSON.parse(fs.readFileSync(path.join(root,'reports/report_data.json')));
const selections=[];
for(const source of ['OPIXray','HiXray','CLCXray','STCray','PIXray','PIDray','DvXray','LDXray']) selections.push({kind:'source_'+source,record:data.records.find(r=>r.datasets.includes(source))});
for(const [kind,items] of Object.entries(report.transformation_samples)) selections.push({kind,record:data.records.find(r=>r.image.id===items[0].image_id)});
const overlap=data.records.find(r=>r.cross_split_images.length>1);
if(overlap) for(const r of data.records.filter(r=>r.image.sha256===overlap.image.sha256)) selections.push({kind:'retained_cross_split_'+r.split,record:r});
const temp=fs.mkdtempSync('/tmp/xray-independent-visual-');
const browser=await chromium.launch({headless:true,executablePath:'/home/hmbao/.cache/ms-playwright/chromium_headless_shell-1254/chrome-headless-shell-linux64/chrome-headless-shell',args:['--no-sandbox'],env:{...process.env,LD_LIBRARY_PATH:'/tmp/xray-html-qa-mm5lvqo6/libs/usr/lib/x86_64-linux-gnu',FONTCONFIG_FILE:'/tmp/xray-html-qa-mm5lvqo6/fonts.conf'}});
const page=await browser.newPage({viewport:{width:1440,height:1100},deviceScaleFactor:1});
for(const s of selections){
const r=s.record;
await page.goto('http://127.0.0.1:8765/Xray36_COCO_v1/reports/quality_report.html?split='+r.split+'&image='+r.image.id);
await page.waitForFunction(()=>document.querySelector('#picture svg image')&&current!==null);
await page.evaluate(async()=>{const src=document.querySelector('#picture svg image').getAttribute('href'); const im=new Image(); im.src=src; await im.decode();});
s.screenshot=path.join(temp,s.kind+'.png');
await page.locator('#viewer-grid').screenshot({path:s.screenshot});
console.log(JSON.stringify({kind:s.kind,image_id:r.image.id,split:r.split,screenshot:s.screenshot,file_name:r.image.file_name,annotations:r.annotations.map(a=>({id:a.id,category_id:a.category_id,bbox:a.bbox,source:a.sources.map(x=>({source_bbox:x.source_bbox,conversion_origin:x.conversion_origin,source_split:x.source_split,clipped:x.clipped}))}))}));
}
await browser.close();
fs.writeFileSync(path.join(root,'reports/independent_visual_review_selection.json'),JSON.stringify({status:'captured_pending_human_style_visual_review',generated_at:new Date().toISOString(),temporary_capture_directory:temp,selections},null,2));
})().catch(e=>{console.error(e);process.exit(1)});