Skip to content

Commit

Permalink
Add jina_clip processor unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xenova committed Dec 12, 2024
1 parent 37b41ee commit 32d7cc6
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/models/jina_clip/test_processor_jina_clip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { AutoProcessor, JinaCLIPProcessor } from "../../../src/transformers.js";
import { load_cached_image } from "../../asset_cache.js";

import { MAX_PROCESSOR_LOAD_TIME, MAX_TEST_EXECUTION_TIME } from "../../init.js";

export default () => {
describe("JinaCLIPProcessor", () => {
const model_id = "jinaai/jina-clip-v2";

/** @type {JinaCLIPProcessor} */
let processor;
beforeAll(async () => {
processor = await AutoProcessor.from_pretrained(model_id);
}, MAX_PROCESSOR_LOAD_TIME);

it(
"Image and text",
async () => {
// Prepare inputs
const images = [await load_cached_image("white_image"), await load_cached_image("blue_image")];
const sentences = [
"غروب جميل على الشاطئ", // Arabic
"海滩上美丽的日落", // Chinese
"Un beau coucher de soleil sur la plage", // French
"Ein wunderschöner Sonnenuntergang am Strand", // German
"Ένα όμορφο ηλιοβασίλεμα πάνω από την παραλία", // Greek
"समुद्र तट पर एक खूबसूरत सूर्यास्त", // Hindi
"Un bellissimo tramonto sulla spiaggia", // Italian
"浜辺に沈む美しい夕日", // Japanese
"해변 위로 아름다운 일몰", // Korean
];

// Encode text and images
const { input_ids, attention_mask, pixel_values } = await processor(sentences, images, { padding: true, truncation: true });

expect(input_ids.dims).toEqual([sentences.length, 19]);
expect(attention_mask.dims).toEqual([sentences.length, 19]);
expect(pixel_values.dims).toEqual([images.length, 3, 512, 512]);
expect(pixel_values.mean().item()).toBeCloseTo(0.7857685685157776, 6);
},
MAX_TEST_EXECUTION_TIME,
);
});
};

0 comments on commit 32d7cc6

Please sign in to comment.