def __init__(self, videoThread):
threading.Thread.__init__(self)
print "Initializing age recognition thread..."
self.videoThread = videoThread
#caffe.set_mode_cpu()
caffe.set_mode_gpu()
# Model file and parameters are written by trainDnn.py
# Take the most recent parameter set
dcnnPath = "./dcnn_age"
paramFiles = glob.glob(dcnnPath + os.sep + "*.caffemodel")
paramFiles = sorted(paramFiles, key=lambda x:os.path.getctime(x))
MODEL_FILE = dcnnPath + os.sep + "deploy.prototxt"
PRETRAINED = paramFiles[-1]
MEAN_FILE = dcnnPath + os.sep + "mean.binaryproto"
blob = caffe.proto.caffe_pb2.BlobProto()
with open(MEAN_FILE, 'rb') as f:
data = f.read()
blob.ParseFromString(data)
# mean = np.array( caffe.io.blobproto_to_array(blob) ) [0]
# Added simple mean
mean = np.array([93.5940, 104.7624, 129.1863])
# Initialize net
self.net = caffe.Classifier(MODEL_FILE, PRETRAINED, image_dims=(224,224), mean=mean)
评论列表
文章目录