Skip to content

Instantly share code, notes, and snippets.

@twmht
Last active March 21, 2017 12:50
Show Gist options
  • Save twmht/36f5f2da4f78ada09d0898c86bdb3f8a to your computer and use it in GitHub Desktop.
Save twmht/36f5f2da4f78ada09d0898c86bdb3f8a to your computer and use it in GitHub Desktop.
VGG Deep Face in python
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