[caffe2] How to load previously saved model

Any suggestions?

I am getting the following error [UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0x90 in position 131: ordinal not in range(128)] when following similar code to this: https://caffe2.ai/docs/tutorial-MNIST.html
Code example

workspace.ResetWorkspace()

device_opts = core.DeviceOption(caffe2_pb2.CUDA, 0)
init_def = caffe2_pb2.NetDef()
net_def = caffe2_pb2.NetDef()

with open(INIT_NET, ‘r’) as f:
init_def.ParseFromString(f.read())
init_def.device_option.CopyFrom(device_opts)
workspace.RunNetOnce(init_def.SerializeToString())

with open(PREDICT_NET, ‘r’) as f:
net_def.ParseFromString(f.read())
net_def.device_option.CopyFrom(device_opts)
workspace.CreateNet(net_def.SerializeToString(), overwrite=True)

I am getting an error in the last line

simply use

with open(PREDICT_NET, 'rb') as f

instead of

with open(PREDICT_NET, 'r') as f:

so load_net function looks like:

def LoadNet(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 f:
        net_def.ParseFromString(f.read())
        net_def.device_option.CopyFrom(device_opts)
        workspace.CreateNet(net_def.SerializeToString(), overwrite=True)
    print("== loaded init_net and predict_net. ==")

you can see the demo here