faster-rcnn.pytorch icon indicating copy to clipboard operation
faster-rcnn.pytorch copied to clipboard

AttributeError: 'Tensor' object has no attribute 'index'

Open DouglasChanges opened this issue 1 year ago • 0 comments

I need a guide on how to resolve this bug: label_idx = labels.index(label) # Convert label to an index AttributeError: 'Tensor' object has no attribute 'index'

Pycharm referenced this class to be the sources of the error: class SpeedDataset(Dataset): def init(self, data): self.data = data

def __len__(self):
    return len(self.data)

def __getitem__(self, idx):
    speed = self.data.iloc[idx]['speeds']
    label = self.data.iloc[idx]['label']
    label_idx = labels.index(label)  # Convert label to an index
    return torch.tensor(speed, dtype=torch.float32), torch.tensor(label_idx, dtype=torch.long)

Please, I need a guide to resolve this issue.

DouglasChanges avatar Jun 04 '24 17:06 DouglasChanges