This repository contains the following models converted from Tensorflow to PyTorch:
progamergov / pytorch-old-tensorflow-models Goto Github PK
View Code? Open in Web Editor NEWModels from Tensorflow and Keras converted to PyTorch
Models from Tensorflow and Keras converted to PyTorch
This repository contains the following models converted from Tensorflow to PyTorch:
Hey,
first I want to thank you for creating the Repo, it was very helpful so far for me.
Now I started looking into the exact output of the torch model and compared it with the TensorFlow model, however, they don't seem to match.
Could you please explain how you converted the TensorFlow model to Pytorch and that the proper input should be?
This is how I use it on the torch side
model = Inception5h()
fileurl = "https://github.com/ProGamerGov/pytorch-old-tensorflow-models/raw/master/inception5h.pth"
model.load_state_dict(load_state_dict_from_url(fileurl))
np.random.seed(0)
input_image = np.float32(np.random.randn(224, 224, 3))
torch_input = transforms.ToTensor()(input_image).unsqueeze_(0)
output = model(torch_input)
output_np = output.detach().numpy()
np.save("torch_output.npy", output_np)
and on the tensorflow side:
graph = tf.Graph()
sess = tf.InteractiveSession(graph=graph)
t_input = tf.placeholder(np.float32, name="our_input") # define the input tensor
t_preprocessed = tf.expand_dims(t_input, 0)
with gfile.FastGFile("./tensorflow_inception_graph.pb", "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, {"input": t_preprocessed})
def T(layer_name):
return graph.get_tensor_by_name("import/%s:0" % layer_name)
np.random.seed(0)
input_image = np.float32(np.random.randn(224, 224, 3))
softmax = T("softmax2")
output = sess.run(softmax, {t_input: input_image})
np.save("tf_output.npy", output)
If I compare the resulting output it is not identical, is this expected or am I missing something?
Thanks for your feedback!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.