question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'MyDataset' object has no attribute 'get_labels'

See original GitHub issue

When I try to use my own Dataset class, I get the error 'MyDataset' object has no attribute 'get_labels' and cannot proceed.

The content of the Dataloader is as follows, and there is nothing strange about it. It processes the image data and label data in .npz format.

class MyDataset(data.Dataset):
    def __init__(self, images, labels, transform=None):
        self.images = images
        self.labels = labels
        self.transform = transform

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

    def __getitem__(self, index):
        image = self.images[index]
        label = self.labels[index]

        if self.transform is not None:
            image = self.transform(image=image)["image"]

        return image, label
train_dataset = MyDataset(train_imgs, train_labels, transform=transform)
train_dataloader = torch.utils.data.DataLoader(train_dataset,
                                               sampler=ImbalancedDatasetSampler(train_dataset),
                                               batch_size= batch_size,
                                               shuffle=True,
                                               num_workers=2)

Is there something wrong with the code? I don’t think it’s a typo.

How can I fix it so that it works correctly?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
jaebbbcommented, Jul 9, 2021

add this in your dataset code, and turn off the shuffle

def get_labels(self): return self.labels

0reactions
Waterkincommented, Jun 12, 2022

You need to include a function to get the label in that class. As you can see in imbalanced-dataset-sampler/torchsampler/imbalanced.py, the code to get the labels looks like this Hi, Should we do shuffle=False for training, validating and testing ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

'MyDataset' object has no attribute 'get_labels' #34 - bytemeta
When I try to use my own Dataset class, I get the error 'MyDataset' object has no attribute 'get_labels' and cannot proceed.
Read more >
ConcatDataset support · Issue #37 - GitHub
I try to combine two datasets by using "dataset = dataset1+dataset2", ... object has no attribute 'get_labels' Is there any workaround?
Read more >
python - Get labels from dataset when using tensorflow ...
My images are organized in directories having the label as the name. The documentation says the function returns a tf.data.Dataset object. If ...
Read more >
get_labels: Retrieve value labels of labelled data in sjlabelled
View source: R/get_labels.R ... If x has no label attributes, factor levels are returned. ... values are set as names attribute of the...
Read more >
lightgbm.Dataset — LightGBM 3.3.3.99 documentation
Get a chain of Dataset objects. Starts with r, then goes to r.reference (if exists), then to r.reference.reference, etc. until we hit ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found