AgeThread.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:live-age-gender-estimator 作者: taipalma 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号