File size: 513 Bytes
8e8cbdc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import model
from transformers import pipeline
from transformers.image_utils import load_image

pipe = pipeline(
    task='sscd-copy-detection',
    model='m3/sscd-copy-detection',
    batch_size=10,
    device='cpu',
)

vec1 = pipe(load_image("http://images.cocodataset.org/val2017/000000039769.jpg"))
vec2 = pipe(load_image("http://images.cocodataset.org/val2017/000000039769.jpg"))

import torch.nn.functional as F
cos_sim = F.cosine_similarity(vec1, vec2, dim=0)
print('similarity:', round(cos_sim.item(), 3))