VGGFace python 抽取人脸特征
来源:互联网 发布:淘宝抢月饼 编辑:程序博客网 时间:2024/05/29 15:21
“`
import numpy,cv2
import os,caffe
import sklearn.metrics.pairwise as pw
import time,skimage
import matplotlib.pyplot as plt
import numpy as np
class LightCNN():
def init(self, end_cnn=”eltwise_fc1”, model_version=”LightenedCNN_B”):
self.net = caffe.Net(“VGG_FACE_deploy.prototxt”,”VGG_FACE.caffemodel”, caffe.TEST) #load net
self.end_cnn=”fc7”
self.model_version = model_version
def getFeat(self, imgPath): ''' img = caffe.io.load_image(imgPath,color=False) img = skimage.img_as_float(skimage.io.imread(imgPath, as_grey=not False)).astype(np.float32) if img.ndim == 2: print "img.ndim =sss= 2" img = img[:, :, np.newaxis] #img = cv2.imread(imgPath,0) print "img.ndim===<<><<" + str(img.ndim) img = cv2.resize(img,(128,128)) print img.shape #img.convertTo(img, cv2.CV_32FC1); #img = img.reshape(128,128) assert img.ndim == 2 #assert img.max() <= 1.001 h, w = img.shape assert h == w == 128 formatted_image = numpy.reshape(img, (1, 1, h, w)).astype(float) output = self.net.forward([self.end_cnn], data=formatted_image) return output[self.end_cnn].copy().flatten() averageImg = [129.1863,104.7624,93.5940] image = caffe.io.load_image( "ak.png" ) #RGB #img = cv2.imread("ak.png" ) #plt.imshow(img) #plt.show() #cv2.imshow("img",img) #cv2.waitKey(0) #img = img[:,:,::-1]*255.0 # convert RGB->BGR R = image[0, :, :] - averageImg[0] G = image[1, :, :] - averageImg[1] B = image[2, :, :] - averageImg[2] bgr_image = numpy.zeros(shape=image.shape) bgr_image[0, :, :] = B bgr_image[1, :, :] = G bgr_image[2, :, :] = R ''' #image = caffe.io.load_image( "ak.png" ) #image = image[:,:,::-1]*255.0 # convert RGB->BGR image = cv2.imread("q1.jpg" ) #opencv is BRG avg = np.array([93.5940,104.7624,129.1863]) #substract by BGR image = image - avg # subtract mean (numpy takes care of dimensions :) #img = img - avg # subtract mean (numpy takes care of dimensions :) image = image.transpose((2,0,1)) ## equal to permute image = image[None,:] # add singleton dimension out = self.net.forward([self.end_cnn], data=image) return out['fc7'] #labels=np.loadtxt('names.txt',str,delimiter='\n') # get the name #print labels[out['prob'].argmax()]
cnn = LightCNN()
for r in [i/10.0 for i in range(10)]:
#print r
imgPath = “ak.png”
t1 = time.time()
feat = cnn.getFeat(imgPath)
for f in feat:
for i in f:
print i
”’
feat2 = cnn.getFeat(“E://19.jpg”)
print (feat)
t2 = time.time()
print len(feat),t2 - t1
predicts=pw.cosine_similarity(feat, feat2)
t2 = time.time()
print predicts,t2 - t1
”’
阅读全文
0 0
- VGGFace python 抽取人脸特征
- SphereFace python抽取人脸特征
- caffe -- Python特征抽取
- 基于PCA的人脸特征抽取
- LightCNN C++接口抽取人脸特征
- caffe python批量抽取图像特征
- caffe python 批量抽取图像特征---续篇
- caffe python批量抽取图像特征
- Caffe 抽取CNN网络特征 Python
- 特征选择与特征抽取
- 特征抽取与特征选择
- 特征抽取与特征选择
- 特征提升之特征抽取
- 特征抽取概述
- 模式特征抽取研究进展
- pca 特征抽取
- 从文本抽取特征
- pca 特征抽取
- 【Scikit-Learn 中文文档】处理文本数据
- @RequestBody使用
- jena解析关于基因的go.owl文件(正在学习中)
- 说说canvas吧(一):paint
- Python 使用 pandas 进行数据分析
- VGGFace python 抽取人脸特征
- simple Android EventBus code
- 【Scikit-Learn 中文文档 】安装 scikit-learn | ApacheCN
- mint ui必填下拉验证
- Your ApplicationContext is unlikely to start due to a @ComponentScan of the default
- Cent7开机自动联网设置
- spring中bean配置和bean注入
- Kafka Java Consumer实现(二)
- httpcilent连接第三方接口请求(post,get)