Coder Social home page Coder Social logo

Comments (14)

yformer avatar yformer commented on July 17, 2024 2

@ArielleBF, @ximitiejiang, @chenin-wang, @alanzhai219, @fPecc, @kaka-lin, @lxfater, @mchaniotakis, EfficientSAM onnx files are available at Hugging Face Space. The export script and running example are provided. Feel free to give it a try.

from efficientsam.

kaka-lin avatar kaka-lin commented on July 17, 2024 2

@ArielleBF, @ximitiejiang, @chenin-wang, @alanzhai219, @fPecc, @kaka-lin, @lxfater, @mchaniotakis, EfficientSAM onnx files are available at Hugging Face Space. The export script and running example are provided. Feel free to give it a try.

Thanks yformer ~

I also create TensorFlow2.x version and coverted to tflite model
If anyone need to use tflite to inference please check here EfficientSAM-tf2-demo.

Thanks!!!

from efficientsam.

yacineMTB avatar yacineMTB commented on July 17, 2024 1

Thanks yformer <3
FYI for other readers; the export tooling is on this repository

def export_onnx_esam_encoder(model, output):
onnx_model = onnx_models.OnnxEfficientSamEncoder(model=model)
dynamic_axes = {
"batched_images": {0: "batch", 2: "height", 3: "width"},
}
dummy_inputs = {
"batched_images": torch.randn(1, 3, 1080, 1920, dtype=torch.float),
}
output_names = ["image_embeddings"]
export_onnx(
onnx_model=onnx_model,
output=output,
dynamic_axes=dynamic_axes,
dummy_inputs=dummy_inputs,
output_names=output_names,
)

from efficientsam.

ximitiejiang avatar ximitiejiang commented on July 17, 2024

same question.

from efficientsam.

yformer avatar yformer commented on July 17, 2024

@ArielleBF @ximitiejiang can you share more information on the export? I will try to export one and share it.

from efficientsam.

ArielleBF avatar ArielleBF commented on July 17, 2024

@ArielleBF @ximitiejiang can you share more information on the export? I will try to export one and share it.
When I try to export the image_encoder model using torch.onnx.export, a bug occurred.It is possible that the bug is caused by incompatibility between the jit format file and onnx during the export.

from efficientsam.

ximitiejiang avatar ximitiejiang commented on July 17, 2024

hello, i tried to export onnx with below codes which are similiar with SAM

def export_onnx():
    model = torch.jit.load('efficientsam_s_gpu.jit')
    output = "efficientsam_s_gpu.onnx"
    output_names = ["masks_predictions", "iou_predictions"]
    dummy_inputs = {
        "images": torch.randn((1, 3, 1024, 1024), dtype=torch.float),
        "point_coords": torch.randint(low=0, high=1024, size=(1, 1, 5, 2), dtype=torch.float),
        "point_labels": torch.randint(low=0, high=4, size=(1, 1, 5), dtype=torch.float)
    }
    dynamic_axes = {
        # "images": {2: "img_height", 3: "img_width"},
        "point_coords": {2: "num_points"},
        "point_labels": {2: "num_points"},
    }
    opset = 14
    with open(output, "wb") as f:
        print(f"Exporting onnx model to {output}...")
        torch.onnx.export(
            model,
            tuple(dummy_inputs.values()),
            f,
            export_params=True,
            verbose=False,
            opset_version=opset,
            do_constant_folding=True,
            input_names=list(dummy_inputs.keys()),
            output_names=output_names,
            dynamic_axes=dynamic_axes,
        )

and i got error as below:
torch.onnx.symbolic_registry.UnsupportedOperatorError: Exporting the operator ::tile to ONNX opset version 14 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.

from efficientsam.

yformer avatar yformer commented on July 17, 2024

@ArielleBF @ximitiejiang thanks for sharing the information. We will be trying to export one.

from efficientsam.

chenin-wang avatar chenin-wang commented on July 17, 2024

same question.

from efficientsam.

alanzhai219 avatar alanzhai219 commented on July 17, 2024

same question.

from efficientsam.

fPecc avatar fPecc commented on July 17, 2024

Same problem here trying to export 'efficientsam_ti_gpu.jit' to ONNX using PyTorch 2.0.1 and opset_version set to 18.

from efficientsam.

kaka-lin avatar kaka-lin commented on July 17, 2024

Same problem

from efficientsam.

lxfater avatar lxfater commented on July 17, 2024

Same problem

from efficientsam.

mchaniotakis avatar mchaniotakis commented on July 17, 2024

The problem originates from torch.tile here:

        # Tile the image embedding for all queries.
        image_embeddings_tiled = torch.tile(
            image_embeddings[:, None, :, :, :], [1, max_num_queries, 1, 1, 1]
        ).view(
            batch_size * max_num_queries,
            image_embed_dim_c,
            image_embed_dim_h,
            image_embed_dim_w,
        )

This could probably be solved by replacing torch.tile() with tensor.repeat() or using a symbolic for onnx to patch it

from efficientsam.

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.