資源簡(jiǎn)介
模仿百度以圖搜圖功能/淘寶的拍立淘功能,使用的模型vgg-16,環(huán)境配置完畢可以直接使用,有問題歡迎交流。
開發(fā)環(huán)境:
# 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?‘a(chǎn)vg‘
????????#?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
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????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
評(píng)論
共有 條評(píng)論