-
-
Save tsingjinyun/239c80fe6350a59f6b4272fe241b88ec to your computer and use it in GitHub Desktop.
VGG Deep Face in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import caffe | |
import numpy as np | |
# http://stackoverflow.com/questions/33828582/vgg-face-descriptor-in-python-with-caffe | |
img = caffe.io.load_image( "ak.png" ) | |
img = img[:,:,::-1]*255.0 # convert RGB->BGR | |
avg = np.array([129.1863,104.7624,93.5940]) | |
img = img - avg # subtract mean (numpy takes care of dimensions :) | |
img = img.transpose((2,0,1)) | |
img = img[None,:] # add singleton dimension | |
net = caffe.Net("VGG_FACE_deploy.prototxt","VGG_FACE.caffemodel", caffe.TEST) | |
out = net.forward_all( data = img ) | |
caffe_fc8 = net.blobs['fc8'].data[0] | |
r2 = np.argmax(caffe_fc8) | |
names = open('names.txt') | |
names = names.readlines() | |
print names[r2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment