Open ycAlex11 opened 6 years ago
Hello @ycAlex11!
The easiest way to run inference on a single image using your model's protobuf files is by using workspace.Predictor()
like this:
# Bring up the network with the .pb files
with open(init_net_path, 'rb') as f:
INIT_NET = f.read()
with open(predict_net_path, 'rb') as f:
PREDICT_NET = f.read()
# Create Predictor object
p = workspace.Predictor(INIT_NET, PREDICT_NET)
# Test img_data (make sure it is correct shape)
results = p.run([img_data])
# results contains softmax results
results = np.asarray(results)
@MatthewInkawhich thanks for your reply, I have figured it out. but I got another problem, I am trying to save model for RNN model(char_rnn.py in caffe2), this way looks does not work !!!
Hi @ycAlex11 - what particular issue are you seeing on saving out the char_rnn model? Can you post more details here? Thanks.
@orionr Hi dude, I can not remember what was showing on terminal !! It is a holiday in China now and the code is on the host, I will look it again when I back to work. I'd like to save the model, load the model and give a input string so can generate few words follow it. The whole problem is I don't know how to save the model'weight and set the input to the model. I was trying saving by INIT_NET and PREDICT_NET. I guess predict_net.pb is forward_net(in Char_rnn). By now I could save sth into INIT_NET and PREDICT_NET, but got error for loading. So I guess it has problem during saving! I hope it does make sense. My writing is getting worse since I have graduated from uni. I am not sure it would possible to saving the char_rnn model and give a input to generate following string. If so could you give me a hint or some useful reference? Cheers
Hi @MatthewInkawhich
I have tried the code which you provided in the comment for inference of caffe2 cifar model but it throws some error do you know why this error occurs ?
Error:
File "inference.py", line 24, in
Here is the code:
import caffe2.python.predictor.predictor_exporter as pe from caffe2.proto import caffe2_pb2 from caffe2.python.predictor import mobile_exporter from caffe2.python import ( brew, core, model_helper, net_drawer, optimizer, visualize, workspace, )
with open('cifar10_init_net.pb', 'rb') as f: INIT_NET = f.read() with open('cifar10_init_net.pb', 'rb') as f: PREDICT_NET = f.read()
p = workspace.Predictor(INIT_NET, PREDICT_NET)
results = p.run([img_data])
results = np.asarray(results
@ycAlex11
I went through the tutorial of MNIST and loading squeezenet,, after I run the code , it generates a few of pbtxt files. can any one tell me would it possible to test only one image by using these pbtxt files. If it is possible, which pbtxt I should load? Is it using workspace.Predictor() and run() function loading into model?
cheers