Skip to content

Instantly share code, notes, and snippets.

@Patriciasr92
Forked from twmht/demo.py
Created September 30, 2016 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Patriciasr92/6e3d352c31c8826d5352f849523528d6 to your computer and use it in GitHub Desktop.
Save Patriciasr92/6e3d352c31c8826d5352f849523528d6 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