# Training on rectangular pictures

**URL:** <https://discuss.roboflow.com/t/training-on-rectangular-pictures/5040>\
**Category:** 🤝  Community Help\
**Created:** [March 30, 2024, 5:58am UTC](https://discuss.roboflow.com/t/training-on-rectangular-pictures/5040 "2024-03-30T05:58:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ai1archivizer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/ai1archivizer/32/8361_2.png) [@ai1archivizer](https://discuss.roboflow.com/u/ai1archivizer)\
**Post date:** [March 30, 2024, 5:58am UTC](https://discuss.roboflow.com/t/training-on-rectangular-pictures/5040/1 "2024-03-30T05:58:50Z")

</div>

I need to train on rectangular pictures w=480, h=128

!python train.py --imgsz [480,128] --batch 16 --epochs 300  
--data …detect\_480x120/data.yaml  
--cfg ./models/yolov5x.yaml  
--weights yolov5x.pt  
--name v5x\_res  
--cache

I get the error:  
train.py: error: argument --imgsz/–img/–img-size: invalid int value: ‘[480,128]’

---

<div class="post-metadata">

**Author:** ![leo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/leo/32/2228_2.png) [@leo](https://discuss.roboflow.com/u/leo)\
**Post date:** [April 9, 2024, 3:01am UTC](https://discuss.roboflow.com/t/training-on-rectangular-pictures/5040/3 "2024-04-09T03:01:47Z")

</div>

Hey @ai1archivizer

It looks like you are using the YOLOv5 model. According to [this issue](https://github.com/ultralytics/yolov5/issues/4116) from the YOLOv5 GitHub, the following should do what you are looking for:

```auto
python train.py --img 512 --rect

```

See this issue: [Train on Non-Square Images · Issue #4116 · ultralytics/yolov5 · GitHub](https://github.com/ultralytics/yolov5/issues/4116)

---

<div class="post-metadata">

**Author:** ![ai1archivizer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/ai1archivizer/32/8361_2.png) [@ai1archivizer](https://discuss.roboflow.com/u/ai1archivizer)\
**Post date:** [April 9, 2024, 5:51pm UTC](https://discuss.roboflow.com/t/training-on-rectangular-pictures/5040/4 "2024-04-09T17:51:15Z")

</div>

Hey [leo](https://discuss.roboflow.com/u/leo)  
Thank you for your attention.  
[There’s](https://github.com/ultralytics/yolov5/issues/4116) no solution

Although it should take the size as a list  
train.py → utils/general.py

```auto
def check_img_size(imgsz, s=32, floor=0):
    # Verify image size is a multiple of stride s in each dimension
    if isinstance(imgsz, int): # integer i.e. img_size=640
        new_size = max(make_divisible(imgsz, int(s)), floor)
    else: # list i.e. img_size=[640, 480]
        imgsz = list(imgsz) # convert to list if tuple
        new_size = [max(make_divisible(x, int(s)), floor) for x in imgsz]
    if new_size != imgsz:
        LOGGER.warning(f'WARNING ⚠️ --img-size {imgsz} must be multiple of max stride {s}, updating to {new_size}')
    return new_size

```

---

<div class="post-metadata">

**Author:** ![leo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/leo/32/2228_2.png) [@leo](https://discuss.roboflow.com/u/leo)\
**Post date:** [April 12, 2024, 1:33pm UTC](https://discuss.roboflow.com/t/training-on-rectangular-pictures/5040/5 "2024-04-12T13:33:47Z")

</div>

Hi @ai1archivizer

The solution I highlighted is from the YOLOv5 GitHub repo and we (Roboflow) don’t maintain that. For any issues that relate directly to YOLOv5, I suggest following up in that issue or creating a new issue there. Of course, for any Roboflow related issues or questions, please let us know here.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/bb6edbfa56d0cf2ee603f061e9e09103502cc8cc.png) [@system](https://discuss.roboflow.com/u/system)\
**Post date:** [April 23, 2024, 1:27am UTC](https://discuss.roboflow.com/t/training-on-rectangular-pictures/5040/6 "2024-04-23T01:27:35Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
