File size: 1,655 Bytes
50015a0
 
 
 
 
 
7cb79aa
 
465df5b
 
50015a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465df5b
50015a0
 
 
 
 
 
 
 
 
 
 
 
 
465df5b
 
 
 
 
 
50015a0
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import fs from 'node:fs/promises';
import path from 'node:path';

const IMAGES_DIR = 'static/images/full';
const THUMBS_DIR = 'static/images/thumbs';
const OUT = 'static/data/manifest.json';
const GT_DIR = 'data/GT/test';
const PRED_DIR = 'data/predictions/';
const OCR_DIR = 'data/ocr/';
const ocr_models = await fs.readdir(OCR_DIR);
const pred_models = await fs.readdir(PRED_DIR);

await fs.mkdir(THUMBS_DIR, { recursive: true });

const files = (await fs.readdir(IMAGES_DIR)).filter(f => /\.(jpe?g|png|webp)$/i.test(f));

const manifest = [];
for (const file of files) {
    const id = path.parse(file).name;

    const thumbPath = path.join(THUMBS_DIR, file.replace(/\.(\w+)$/, '.jpg'));

    // load JSONs
    const gt = JSON.parse(await fs.readFile(path.join(GT_DIR, `${id}.json`), 'utf8'));



    manifest.push({
        id,
        file,
        model: PRED_DIR.split('/').pop(),
        thumb: `/images/thumbs/${path.basename(thumbPath)}`,
        full: `/images/full/${file}`,
        ground_truth: gt,
        predictions: {
            ...Object.fromEntries(await Promise.all(pred_models.map(async pred_model => [
                pred_model,
                JSON.parse(await fs.readFile(path.join(PRED_DIR, pred_model, `${id}.json`), 'utf8'))
            ])))
        },
        ocr: {
            ...Object.fromEntries(await Promise.all(ocr_models.map(async ocr_model => [
                ocr_model,
                await fs.readFile(path.join(OCR_DIR, ocr_model, `${id}.txt`), 'utf8')
            ])))
        }
    });
}
await fs.writeFile(OUT, JSON.stringify(manifest), 'utf8');
console.log(`Wrote ${manifest.length} entries to ${OUT}`);