Skip to content

Instantly share code, notes, and snippets.

@twmht
twmht / demo.py
Last active March 21, 2017 12:50
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)
@twmht
twmht / write_mnist_data_to_lmdb.py
Created July 19, 2016 03:05
Write mnist image to lmdb with python
from mnist import MNIST
import numpy as np
import cv2
import lmdb
import caffe
mndata = MNIST('./data')
images, labels = mndata.load_training()
labels = np.array(labels)
images = np.array(images).reshape(len(labels), 28, 28).astype(np.uint8)
@twmht
twmht / loader.py
Last active July 21, 2016 15:53
much faster
import os
import struct
from array import array
import numpy as np
class MNIST(object):
def __init__(self, path='.'):
self.path = path
from mnist import MNIST
import numpy as np
import lmdb
import caffe
mndata = MNIST('./data')
count = 0
env = lmdb.open('mnist_lmdb', map_size=1000*1000*1000)
txn = env.begin(write=True)
@twmht
twmht / create_numbers.py
Last active July 29, 2016 14:51
create number with background
import glob
from collections import defaultdict
import cv2
import numpy as np
import random
char2num = {
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8,
'9': 9, 'A': 10, 'B': 12, 'C': 13, 'D': 14, 'E': 15, 'F': 16, 'G': 17,
'H': 18, 'I': 19, 'J': 20, 'K': 21, 'L': 23, 'M': 24, 'N': 25, 'O': 26,
@twmht
twmht / font.py
Created August 3, 2016 11:39
font
import PIL
import cv2
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
import string
import os
import shutil
import random
from collections import defaultdict
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 6 10:13:27 2016
@author: gene
"""
import xml.etree.cElementTree as ET
import Image
import os, glob
@twmht
twmht / wider.py
Last active January 8, 2017 01:21
h5py for wider
import numpy as np, h5py
from collections import defaultdict
import os
f = h5py.File('wider_face_train.mat','r')
event_list = f.get('event_list')
print f[event_list.value[0][0]].value.tostring()
# for i in range(0, 61):
# print f[event_list.value[0][i]].value.tostring()
@twmht
twmht / README
Created May 11, 2017 13:33
cuda example
/usr/local/cuda/bin/nvcc -c file1.cu
g++ -c file2.cpp
g++ -o test file1.o file2.o -L/usr/local/cuda/lib64 -lcudart
./test
@twmht
twmht / DeepLearningFaces.md
Created June 8, 2017 09:19 — forked from jdsgomes/DeepLearningFaces.md
Deep Learning for Face Recognition

Deep Learning for Face Recognition (May 2016)

Popular architectures

  • FaceNet (Google)
    • They use a triplet loss with the goal of keeping the L2 intra-class distances low and inter-class distances high
  • DeepID (Hong Kong University)
    • They use verification and identification signals to train the network. Afer each convolutional layer there is an identity layer connected to the supervisory signals in order to train each layer closely (on top of normal backprop)
  • DeepFace (Facebook)
    • Convs followed by locally connected, followed by fully connected