Giter VIP home page Giter VIP logo

Comments (4)

guillesanbri avatar guillesanbri commented on August 30, 2024 1

For reference, this is the code we have in the tests regarding this model 🙂

@pytest.mark.parametrize("batch_size", [1])
@pytest.mark.parametrize("image_dims", [[224, 224]])
def test_resnet_18_imagenet(
    batch_size,
    image_dims,
    dev,
):
    ivy.set_backend("torch")
    with DefaultDevice(dev):
        try:
            model = torch.hub.load(
                "pytorch/vision:v0.10.0", "resnet18", pretrained=True
            )
        except urllib.error.URLError:
            pytest.skip()
        net = ivy.to_ivy_module(model.to(ivy.as_native_dev(dev)))
        x0 = ivy.random_uniform(
            low=0.0,
            high=1.0,
            shape=[batch_size] + [3] + image_dims,
            dtype=torch.float32,
            device=dev,
        )
        x1 = ivy.random_uniform(
            low=0.0,
            high=1.0,
            shape=[batch_size] + [3] + image_dims,
            dtype=torch.float32,
            device=dev,
        )
        ret0_nc = net(x0)
        ret1_nc = net(x1)
        assert not np.allclose(ivy.to_numpy(ret0_nc), ivy.to_numpy(ret1_nc))
        comp_network = compile_graph(net, x0)
        show_graph(
            net,
            x0,
            # fname="resnet_18_imagenet.html",  # uncomment this to save the graph locally
        )
        ret0_c = comp_network(x0)
        ret1_c = comp_network(x1)
        assert not np.allclose(ivy.to_numpy(ret0_c), ivy.to_numpy(ret1_c))
        assert np.allclose(ivy.to_numpy(ret0_nc), ivy.to_numpy(ret0_c))
        assert np.allclose(ivy.to_numpy(ret1_nc), ivy.to_numpy(ret1_c))

from demos.

guillesanbri avatar guillesanbri commented on August 30, 2024 1

The idea is to transpile existing models, you don't have to write one in Ivy 🙂

from demos.

zhumakhan avatar zhumakhan commented on August 30, 2024

@guillesanbri I have some confusion: should resnet18 be implemented using ivy functional OR can I just load resent18 from torch.hub as in the above example?

from demos.

zhumakhan avatar zhumakhan commented on August 30, 2024

Done. https://github.com/unifyai/demos/blob/main/temp_demos/compilation_of_various_models/resnet_18.ipynb

from demos.

Related Issues (20)

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.