Giter Site home page Giter Site logo

Comments (4)

Bixiii avatar Bixiii commented on May 29, 2024 1

You can use the torch.onnx package.

When you have your trained OFA network as ofa_network you can sample a random subnet with ofa_network.sample_active_subnet() than you can cut that network with subnet = ofa_network.get_active_subnet(). Don't forget to reset the batch norm statistics reset_running_statistics(net=subnet) . Then you can export it like any model.

torch.onnx.export(
    subnet,
    torch.randn(1, 3, 224, 224),
    'model_name.onnx',
    export_params=True,
)

from once-for-all.

Darshcg avatar Darshcg commented on May 29, 2024

Yes, I do have the same Question.

from once-for-all.

detectRecog avatar detectRecog commented on May 29, 2024

You can use the torch.onnx package.

When you have your trained OFA network as ofa_network you can sample a random subnet with ofa_network.sample_active_subnet() than you can cut that network with subnet = ofa_network.get_active_subnet(). Don't forget to reset the batch norm statistics reset_running_statistics(net=subnet) . Then you can export it like any model.

torch.onnx.export(
    subnet,
    torch.randn(1, 3, 224, 224),
    'model_name.onnx',
    export_params=True,
)

How to extract the subnet according to these preset configs like "pixel2_lat@[email protected]_finetune@25"? After I load the big OFA pretrained on a custom dataset, I can not figure out how to get the subnet according to the preset config.

from once-for-all.

Bixiii avatar Bixiii commented on May 29, 2024

You can use the torch.onnx package.
When you have your trained OFA network as ofa_network you can sample a random subnet with ofa_network.sample_active_subnet() than you can cut that network with subnet = ofa_network.get_active_subnet(). Don't forget to reset the batch norm statistics reset_running_statistics(net=subnet) . Then you can export it like any model.

torch.onnx.export(
    subnet,
    torch.randn(1, 3, 224, 224),
    'model_name.onnx',
    export_params=True,
)

How to extract the subnet according to these preset configs like "pixel2_lat@[email protected]_finetune@25"? After I load the big OFA pretrained on a custom dataset, I can not figure out how to get the subnet according to the preset config.

I' have not tried this myself, but I would try something like this

Either:

Write a script that generates an architecture configuration as needed by this function
from the net.config file. Then do everything as described previously.

Or:

Create a model with the desired architecture, as it is done here. In your example for net_id use "pixel2_lat@[email protected]_finetune@25".

Now a little work is needed. You need to load the weights from your OFA network into the subnetwork. Therefore, you need to write a function similar to this. But only load the values from your OFA network that are needed in the subnet architecture.
You also have to reset_running_statistics() for the subnet.

Then you can export the subnetwork as described previously.

from once-for-all.

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.