Reputation: 91
Since ONNX supports limited models, I tried to do this conversion by assigning parameters directly, but the gained tensorflow model failed to show the desired accuracy. Details are described as follows:
However, the accuracy of gained tensorflow model is only about 20%. Thus, my question is that is it possible to convert the pytorch model by this method?. If yes, what's the possible issue causing the bad result? If no, then please kindly explain the reasons.
PS: assume the assignment procedure is right.
Upvotes: 1
Views: 3383
Reputation: 295
As the comment by jodag mentioned, there are many differences between operator representations in Tensorflow and PyTorch that might cause discrepancies in your workflow.
We would recommend using the following method:
import torch.onnx
# Argument: model is the PyTorch model
# Argument: dummy_input is a torch tensor
torch.onnx.export(model, dummy_input, "LeNet_model.onnx")
import onnx
from onnx_tf.backend import prepare
onnx_model = onnx.load("LeNet_model.onnx") # load onnx model
tf_rep = prepare(onnx_model) # prepare tf representation
tf_rep.export_graph("LeNet_model.pb") # export the model
Upvotes: 3