Open pjoshi0621 opened 5 years ago
from caffe2.python import workspace, core from caffe2.proto import caffe2_pb2 import logging
logging.getLogger().setLevel(logging.ERROR)
def load_net(INIT_NET, PREDICT_NET, device_opts):
workspace.ResetWorkspace()
# Load the initialization network
init_def = caffe2_pb2.NetDef()
with open(INIT_NET, 'rb') as f:
init_def.ParseFromString(f.read())
init_def.device_option.CopyFrom(device_opts)
workspace.RunNetOnce(init_def.SerializeToString())
# Load the prediction network
net_def = caffe2_pb2.NetDef()
with open(PREDICT_NET, 'rb') as f1:
net_def.ParseFromString(f1.read())
net_def.device_option.CopyFrom(device_opts)
workspace.CreateNet(net_def.SerializeToString(), overwrite=True)
INIT_NET = 'model_init.pb' PREDICT_NET = 'model.pb' device_opts = core.DeviceOption(caffe2_pb2.CPU, 0)
load_net(INIT_NET, PREDICT_NET, device_opts)
I am using Detectron retinanet to train a model. As a result of training, I am getting a ".pkl" file as an output. Then, I have converted it to ".pb" file. And got two files "model_init.pb" and model.pb. So, now I am trying to load a model using this ".pb" file. For that I am using the below code: import sys reload(sys) sys.setdefaultencoding('Cp1252')
from caffe2.python import workspace, core from caffe2.proto import caffe2_pb2
def load_net(INIT_NET, PREDICT_NET, device_opts):
init_def = caffe2_pb2.NetDef() with open(INIT_NET,'rb') as f: init_def.ParseFromString(f.read()) init_def.device_option.CopyFrom(device_opts) workspace.RunNetOnce(init_def.SerializeToString())
net_def = caffe2_pb2.NetDef() with open(PREDICT_NET, 'rb') as f1: net_def.ParseFromString(f1.read()) net_def.device_option.CopyFrom(device_opts) workspace.CreateNet(net_def.SerializeToString(), overwrite=True) INIT_NET = 'model_init.pb' PREDICT_NET = 'model.pb' device_opts = core.DeviceOption(caffe2_pb2.CPU, 0) load_net(INIT_NET, PREDICT_NET, device_opts)
While executing this script it gives me this error: No handlers could be found for logger "caffe2.python.workspace" Traceback (most recent call last): File "read_pb_file.py", line 32, in load_net(INIT_NET, PREDICT_NET, device_opts) File "read_pb_file.py", line 26, in load_net workspace.CreateNet(net_def.SerializeToString(), overwrite=True) File "/home/abcd/anaconda2/lib/python2.7/site-packages/caffe2/python/workspace.py", line 154, in CreateNet StringifyProto(net), overwrite, File "/home/abcd/anaconda2/lib/python2.7/site-packages/caffe2/python/workspace.py", line 180, in CallWithExceptionIntercept return func(*args, **kwargs) RuntimeError: [enforce fail at net.cc:69] . op BBoxTransform: Source for input rpn_rois is unknown for net detectron, operator input: "rpn_rois" input: "bbox_pred" input: "im_info" output: "pred_bbox" name: "" type: "BBoxTransform" arg { name: "correct_transform_coords" i: 1 } arg { name: "apply_scale" i: 0 } arg { name: "weights" floats: 10 floats: 10 floats: 5 floats: 5 } Please help me to solve this issue.