From 983c502554d3fe92d426759d2b0b46de2496703c Mon Sep 17 00:00:00 2001 From: Joshua Lochner Date: Wed, 15 Nov 2023 01:42:58 +0200 Subject: [PATCH] Add owlvit processor test --- tests/processors.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/processors.test.js b/tests/processors.test.js index fe594613e..6cbb6a6b1 100644 --- a/tests/processors.test.js +++ b/tests/processors.test.js @@ -38,6 +38,7 @@ describe('Processors', () => { beit: 'microsoft/beit-base-patch16-224-pt22k-ft22k', detr: 'facebook/detr-resnet-50', yolos: 'hustvl/yolos-small-300', + owlvit: 'google/owlvit-base-patch32', } const TEST_IMAGES = { @@ -45,6 +46,7 @@ describe('Processors', () => { checkerboard_8x8: 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/checkerboard_8x8.png', receipt: 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/receipt.png', tiger: 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg', + cats: 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/cats.jpg', // grayscale image skateboard: 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/ml-web-games/skateboard.png', @@ -236,5 +238,22 @@ describe('Processors', () => { compare(reshaped_input_sizes, [[888, 1333]]); } }, MAX_TEST_EXECUTION_TIME); + + + // OwlViTFeatureExtractor + it(MODELS.owlvit, async () => { + const processor = await AutoProcessor.from_pretrained(m(MODELS.owlvit)) + + { + const image = await load_image(TEST_IMAGES.cats); + const { pixel_values, original_sizes, reshaped_input_sizes } = await processor(image); + + compare(pixel_values.dims, [1, 3, 768, 768]); + compare(avg(pixel_values.data), 0.250620447910435); + + compare(original_sizes, [[480, 640]]); + compare(reshaped_input_sizes, [[768, 768]]); + } + }, MAX_TEST_EXECUTION_TIME); }); });