Views
No views yet
1import {
2 AutoModel,
3 AutoProcessor,
4 load_image
5} from '@huggingface/transformers';
6
7// require 50% confidence in watermark presence
8const threshold = 0.5;
9// name of this model
10const modelId = 'ayan4m1/Watermark-Detection-YOLO11-ONNX';
11
12// load it using AutoModel and AutoProcessor
13const model = await AutoModel.from_pretrained(modelId, { dtype: 'fp32' });
14const processor = await AutoProcessor.from_pretrained(modelId);
15
16let watermarked = false;
17
18// load the image and run inference
19const image = await load_image(file);
20const inputs = await processor(image);
21const { output0 } = await model({ images: inputs.pixel_values });
22
23// unpack the results
24const permuted = output0[0].transpose(1, 0);
25for (const row of permuted.tolist()) {
26 // data shape represents a bounding box [xCenter, yCenter, width, height, watermarkProbability]
27 const score = row[4];
28
29 if (score < threshold) {
30 continue;
31 }
32
33 watermarked = true;
34 break;
35}
36
37if (watermarked) {
38 ...
39} else {
40 ...
41}