-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
21 lines (18 loc) · 929 Bytes
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import {Clip} from './src/index.ts';
main();
async function main() {
const clip = new Clip(process.argv[2] ?? 'clip-vit-large-patch14');
const labelEmbeddings = clip.computeLabelEmbeddingsJs([ 'seagull', 'lovely dog' ]);
const imageEmbeddings = clip.computeImageEmbeddingsJs(
await clip.processImages(await Promise.all([
download('https://d29fhpw069ctt2.cloudfront.net/photo/34910/preview/u3x7cekkS16ajjtJcb5L_DSC_5869_npreviews_9e55.jpg'),
download('https://d29fhpw069ctt2.cloudfront.net/photo/35183/preview/UzWklzFdRBSbkRKhEnvc_1-6128_npreviews_79e3.jpg'),
])));
const [ scores, indices ] = Clip.computeCosineSimilarities(labelEmbeddings,
imageEmbeddings);
console.log('Cosine similarity:', scores.tolist());
}
async function download(url) {
const response = await fetch(url);
return Buffer.from(await response.arrayBuffer());
}