How to deal with Imbalanced Datasets in PyTorch - Weighted Random Sampler Tutorial

  Рет қаралды 26,744

Aladdin Persson

Aladdin Persson

Күн бұрын

Пікірлер: 66
@AladdinPersson
@AladdinPersson 3 жыл бұрын
A tip that I didn't mention in the video is when you're iterating through the dataset to create the sample weights is to iterate through dataset.imgs rather than just dataset. This will run much faster because we are not resizing, performing transformations and so on which we do not need to do when we are only interested in the labels of the examples.
@amnesie148
@amnesie148 3 жыл бұрын
Hi Aladdin , First of all thank you for the super good video, but I didn't figure out which part should be " iterate through dataset.imgs ", can you point it out?
@imveryhungry112
@imveryhungry112 2 жыл бұрын
the pytorch weighted random sampler is an amazing pytorch feature. Thanks for talking about it here.
@sahasamanecheppali547
@sahasamanecheppali547 3 жыл бұрын
You sir, deserve way more subscribers for the consistency and the diversity of the topics you choose. Keep up the good work.
@wolfisraging
@wolfisraging 3 жыл бұрын
Awesome video bro, this has been really helpful. I'd like to share one trick of mine: Applying more random and strong data augmentation to the examples that are limited, and less random augmentation on examples that are quiet enough, and then making sure that each batch to the model receives an equal number of examples for each unique label. The only side effect here would be that you'd have to write your own custom dataloader that does that 🥱, and to be honest, it's not easy 😂, but once you set it up then its just a matter of copying and pasting for next projects :) Thanks again for the video.
@AladdinPersson
@AladdinPersson 3 жыл бұрын
Hey Wolf! :) That sounds interesting, I would like to check it out if you could you share an example of such a custom dataloader?
@rosacanina674
@rosacanina674 5 ай бұрын
Thank you so much for your great content! I was wondering if the loader in the video is the train_loader? do you also apply oversampling on dev_train and test dataloader?
@jacoblee6246
@jacoblee6246 3 жыл бұрын
Great video!A small bug: The orders of traversal between os.walk and datasets.ImageFolder are different. In the github code, We cannot guarantee that the smaller number of samples will get a greater sampling weight.
@yashrunwal5111
@yashrunwal5111 3 жыл бұрын
Hi, how can we use the WeightedRandomSampler for Object Detection task?
@mochametmachmout4467
@mochametmachmout4467 3 жыл бұрын
To tackle the imbalance one can also use the Focal Loss function. The kornia library has it.
@rafaelmahammadli667
@rafaelmahammadli667 2 жыл бұрын
Hello, How can we apply under-sampling on your case? Oversampling and undersampling can be applied together? Thank you
@Zulle863
@Zulle863 Жыл бұрын
Does we have to call get data loader for once for train and once for test set or just a single time for the entire dataset?
@kirankharel929
@kirankharel929 3 жыл бұрын
Thanks Aladdin for all your videos, they are really awesome and informative
@AladdinPersson
@AladdinPersson 3 жыл бұрын
Really appreciate it bro
@yanfeng5519
@yanfeng5519 Жыл бұрын
Great lecture.
@clariolee
@clariolee Жыл бұрын
人像加入视频时候舒服多了!!不知道看哪的时候就看脸哈哈哈。
@fasolya99
@fasolya99 3 жыл бұрын
why did you multiply the sample_weights (which is zero) by len(dataset) ?
@frankrobert9199
@frankrobert9199 2 жыл бұрын
Great lectures.
@thantyarzarhein5459
@thantyarzarhein5459 3 жыл бұрын
Awesome video and this channel is so underrated in DL community. I would like to know if there will be paper implementation tutorials in the future ?
@AladdinPersson
@AladdinPersson 3 жыл бұрын
Yeah for sure. Any paper in particular you'd wanna see?
@aishwaryaagarwal3540
@aishwaryaagarwal3540 3 жыл бұрын
@@AladdinPersson arxiv.org/pdf/1905.05908.pdf This one if possible. Can you make some tutorials on compositional zero-shot learning and implement some papers in that field.
@0730pleomax
@0730pleomax 3 жыл бұрын
Thanks Aladdin! Would you mind recommend us your learning resources? I mean most of your teaching content are pretty rare in any ML/DL book.
@AladdinPersson
@AladdinPersson 3 жыл бұрын
I'm just sharing solutions to problems I face. Googling, reading docs and github, no good learning resource there unfortunately
@hassanrevel
@hassanrevel Жыл бұрын
Thanks man
@sebastianamaruescalantecco7916
@sebastianamaruescalantecco7916 3 жыл бұрын
There is a bug in the program that can cause you a lot of trouble. After line 22 add this line of code -> subdir.sort() os.walk() won't traverse your folders in alphabetical order so you have to sort the generator before appending the calculated weights. The could should look something like this: for root, subdir, files in os.walk(root_dir): subdir.sort() if len(files) > 0: ....
@bryanyan8346
@bryanyan8346 2 жыл бұрын
The same problem arises for me, thanks for pointing out!
@hamidmahmoodpour3659
@hamidmahmoodpour3659 2 жыл бұрын
why we can not use shuffle while using sampler?
@ZulkaifAhmed1
@ZulkaifAhmed1 3 жыл бұрын
Dude you are awesome. I like your pytorch tutorials. But would love if you could use google colab for next ones.
@mariaanson6537
@mariaanson6537 3 жыл бұрын
What is the editor or Ide you are using
@nishantyadav6341
@nishantyadav6341 3 жыл бұрын
Aladdin, you deserve more subscribers. And you need to charge more :) Just joined as a member.
@AladdinPersson
@AladdinPersson 3 жыл бұрын
Appreciate you bro
@helimehuseynova6631
@helimehuseynova6631 2 жыл бұрын
Hi , If we have 3 classes, how can we do it ?
@kelixoderamirez
@kelixoderamirez Жыл бұрын
permisiion to learn sir. thank you
@sahil-7473
@sahil-7473 3 жыл бұрын
Superb!! I implemented AugMix DataAugmentation myself to increase the minority label's samples. My question is should we stick around one data augmentation technique which is state of the art OR we should try all of the others technique? Thanks
@AladdinPersson
@AladdinPersson 3 жыл бұрын
I prefer to use RandAugment
@mustafabuyuk6425
@mustafabuyuk6425 3 жыл бұрын
Randaugment is one of the best augmentation method, it will improve your model performance and I was using weight normalization like this nSamples = [346,168,106] # class samples normedWeights = [1 - (x / sum(nSamples)) for x in nSamples] normedWeights = torch.FloatTensor(normedWeights).to(device) print(normedWeights) nn.CrossEntropyLoss(weight=normedWeights) is your second method different than this
@AladdinPersson
@AladdinPersson 3 жыл бұрын
I prefer oversampling (and you can still use RandAugment) rather than class weighting as it seems you're doing in the example
@НиколайНовичков-е1э
@НиколайНовичков-е1э 3 жыл бұрын
Thanks!
@TheAcujlGamer
@TheAcujlGamer 3 жыл бұрын
Great video!
@Tripdin
@Tripdin 3 жыл бұрын
Thank you
@kirtipandya4618
@kirtipandya4618 3 жыл бұрын
How can you use pytorch and tensorflow so well. You must have invested so many hours of practice. How do you do that? Which API you like more for ML? In Keras you handle images differently and in pytorch you handle differently. It amazing to see that you have mastery over both. Well less people can do that. Usually people like to work with only one API.
@AladdinPersson
@AladdinPersson 3 жыл бұрын
I like PyTorch more. I think you overestimate me for sure, I'm way worse than what you think and need to google everything. You just see the refined version in the video and not the horrible mistakes I make :)
@jimmychen4796
@jimmychen4796 3 жыл бұрын
@@AladdinPersson You are too humble bro! A nice lesson learned: ), good job, and keep going!
@shaharweksler1203
@shaharweksler1203 3 жыл бұрын
@@AladdinPersson maybe you can make a video about how you get stuck and your train of thoughts and google queries to solve it
@mattiagatti1200
@mattiagatti1200 2 жыл бұрын
Hello, I still don't understand how replacement = True differs from replacement = False, may you explain me it please? Thank you :)
@erdi749
@erdi749 3 жыл бұрын
Another amazing tutorial! I wonder if you have a patreon page where we can support you, it is well deserved. I have a question as well. I have a large imbalanced dataset. I need to call getloader function to get train and test loaders for hyperparamter tuning. Scanning the entire trainset in each function call makes the code slower. Do you suggest a work around? Thank you!
@amirhosseindaraie5622
@amirhosseindaraie5622 2 жыл бұрын
Hi Aladdin, Your code does not work and the result is still imbalanced. What should we do?
@AladdinPersson
@AladdinPersson 2 жыл бұрын
Why does the code "not work"?
@jijie133
@jijie133 3 жыл бұрын
Great video!
@sakib.9419
@sakib.9419 3 жыл бұрын
I've been trying to do this in TensorFlow with ImageDataGens for over 5 hrs now, Could you help out?
@AladdinPersson
@AladdinPersson 3 жыл бұрын
I'm not sure how you do it in Tensorflow
@sakib.9419
@sakib.9419 3 жыл бұрын
@@AladdinPersson That's fine, d'you have a discord btw?
@apurbasarkar6918
@apurbasarkar6918 3 жыл бұрын
how to do it in tensorflow? I'm struck
@tirthadatta2072
@tirthadatta2072 Жыл бұрын
Can u give me solution about computational cost or memory allocation problem related to oversampling imbalance dataset. It is too hard for me to buy gpu because of high cost and it is also problem for many of us. Can anyone here give solution related to the issue?
@유영재-c9c
@유영재-c9c 2 жыл бұрын
dataset link over!
@robinranabhat3125
@robinranabhat3125 Жыл бұрын
Recap at 9:00
@seanbenhur
@seanbenhur 3 жыл бұрын
Bro..are you in linkedin!?
@AladdinPersson
@AladdinPersson 3 жыл бұрын
Yeyup, same name :)
@seanbenhur
@seanbenhur 3 жыл бұрын
@@AladdinPersson Request sent😌
@ArunKumar-sg6jf
@ArunKumar-sg6jf 3 жыл бұрын
Do in TENSORFLOW also bro
@AladdinPersson
@AladdinPersson 3 жыл бұрын
I don't know a good way to do it in Tensorflow... :\ Maybe someone else knows and can help out?
@wolfisraging
@wolfisraging 3 жыл бұрын
I've been using it in almost every other projects... but never understood what's so random about it? Why random in its name? 🙂
@AladdinPersson
@AladdinPersson 3 жыл бұрын
Donno actually 🤔
PYTORCH COMMON MISTAKES - How To Save Time 🕒
19:12
Aladdin Persson
Рет қаралды 56 М.
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24
Haunted House 😰😨 LeoNata family #shorts
00:37
LeoNata Family
Рет қаралды 6 МЛН
Pytorch Transformers from Scratch (Attention is all you need)
57:10
Aladdin Persson
Рет қаралды 315 М.
Samplers in PyTorch.
22:52
Datum Learning
Рет қаралды 1,6 М.
How to handle imbalanced datasets in Python
11:48
Data Professor
Рет қаралды 53 М.
Albumentations Tutorial for Data Augmentation (Pytorch focused)
31:29
Aladdin Persson
Рет қаралды 32 М.
How to deal with unbalanced dataset using custom samplers in Pytorch?
14:38
Pytorch GoogLeNet / InceptionNet implementation from scratch
26:00
Aladdin Persson
Рет қаралды 19 М.