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.

NotImplemented Error while running ImbalancedDatasetSampler

See original GitHub issue

I followed the steps exactly according to the readme file. Yet I am getting a notimplemented error. There’s no explanation for the error as well.

Here’s my code: `from torchvision import transforms from torchsampler import ImbalancedDatasetSampler

batch_size = 128 val_split = 0.2 shuffle_dataset=True random_seed=42

dataset_size = len(melanoma_dataset) indices = list(range(dataset_size)) split = int(np.floor(val_split * dataset_size)) if shuffle_dataset : np.random.seed(random_seed) np.random.shuffle(indices) train_indices, test_indices = indices[split:], indices[:split]

train_loader = torch.utils.data.DataLoader(melanoma_dataset,batch_size=batch_size,sampler=ImbalancedDatasetSampler(melanoma_dataset)) test_loader = torch.utils.data.DataLoader(melanoma_dataset,batch_size=batch_size,sampler=test_sampler)`

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
SorenJ89commented, Dec 1, 2020

If anyone reads this, this worked for me:

def callback_get_label(dataset, idx):
    #callback function used in imbalanced dataset loader.
    input, target = dataset[idx]
    return np.argwhere(target.numpy()).item()

Edit: I suspect it would be faster to not cast the tensor to numpy, so the following change should do the same within the tensor framework:

def callback_get_label(dataset, idx):
    #callback function used in imbalanced dataset loader.
    input, target = dataset[idx]
    return target.nonzero().item()
3reactions
PaleNeutroncommented, Dec 1, 2020

If you have an int label, try use this:

def callback_get_label(dataset, idx):
    #callback function used in imbalanced dataset loader.
    i, target = dataset[idx]
    return int(target)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error when call ImbalancedDatasetSampler function · Issue #16
Following error occurred when on dataloader. I am working on google colab. Code train_dataset = DataLoader(train_dataset, ...
Read more >
Error with "ImbalancedDatasetSampler" - PyTorch Forums
Hi, I am dealing with imbalanced data (mere 2% minority samples). I tried “WeightedRandomSampler” approach which only works OK for my ...
Read more >
Paper on Imbalanced classes - Intro to Machine Learning (2018)
In this study, we systematically investigate the impact of class imbalance on classification performance of convolutional neural networks (CNNs ...
Read more >
python - Google Colab - NotImplementedError - Stack Overflow
I've been trying to use the following package and just when I tried to instantiate it, NotImplementedError: showed up in Google Colab.
Read more >
How to save NotImplementedError - PyTorch Lightning
Hi, I try to use pytorch lightning to detect objects in my own dataset. The model I am using is Faster R-CNN, but...
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