Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DouglasChanges opened this issue Jun 4, 2024 · 0 comments
Open

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

DouglasChanges opened this issue Jun 4, 2024 · 0 comments

Comments

@DouglasChanges
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant