资源简介
模仿百度以图搜图功能/淘宝的拍立淘功能,使用的模型vgg-16,环境配置完毕可以直接使用,有问题欢迎交流。
开发环境:
# windows 10
# tensorflow-gpu 1.8 + keras
# python 3.6
代码片段和文件信息
# -*- coding: utf-8 -*-
import numpy as np
from numpy import linalg as LA
from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
class VGGNet:
def __init__(self):
# weights: ‘imagenet‘
# pooling: ‘max‘ or ‘avg‘
# input_shape: (width height 3) width and height should >= 48
self.input_shape = (224 224 3)
self.weight = ‘imagenet‘
self.pooling = ‘max‘
self.model = VGG16(weights = self.weight input_shape = (self.input_shape[0] self.input_shape[1] self.input_shape[2]) pooling = self.pooling include_top = False)
self.model.predict(np.zeros((1 224 224 3)))
‘‘‘
Use vgg16 model to extract features
Output normalized feature vector
‘‘‘
def extract_feat(self img_path):
img = image.load_img(img_path target_size=(self.input_shape[0] self.input_shape[1]))
img = image.img_to_array(img)
img = np.expand_dims(img axis=0)
img = preprocess_input(img)
feat = self.model.predict(img)
norm_feat = feat[0]/LA.norm(feat[0])
return norm_feat
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-10-22 20:23 ImageRetrieval\
文件 1202 2018-09-16 21:10 ImageRetrieval\extract_cnn_vgg16_keras.py
文件 1727 2018-09-16 21:11 ImageRetrieval\index.py
文件 1748 2018-09-16 21:12 ImageRetrieval\query_online.py
文件 467 2018-10-22 20:24 ImageRetrieval\ReadMe.txt
- 上一篇:pid code python
- 下一篇:python五子棋双人对战
评论
共有 条评论