From 4498437025f4fd5ff2f97e972fc4e83ddac2b222 Mon Sep 17 00:00:00 2001 From: Joshua Lochner Date: Tue, 26 Dec 2023 20:13:42 +0200 Subject: [PATCH] Add semantic segmentation unit test --- tests/pipelines.test.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/pipelines.test.js b/tests/pipelines.test.js index 4d9619b65..75f1d5211 100644 --- a/tests/pipelines.test.js +++ b/tests/pipelines.test.js @@ -1164,6 +1164,7 @@ describe('Pipelines', () => { // List all models which will be tested const models = [ 'facebook/detr-resnet-50-panoptic', + 'mattmdjaga/segformer_b2_clothes', ]; it(models[0], async () => { @@ -1195,6 +1196,46 @@ describe('Pipelines', () => { await segmenter.dispose(); }, MAX_TEST_EXECUTION_TIME); + + it(models[1], async () => { + let segmenter = await pipeline('image-segmentation', m(models[1])); + let img = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/young-man-standing-and-leaning-on-car.jpg'; + + // single + { + let outputs = await segmenter(img); + + let expected = [ + { label: 'Background' }, + { label: 'Hair' }, + { label: 'Pants' }, + { label: 'Left-shoe' }, + { label: 'Right-shoe' }, + { label: 'Face' }, + { label: 'Left-leg' }, + { label: 'Right-leg' }, + { label: 'Left-arm' }, + { label: 'Right-arm' }, + ]; + + let outputLabels = outputs.map(x => x.label); + let expectedLabels = expected.map(x => x.label); + + expect(outputLabels).toHaveLength(expectedLabels.length); + expect(outputLabels.sort()).toEqual(expectedLabels.sort()) + + // check that all scores are null, and masks have correct dimensions + for (let output of outputs) { + expect(output.score).toBeNull(); + expect(output.mask.width).toEqual(970); + expect(output.mask.height).toEqual(1455); + expect(output.mask.channels).toEqual(1); + } + } + + await segmenter.dispose(); + + }, MAX_TEST_EXECUTION_TIME); }); describe('Zero-shot image classification', () => {