-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentificationNet.py
More file actions
46 lines (36 loc) · 1.38 KB
/
identificationNet.py
File metadata and controls
46 lines (36 loc) · 1.38 KB
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
35
36
37
38
39
40
41
42
43
44
45
from tensorflow.keras.layers import Input, Lambda, Dense, Flatten
from tensorflow.keras.models import Model
from tensorflow.keras.regularizers import l2
from tensorflow.keras import backend as K
import cv2
from tensorflow import keras
import os
import logging
import numpy as np
def get_embeddingNetwork(input_shape=(96,96,3), embedding_size=4096):
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # FATAL
logging.getLogger('tensorflow').setLevel(logging.FATAL)
base_model = keras.applications.VGG16(
include_top=False,
weights=None,
input_shape=input_shape
)
inputs = Input(shape=input_shape)
x = base_model(inputs)
x=Flatten()(x)
x = Dense(embedding_size, activation='sigmoid',kernel_regularizer=l2(2e-4))(x)
outputs = Lambda(lambda x: K.l2_normalize(x,axis=-1)) (x)
embeddingNetwork = Model(inputs, outputs)
return(embeddingNetwork)
def compute_dist(a,b):
return np.sum(np.square(a-b))
def prepareSavedImageForSiameseEmbedding(image, RESIZE):
img = cv2.imread(image)
img = cv2.resize(img, (RESIZE, RESIZE))
img = (img - img.mean(axis=(0,1)))/img[0].std(axis=(0,1))
img = img.reshape(-1, RESIZE, RESIZE, 3)
return img
def prepareNumpyImageForSiameseEmbedding(image, RESIZE):
img = (image - image.mean(axis=(0,1)))/image.std(axis=(0,1))
img = img.reshape(-1, RESIZE, RESIZE, 3)
return img