-
Notifications
You must be signed in to change notification settings - Fork 74
/
pre.py
34 lines (24 loc) · 854 Bytes
/
pre.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
29
30
31
32
33
34
import cv2
import numpy as np
from keras.models import load_model
from keras.layers import Lambda
from keras import backend as K
import os
import random
from PIL import Image
input1 = input('请输入图片名称1:')
input2 = input('请输入图片名称2:')
output = Lambda(lambda x: K.abs(x[0] - x[1]))
weight = "./best.h5"
# 加载模型
# model = load_model(weight, custom_objects={'contrastive_loss': contrastive_loss, 'binary_accuracy': binary_accuracy})
model = load_model(weight, custom_objects={'output': output})
resize = 52
img1 = cv2.imread(input1)
img2 = cv2.imread(input2)
img1 = cv2.resize(img1, (resize, resize)) / 255
img2 = cv2.resize(img2, (resize, resize)) / 255
img1 = np.expand_dims(img1, axis=0)
img2 = np.expand_dims(img2, axis=0)
result = model.predict([img1, img2])
print(result)