def getNet():
global TRANSFORMER, NET
if TRANSFORMER is None or NET is None:
import caffe
os.environ['GLOG_minloglevel'] = '2'
caffe.set_mode_cpu()
## Opening mean average image
proto_data = open(mean_path, "rb").read()
a = caffe.io.caffe_pb2.BlobProto.FromString(proto_data)
mean = caffe.io.blobproto_to_array(a)[0]
## Loading the CNN
NET = caffe.Classifier(deploy_path, model_path)
## Setting up the right transformer for an input image
TRANSFORMER = caffe.io.Transformer({'data': NET.blobs['data'].data.shape})
TRANSFORMER.set_transpose('data', (2, 0, 1))
TRANSFORMER.set_channel_swap('data', (2, 1, 0))
TRANSFORMER.set_raw_scale('data', 255.0)
TRANSFORMER.set_mean('data', mean)
print('> CNN Model loaded to regress 3D Shape and Texture!')
return TRANSFORMER, NET
评论列表
文章目录