{"record":{"id":"b60eab7f53c7b955","repo":"open-mmlab/mmdetection","slug":"neck-inputs-should-be-tuple-or-torch-tensor","errorCode":null,"errorMessage":"neck inputs should be tuple or torch.tensor","messagePattern":"neck inputs should be tuple or torch\\.tensor","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"mmdet/models/reid/gap.py","lineNumber":39,"sourceCode":"            self.gap = nn.AdaptiveAvgPool2d((1, 1))\n        else:\n            self.gap = nn.AvgPool2d(kernel_size, stride)\n\n    def forward(self, inputs):\n        if isinstance(inputs, tuple):\n            outs = tuple([self.gap(x) for x in inputs])\n            outs = tuple([\n                out.view(x.size(0),\n                         torch.tensor(out.size()[1:]).prod())\n                for out, x in zip(outs, inputs)\n            ])\n        elif isinstance(inputs, torch.Tensor):\n            outs = self.gap(inputs)\n            outs = outs.view(\n                inputs.size(0),\n                torch.tensor(outs.size()[1:]).prod())\n        else:\n            raise TypeError('neck inputs should be tuple or torch.tensor')\n        return outs\n","sourceCodeStart":21,"sourceCodeEnd":41,"githubUrl":"https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/reid/gap.py#L21-L41","documentation":"GlobalAvgPooling (Gap neck used in ReID models) only accepts a tuple/list of tensors or a single torch.Tensor as input. Any other type raises this TypeError in forward.","triggerScenarios":"Passing a numpy array, a dict, or None to the Gap neck; a neck whose forward receives a non-tensor (e.g. when data samples or list-wrapped inputs are fed directly instead of the batched image tensor).","commonSituations":"Custom pipelines feeding numpy images without ToTensor; chaining necks incorrectly so a non-tensor flows into the reid neck.","solutions":["Ensure the input is a stacked torch.Tensor of shape (N, C, H, W) or a tuple of tensors","Add mmcv.transforms ToTensor / use the configured DataPreprocessor so images become tensors","If inputs come from a loader, check that batch['inputs'] is tensorized before forward"],"exampleFix":"# before\nneck_out = gap_neck(batch['inputs'])  # numpy arrays\n# after\nimport torch\nneck_out = gap_neck(torch.stack([torch.as_tensor(i) for i in batch['inputs']]))","handlingStrategy":"type-guard","validationCode":"import torch\nassert isinstance(inputs, torch.Tensor) or (isinstance(inputs, (tuple, list)) and all(isinstance(t, torch.Tensor) for t in inputs))","typeGuard":"def is_tensorlike(x): import torch; return isinstance(x, torch.Tensor) or (isinstance(x,(tuple,list)) and all(isinstance(t, torch.Tensor) for t in x))","tryCatchPattern":null,"preventionTips":["Ensure ToTensor/DataPreprocessor in the pipeline","Convert numpy to torch.as_tensor before manual forward calls"],"tags":["mmdetection","reid","neck","type-error"],"backgroundTag":"invalid-input-type","analyzedSha":"cfd5d3a985b0249de009b67d04f37263e11cdf3d","analyzedAt":"2026-08-27T20:54:20.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}