Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何训练图片尺寸为(640,480)的模型 #11768

Closed
1 task done
xingjunhong opened this issue Jun 25, 2023 · 10 comments
Closed
1 task done

如何训练图片尺寸为(640,480)的模型 #11768

xingjunhong opened this issue Jun 25, 2023 · 10 comments
Labels
question Further information is requested Stale

Comments

@xingjunhong
Copy link

Search before asking

Question

目前官方的模型训练的尺寸是正方形尺寸,如何训练修改为长方形(640,480)尺寸的模型?

Additional

No response

@xingjunhong xingjunhong added the question Further information is requested label Jun 25, 2023
@glenn-jocher
Copy link
Member

@xingjunhong hi there,

To train the YOLOv5 model with a rectangular shape such as (640, 480), you can modify the input size in the training configuration file. Simply edit the --img argument in the --hyp section of the yaml file to specify your desired dimensions (e.g., --img: '640, 480'). This will ensure that the input images are resized to the specified dimensions during training.

Please note that modifying the input size may affect the performance and accuracy of your model, so it's important to experiment with different sizes and evaluate the results accordingly.

If you have any further questions or encounter any issues, please don't hesitate to ask.

Best regards,
Glenn Jocher

@xingjunhong
Copy link
Author

@xingjunhong hi there,

To train the YOLOv5 model with a rectangular shape such as (640, 480), you can modify the input size in the training configuration file. Simply edit the --img argument in the --hyp section of the yaml file to specify your desired dimensions (e.g., --img: '640, 480'). This will ensure that the input images are resized to the specified dimensions during training.

Please note that modifying the input size may affect the performance and accuracy of your model, so it's important to experiment with different sizes and evaluate the results accordingly.

If you have any further questions or encounter any issues, please don't hesitate to ask.

Best regards, Glenn Jocher

修改这个参数后,会出现报错。
parser.add_argument('--imgsz', '--img', '--img-size', type=int, default=[640, 480], help='train, val image size (pixels)')

Traceback (most recent call last):
File "train.py", line 634, in
main(opt)
File "train.py", line 528, in main
train(opt.hyp, opt, device, callbacks)
File "train.py", line 283, in train
for i, (imgs, targets, paths, _) in pbar: # batch -------------------------------------------------------------
File "/mnt/hdd/home/xingjh/anaconda3/envs/yolov5/lib/python3.8/site-packages/tqdm/std.py", line 1195, in iter
for obj in iterable:
File "/mnt/hdd2/extension/xingjh/02.work/yolov5/utils/dataloaders.py", line 172, in iter
yield next(self.iterator)
File "/mnt/hdd/home/xingjh/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 435, in next
data = self._next_data()
File "/mnt/hdd/home/xingjh/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data
return self._process_data(data)
File "/mnt/hdd/home/xingjh/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data
data.reraise()
File "/mnt/hdd/home/xingjh/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/_utils.py", line 428, in reraise
raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/mnt/hdd/home/xingjh/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
data = fetcher.fetch(index)
File "/mnt/hdd/home/xingjh/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/mnt/hdd/home/xingjh/anaconda3/envs/yolov5/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/mnt/hdd2/extension/xingjh/02.work/yolov5/utils/dataloaders.py", line 669, in getitem
img, (h0, w0), (h, w) = self.load_image(index)
File "/mnt/hdd2/extension/xingjh/02.work/yolov5/utils/dataloaders.py", line 737, in load_image
r = self.img_size / max(h0, w0) # ratio
TypeError: unsupported operand type(s) for /: 'list' and 'int'

@glenn-jocher
Copy link
Member

@xingjunhong I apologize for the confusion. It seems that the issue you encountered is related to a type mismatch in the imgsz argument.

To resolve this error, make sure that the imgsz argument in the --hyp section of the yaml file is specified as a single integer (e.g., imgsz: 640). The img_size argument should be a single integer value, not a list.

Once you make this adjustment, you should be able to train the model successfully with the desired rectangular shape (640, 480).

If you have any further questions or need additional assistance, please feel free to ask.

Best regards,
Glenn Jocher

@xingjunhong
Copy link
Author

@xingjunhong I apologize for the confusion. It seems that the issue you encountered is related to a type mismatch in the imgsz argument.

To resolve this error, make sure that the imgsz argument in the --hyp section of the yaml file is specified as a single integer (e.g., imgsz: 640). The img_size argument should be a single integer value, not a list.

Once you make this adjustment, you should be able to train the model successfully with the desired rectangular shape (640, 480).

If you have any further questions or need additional assistance, please feel free to ask.

Best regards, Glenn Jocher

但是我想训练的是(640,480)尺寸的模型,而不是(640,640)尺寸的模型

@glenn-jocher
Copy link
Member

@xingjunhong I apologize for the confusion in my previous response.

To train a YOLOv5 model with a resolution of (640, 480) instead of (640, 640), you can modify the img_size argument directly in the --hyp section of the yaml file. Simply change the value of img_size to 480. It should look like this: img_size: 480.

By setting the img_size to 480, you will be training the model with the desired rectangular shape of (640, 480).

Please let me know if you have any further questions or need any additional assistance.

Best regards,
Glenn Jocher

@JiahuiSun
Copy link

好家伙,跨语言交流,在训练的时候声明rect参数即可:python train.py --imgsz 640 --rect

@glenn-jocher
Copy link
Member

@JiahuiSun hello,

Thank you for your input. Yes, when training the YOLOv5 model, you can specify the rect parameter to resize the input images to a rectangular aspect ratio. To specify a rectangular input size of (640, 480), you can use the following command:

python train.py --imgsz 640 480 --rect

This will ensure that the input images are resized to the desired dimensions during training.

If you have any further questions or need additional assistance, please don't hesitate to ask.

Best regards,

@github-actions
Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Jul 28, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2023
@s2244521
Copy link

@xingjunhong hi there,

To train the YOLOv5 model with a rectangular shape such as (640, 480), you can modify the input size in the training configuration file. Simply edit the --img argument in the --hyp section of the yaml file to specify your desired dimensions (e.g., --img: '640, 480'). This will ensure that the input images are resized to the specified dimensions during training.

Please note that modifying the input size may affect the performance and accuracy of your model, so it's important to experiment with different sizes and evaluate the results accordingly.

If you have any further questions or encounter any issues, please don't hesitate to ask.

Best regards, Glenn Jocher
Hi @glenn-jocher ,
If I train with rectangle model and I get the bad result (low AP and Recall), what parameters you recommend that I can change to improve my model result?

Best regards, Tina

@glenn-jocher
Copy link
Member

Hi @s2244521,

If you are training a YOLOv5 model with a rectangular shape and experiencing lower AP and Recall, there are several parameters you can try adjusting to improve your model's results. Here are a few recommendations:

  1. Anchor boxes: Experiment with different anchor box configurations that better suit your dataset. You can modify the anchor.yaml file to specify anchor box sizes and aspect ratios that are more representative of your dataset.

  2. Learning rate: Adjust the learning rate in the training configuration file (--hyp.yaml). Lowering the learning rate can help the model converge more slowly and potentially improve performance.

  3. Image size: Try using different image sizes during training. You can modify the --img argument in the --hyp section of the yaml file to specify different dimensions and see if it improves your model's accuracy.

  4. Data augmentation: Explore different data augmentation techniques to increase the diversity of your training data. This can help the model generalize better to unseen examples. You can modify augmentation settings in the --data.yaml file.

Please note that these recommendations may require some experimentation and fine-tuning to find the best configuration for your specific dataset. It's always a good idea to keep track of your changes and evaluate the results using metrics such as AP and Recall.

If you have any further questions or need additional guidance, please let me know.

Best regards, Glenn Jocher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

4 participants