-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
28 lines (21 loc) · 867 Bytes
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import cv2
import numpy as np
from models.generic_models import TransformerHash
org_path = 'examples/original.jpg'
aug_path = 'examples/benign.jpg'
pho_path = 'examples/manipulated.jpg'
WEIGHT = 'weight/best.pt'
if __name__ == '__main__':
ims = [cv2.imread(path, cv2.IMREAD_COLOR) for path in (org_path, aug_path, pho_path)]
gtn = TransformerHash(WEIGHT)
feats = gtn.hash(ims)
aug_dist = np.bitwise_xor(feats[0], feats[1]).sum()
pho_dist = np.bitwise_xor(feats[0], feats[2]).sum()
print(f'Hamming ({os.path.basename(org_path)}, {os.path.basename(aug_path)}): {aug_dist}')
print(f'Hamming ({os.path.basename(org_path)}, {os.path.basename(pho_path)}): {pho_dist}')