Git Product home page Git Product logo

Comments (3)

shafu0x avatar shafu0x commented on July 2, 2024
model = torch.hub.load('facebookresearch/detr', 'detr_resnet50', pretrained=True)
x = torch.randn((10,3,800,400)) # batch size of 10
model(x)

This should work.

from detr.

jetjodh avatar jetjodh commented on July 2, 2024

This worked but why does the example give this error and how can it be fixed?:

      2 
      3     # propagate through the model
----> 4 outputs = detr(x)
      5 print(outputs)

3 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    548             result = self._slow_forward(*input, **kwargs)
    549         else:
--> 550             result = self.forward(*input, **kwargs)
    551         for hook in self._forward_hooks.values():
    552             hook_result = hook(self, input, result)

<ipython-input-2-f9392da44538> in forward(self, inputs)
     63         # propagate through the transformer
     64         h = self.transformer(pos + 0.1 * h.flatten(2).permute(2, 0, 1),
---> 65                              self.query_pos.unsqueeze(1)).transpose(0, 1)
     66 
     67         # finally project transformer outputs to class labels and bounding boxes

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    548             result = self._slow_forward(*input, **kwargs)
    549         else:
--> 550             result = self.forward(*input, **kwargs)
    551         for hook in self._forward_hooks.values():
    552             hook_result = hook(self, input, result)

/usr/local/lib/python3.6/dist-packages/torch/nn/modules/transformer.py in forward(self, src, tgt, src_mask, tgt_mask, memory_mask, src_key_padding_mask, tgt_key_padding_mask, memory_key_padding_mask)
    113 
    114         if src.size(1) != tgt.size(1):
--> 115             raise RuntimeError("the batch number of src and tgt must be equal")
    116 
    117         if src.size(2) != self.d_model or tgt.size(2) != self.d_model:

RuntimeError: the batch number of src and tgt must be equal

from detr.

fmassa avatar fmassa commented on July 2, 2024

The colab notebook we provide is a demo implementation which does not support batching (as mentioned in the docstring of the DETRdemo class on the notebook).

Only batch size 1 supported.

The implementation in the repo that @SharifElfouly posted is the recommended way to execute in batched mode, as it exactly reproduces the results in the paper and supports batching.

I believe I have addressed your question, but please let us know if you have follow-up questions

from detr.

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.