# How to oversample the imbalanced classes in BoW

**URL:** <https://discuss.pytorch.org/t/how-to-oversample-the-imbalanced-classes-in-bow/93424>\
**Category:** vision\
**Created:** [August 20, 2020, 1:12am UTC](https://discuss.pytorch.org/t/how-to-oversample-the-imbalanced-classes-in-bow/93424 "2020-08-20T01:12:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kit\_m](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/kit_m/32/29740_2.png) [@kit\_m](https://discuss.pytorch.org/u/kit_m)\
**Post date:** [August 20, 2020, 1:12am UTC](https://discuss.pytorch.org/t/how-to-oversample-the-imbalanced-classes-in-bow/93424/1 "2020-08-20T01:12:51Z")

</div>

Suppose my task is to build a BoW predictor from image features. Inputs are image features and outputs are BoW vectors. Each element of the BoW are cat, dog, pig, panda and penguin. The BoW in the training data is imbalanced. For example, [1, 0, 0, 0, 0], [1, 0, 1, 0, 0],[1, 1, 1, 0, 0], [1, 0, 0, 0, 1],[1, 0, 1, 1, 0]…

My question is how I should oversample the data? In the example above, panda is the minority class. If I try to increase frequencies of panda by oversampling, cat and pig also increase as well.  
Should I use `torch.utils.data.distributed.` `DistributedSampler`?

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [August 22, 2020, 4:52am UTC](https://discuss.pytorch.org/t/how-to-oversample-the-imbalanced-classes-in-bow/93424/2 "2020-08-22T04:52:05Z")

</div>

[This post](https://discuss.pytorch.org/t/unbalanced-data-in-multiple-object-detection/88104/2) has some suggestions for different sampling implementation when dealing with an imbalanced multi-label dataset. 🙂
