Coder Social home page Coder Social logo

progamergov / pytorch-old-tensorflow-models Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 149.65 MB

Models from Tensorflow and Keras converted to PyTorch

Python 100.00%
pytorch tensorflow inception-v1 inception5h mmdnn pytorch-models inception5h-pytorch model-zoo keras keras-tensorflow

pytorch-old-tensorflow-models's Introduction

pytorch-old-tensorflow-models

This repository contains the following models converted from Tensorflow to PyTorch:

pytorch-old-tensorflow-models's People

Contributors

progamergov avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

alexus37

pytorch-old-tensorflow-models's Issues

Question

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!

Selection_064

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.