-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcv.py
28 lines (24 loc) · 776 Bytes
/
cv.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from keras.applications import VGG16,resnet50
from keras.models import Model
from keras.preprocessing import image
from scipy.linalg import norm
def extract_feature(img_path):
input_shape = (224,224,3)
model = VGG16()
model.layers.pop()
print(model.inputs)
model = Model(inputs=model.inputs,outputs=model.layers[-1].output)
img = image.load_img(img_path,target_size=(224,224,3))
img = np.expand_dims(img,axis=0)
# img = preprocess_input(img)
feature =model.predict(img)
print(feature.shape)
norm_feat = feature[0] / norm(feature[0])
# return feature
return norm_feat
if __name__ == '__main__':
# extract_feature('4.jpg')
model=resnet50.ResNet50()