Skip to content

Allow batch_size > 1 in quantized RoIAlign #3655

Open
@NicolasHug

Description

@NicolasHug

#3624 was recently merged and we identified a potential issue: #3624 (comment)

In short, the rois tensor contains indices in the first column, but depending on the quantization, some indices cannot be properly represented. For example uneven numbers can't be represented if the tensor was quantized with qscale = 2.

To prevent any potential bug, we currently force the batch size to be 1 and hard-code the index to 0:

TORCH_CHECK(
input.size(0) == 1,
"Only one image per batch is allowed in roi_align when quantized tensors are passed.");

// FIXME: change this when batches of size > 1 are allowed
const int roi_batch_ind = 0;

We should try to allow more than one element per batch. A potential solution would involve using per-channel quantized tensors for the roi tensor, where the first column containing the indices would be quantized in a different way from the rest of the columns.

In roi_align python op:

  • if a tensor with 5 columns is passed, raise an error if it's not per-channel: there's a high changes the indices are wrong and it's too risky. If the tensor is per-chanel, pass it through: we can assume that the user knows what they're doing and that the indices are properly represented. As a good sanity check, we can still check that the batch size is within the range of the quantized type of the first column.
  • if a list of tensors is passed, convert that list of tensors into a per-channel quantized tensor with 5 columns.

The convert_boxes_to_roi_format utils should be modified. To ensure consistency throughout the library, it should also be used in MultiScaleRoIAlign.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions