Skip to content

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

@DouglasChanges

Description

@DouglasChanges

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions