# After Merging Datasets, Re-balancing (Train/Val/Test) excludes multiple classes in VAL split

**URL:** <https://discuss.roboflow.com/t/after-merging-datasets-re-balancing-train-val-test-excludes-multiple-classes-in-val-split/704>\
**Category:** 🛠️ Feature Reqs\
**Tags:** split-after-upload, bugs\
**Created:** [July 18, 2022, 8:48pm UTC](https://discuss.roboflow.com/t/after-merging-datasets-re-balancing-train-val-test-excludes-multiple-classes-in-val-split/704 "2022-07-18T20:48:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sparrowtech](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/sparrowtech/32/242_2.png) [@Sparrowtech](https://discuss.roboflow.com/u/Sparrowtech)\
**Post date:** [July 18, 2022, 8:48pm UTC](https://discuss.roboflow.com/t/after-merging-datasets-re-balancing-train-val-test-excludes-multiple-classes-in-val-split/704/1 "2022-07-18T20:48:16Z")

</div>

After merging several object datasets (already uploaded to Roboflow) into one, I am unable to get a fairly balanced split between classes when generating a new version. After reviewing similar topics, a suggestion to manually move more images from one class into the “VAL” split is not feasible with ~17,500 total images.

Currently, have to export the entire “Merged” Dataset, properly shuffle/splits (e.g. 75/20/5) all objects into new Train/Val/Test splits… THEN upload AGAIN the properly balanced dataset to Roboflow while keeping the existing splits. Have no idea what happens when you add augmentations or if for some reason needed to adjust the balance between Train/Val/Test.

Previously asked about same issue, don’t believe ever received any further update after this response:

> [@Need Ability to randomly shuffle "merged dataset" when allocating Train/Val/Test Sets](https://discuss.roboflow.com/t/need-ability-to-randomly-shuffle-merged-dataset-when-allocating-train-val-test-sets/360/3):
>
> Thanks for reporting. This sounds like a recent regression stemming from us keeping uploaded images in sequential order to make it easier for annotators to label sequences of video frames. Let me look at the code and see what I can do to restore the randomness for the model while preserving the ordering for humans in the tool.

Please see below export stats and screenshots:

**Train Object Stats:**  
5347 handgun  
4648 rifle  
4748 knife  
1437 hammer

**Val Object Stats :**  
0 handgun  
0 rifle  
995 knife  
2587 hammer

 ![Health Check](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/71370c536da0e5aaa8645f6307539eaf42b61c63.png)  
 ![Robo Dataset Breakdown](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/89e617357a513b97ed4935aa76a5a38cc69fc862.png)

---

<div class="post-metadata">

**Author:** ![josephofiowa](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/josephofiowa/32/80_2.png) [@josephofiowa](https://discuss.roboflow.com/u/josephofiowa)\
**Post date:** [July 19, 2022, 2:34pm UTC](https://discuss.roboflow.com/t/after-merging-datasets-re-balancing-train-val-test-excludes-multiple-classes-in-val-split/704/2 "2022-07-19T14:34:45Z")

</div>

Thanks for the note here.

> [@Sparrowtech](#):
>
> I am unable to get a fairly balanced split between classes when generating a new version

If understood correctly, the desired outcome is a merged dataset with classes randomly shuffled among training, validation, and testing. Is that correct?

---

<div class="post-metadata">

**Author:** ![Sparrowtech](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/sparrowtech/32/242_2.png) [@Sparrowtech](https://discuss.roboflow.com/u/Sparrowtech)\
**Post date:** [July 19, 2022, 8:36pm UTC](https://discuss.roboflow.com/t/after-merging-datasets-re-balancing-train-val-test-excludes-multiple-classes-in-val-split/704/3 "2022-07-19T20:36:16Z")

</div>

Yes, almost. There is a bunch of terminology about what we are trying to insure is accomplished but generally speaking we desire a random “sampling” of each class such that there would be a balance of objects in the respective Train,Val,Test splits. Then shuffling those splits so there is no perceived order amongst classes.

E.G.

5 classes of objects in a merged Roboflow dataset - each with 100 images per class totaling 500 total images.

Tiger - 100 images  
Lion -100 images  
Elephant -100 images  
Zebra - 100 images  
Monkey -100 images

Seek to split 500 images into Train/Val/Test with 80/15/5 ratio.

OUTCOME WOULD BE:

**Train:**  
Tiger 80  
Lion 80  
Elephant 80  
Zebra 80  
Monkey 80

**Val:**

Tiger 15  
Lion 15  
Elephant 15  
Zebra 15  
Monkey 15

**Test:**

Tiger 5  
Lion 5  
Elephant 5  
Zebra 5  
Monkey 5

In each of those balanced splits, all of the images would be shuffled.

Hope this makes sense and as you can see from the exported stats above, the splits are not balanced at all and even exclude entire object classes in the Val Split.

Thanks.

---

<div class="post-metadata">

**Author:** ![Sparrowtech](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/sparrowtech/32/242_2.png) [@Sparrowtech](https://discuss.roboflow.com/u/Sparrowtech)\
**Post date:** [July 25, 2022, 7:09pm UTC](https://discuss.roboflow.com/t/after-merging-datasets-re-balancing-train-val-test-excludes-multiple-classes-in-val-split/704/4 "2022-07-25T19:09:40Z")

</div>

Any update?

---

<div class="post-metadata">

**Author:** ![brad](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/brad/32/23_2.png) [@brad](https://discuss.roboflow.com/u/brad)\
**Post date:** [July 26, 2022, 2:03am UTC](https://discuss.roboflow.com/t/after-merging-datasets-re-balancing-train-val-test-excludes-multiple-classes-in-val-split/704/5 "2022-07-26T02:03:07Z")

</div>

You can accomplish this by uploading each class separately so you can choose the split per class. (Or if you upload them already organized in `train` `valid` and `test` folders we’ll parse those from the file path and let you keep those choices.

---

<div class="post-metadata">

**Author:** ![Sparrowtech](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/sparrowtech/32/242_2.png) [@Sparrowtech](https://discuss.roboflow.com/u/Sparrowtech)\
**Post date:** [July 26, 2022, 5:06pm UTC](https://discuss.roboflow.com/t/after-merging-datasets-re-balancing-train-val-test-excludes-multiple-classes-in-val-split/704/6 "2022-07-26T17:06:30Z")

</div>

Thanks Brad. We generally upload each class to Roboflow by itself and put all into train so can re-balance later upon export depending upon split-need. Pretty cumbersome to export already uploaded datasets to local machine, shuffle-split, then reload back to Roboflow, then merge, and finally generate new export… don’t you think?. Kinda makes your “re-balance” feature in Generate obsolete. Any chance can incorporate a “shuffle-sample” feature into re-balance dataset? Either behind the scene automatically, which I think everyone would want, or a button-slide feature to equally balance classes upon choosing the re-balance function?

Please advise and thanks.  
Sean

---

<div class="post-metadata">

**Author:** ![25benjaminli](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/25benjaminli/32/1242_2.png) [@25benjaminli](https://discuss.roboflow.com/u/25benjaminli)\
**Post date:** [February 19, 2023, 4:12am UTC](https://discuss.roboflow.com/t/after-merging-datasets-re-balancing-train-val-test-excludes-multiple-classes-in-val-split/704/7 "2023-02-19T04:12:23Z")

</div>

I agree - will this be fixed? The train val split feature is somewhat obsolete right now due to it being so imbalanced. Also, is there a way to re-split images after labeling is finished?

---

<div class="post-metadata">

**Author:** ![Jeff\_Cochran](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/jeff_cochran/32/3965_2.png) [@Jeff\_Cochran](https://discuss.roboflow.com/u/Jeff_Cochran)\
**Post date:** [March 11, 2024, 5:18pm UTC](https://discuss.roboflow.com/t/after-merging-datasets-re-balancing-train-val-test-excludes-multiple-classes-in-val-split/704/8 "2024-03-11T17:18:00Z")

</div>

As far as I can tell, they haven’t done anything to address this. Really not sure why the rebalancing wouldn’t be random by default; seems like a silly design choice.
