def grad_enabled_forward(self, samples: NestedTensor):
    """
    Adapted from DETR source: https://github.com/facebookresearch/detr
    (detr/models/detr.py)
    """

    if isinstance(samples, (list, torch.Tensor)):
        samples = nested_tensor_from_tensor_list(samples)
    features, pos = self.backbone(samples)
    src, mask = features[-1].decompose()
    assert mask is not None
    h_s = self.transformer(self.input_proj(src), mask, self.query_embed.weight, pos[-1])[0]
    outputs_class = self.class_embed(h_s)
    outputs_coord = self.bbox_embed(h_s).sigmoid()
    out = {"pred_logits": outputs_class[-1], "pred_boxes": outputs_coord[-1]}
    if self.aux_loss:
        out["aux_outputs"] = self._set_aux_loss(outputs_class, outputs_coord)
    return out

    Adapted from DETR source: https://github.com/facebookresearch/detr
    (detr/models/detr.py)
    
art/estimators/object_detection/detr.py