ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.56k stars 16.31k forks source link

How to convert from json format with Polygon labels to YOLOv7 instance segmentation Without Roboflow? #12560

Closed Yuanchihwei closed 8 months ago

Yuanchihwei commented 10 months ago

Search before asking

Question

Epoch GPU_mem box_loss seg_loss obj_loss cls_loss Instances Size 7/299 18.3G 0.06648 0.05584 0.03083 0.0004405 92 640: 100%|██████████| 260/260 [41:52<00:00, 9.66s/it] Class Images Instances Box(P R mAP50 mAP50-95) Mask(P R mAP50 mAP50-95): 100%|██████████| 33/33 [02:55<00:00, 5.32s/ all 1038 4626 0.677 0.127 0.106 0.0427 0.673 0.119 0.101 0.037

  Epoch    GPU_mem   box_loss   seg_loss   obj_loss   cls_loss  Instances       Size
  8/299      18.3G     0.0655    0.05468    0.03018  0.0003959        167        640:  34%|███▍      | 88/260 [14:58<29:16, 10.21s/it]

Traceback (most recent call last): File "D:\yolov7-u7\yolov7-u7\seg\segment\train.py", line 681, in main(opt) File "D:\yolov7-u7\yolov7-u7\seg\segment\train.py", line 577, in main train(opt.hyp, opt, device, callbacks) File "D:\yolov7-u7\yolov7-u7\seg\segment\train.py", line 295, in train for i, (imgs, targets, paths, _, masks) in pbar: # batch ------------------------------------------------------ File "D:\anaconda\Lib\site-packages\tqdm\std.py", line 1178, in iter for obj in iterable: File "D:\yolov7-u7\yolov7-u7\seg\utils\dataloaders.py", line 171, in iter yield next(self.iterator) ^^^^^^^^^^^^^^^^^^^ File "D:\anaconda\Lib\site-packages\torch\utils\data\dataloader.py", line 630, in next data = self._next_data() ^^^^^^^^^^^^^^^^^ File "D:\anaconda\Lib\site-packages\torch\utils\data\dataloader.py", line 1345, in _next_data return self._process_data(data) ^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda\Lib\site-packages\torch\utils\data\dataloader.py", line 1371, in _process_data data.reraise() File "D:\anaconda\Lib\site-packages\torch_utils.py", line 694, in reraise raise exception ValueError: Caught ValueError in DataLoader worker process 0. Original Traceback (most recent call last): File "D:\anaconda\Lib\site-packages\torch\utils\data_utils\worker.py", line 308, in _worker_loop data = fetcher.fetch(index) ^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda\Lib\site-packages\torch\utils\data_utils\fetch.py", line 51, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\anaconda\Lib\site-packages\torch\utils\data_utils\fetch.py", line 51, in data = [self.dataset[idx] for idx in possibly_batched_index]


  File "D:\yolov7-u7\yolov7-u7\seg\utils\segment\dataloaders.py", line 116, in __getitem__
    img, labels, segments = mixup(img, labels, segments, *self.load_mosaic(random.randint(0, self.n - 1)))
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\yolov7-u7\yolov7-u7\seg\utils\segment\augmentations.py", line 21, in mixup
    segments = np.concatenate((segments, segments2), 0)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<__array_function__ internals>", line 180, in concatenate
ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 3 dimension(s) and the array at index 1 has 1 dimension(s)

******I did try to train with Yolov7-seg with "python segment/train.py --data data/custom.yaml --batch 16 --weights '' --cfg yolov7-seg.yaml --epochs 300 --name yolov7-seg --img 640 --hyp hyp.scratch-high.yaml", but it appears error above, i did search articals but I can't found how to convert from json format with Polygon labels to YOLOv7 instance segmentation Without Roboflow? Beside, format issue, any other problem could cause this error? 
Source: https://github.com/WongKinYiu/yolov7/tree/u7/seg 

Current, my label text is converted using Labelme2YOLO. 
Source: https://github.com/rooneysh/Labelme2YOLO

 I am coding beginner, Please top help me, thanks**.**** 

### Additional

n/a
github-actions[bot] commented 10 months ago

👋 Hello @Yuanchihwei, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics
glenn-jocher commented 10 months ago

@Yuanchihwei make sure you are using the latest code from the Yolov7-seg branch and have correct label formatting. Check out the YOLOv5 docs for label format requirements. Good luck!

github-actions[bot] commented 9 months ago

👋 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 ⭐

mature-1111 commented 6 months ago

I meet with similar problem in yolov9. Traceback (most recent call last): File "D:/zyqi/yolov9-main/segment/train.py", line 646, in main(opt) File "D:/zyqi/yolov9-main/segment/train.py", line 542, in main train(opt.hyp, opt, device, callbacks) File "D:/zyqi/yolov9-main/segment/train.py", line 270, in train for i, (imgs, targets, paths, _, masks) in pbar: # batch ------------------------------------------------------ File "D:\anaconda3\envs\yolov9\lib\site-packages\tqdm\std.py", line 1181, in iter for obj in iterable: File "D:\zyqi\yolov9-main\utils\dataloaders.py", line 170, in iter yield next(self.iterator) File "D:\anaconda3\envs\yolov9\lib\site-packages\torch\utils\data\dataloader.py", line 628, in next data = self._next_data() File "D:\anaconda3\envs\yolov9\lib\site-packages\torch\utils\data\dataloader.py", line 671, in _next_data data = self._dataset_fetcher.fetch(index) # may raise StopIteration File "D:\anaconda3\envs\yolov9\lib\site-packages\torch\utils\data_utils\fetch.py", line 58, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\anaconda3\envs\yolov9\lib\site-packages\torch\utils\data_utils\fetch.py", line 58, in data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\zyqi\yolov9-main\utils\segment\dataloaders.py", line 116, in getitem img, labels, segments = mixup(img, labels, segments, *self.load_mosaic(random.randint(0, self.n - 1))) File "D:\zyqi\yolov9-main\utils\segment\augmentations.py", line 16, in mixup segments = np.concatenate((segments, segments2), 0) File "<__array_function__ internals>", line 200, in concatenate ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 1 has 3 dimension(s)

glenn-jocher commented 6 months ago

It seems like there's a mismatch in the dimensions of your arrays during the concatenation process in the mixup function. This often occurs when the data isn't uniformly structured. Ensure all your segments arrays have the same number of dimensions before concatenation. A quick fix could be checking and reshaping arrays if necessary before the np.concatenate call. For example:

if segments.ndim != segments2.ndim:
    # Reshape or handle arrays to match dimensions
    # Example reshaping to 3D if they are not:
    segments = segments.reshape(-1, segments.shape[0], segments.shape[1])
    segments2 = segments2.reshape(-1, segments2.shape[0], segments2.shape[1])
segments = np.concatenate((segments, segments2), 0)

This code is just a starting point; adjust as necessary based on your actual data structure. Good luck! 🚀

mature-1111 commented 6 months ago

Yes,I do it. I have converted from json format with Polygon labels to YOLOv7 instance segmentation. The solution to this problem is to  use hyp.scratch-high.yaml but set mixup to 0.0  

天空 @.***

 

------------------ 原始邮件 ------------------ 发件人: "Glenn @.>; 发送时间: 2024年4月18日(星期四) 凌晨4:18 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [ultralytics/yolov5] How to convert from json format with Polygon labels to YOLOv7 instance segmentation Without Roboflow? (Issue #12560)

It seems like there's a mismatch in the dimensions of your arrays during the concatenation process in the mixup function. This often occurs when the data isn't uniformly structured. Ensure all your segments arrays have the same number of dimensions before concatenation. A quick fix could be checking and reshaping arrays if necessary before the np.concatenate call. For example: if segments.ndim != segments2.ndim: # Reshape or handle arrays to match dimensions # Example reshaping to 3D if they are not: segments = segments.reshape(-1, segments.shape[0], segments.shape[1]) segments2 = segments2.reshape(-1, segments2.shape[0], segments2.shape[1]) segments = np.concatenate((segments, segments2), 0)

This code is just a starting point; adjust as necessary based on your actual data structure. Good luck! 🚀

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

glenn-jocher commented 6 months ago

Great to hear you've found a solution by adjusting the hyp.scratch-high.yaml and setting mixup to 0.0! 🎉 Remember, small tweaks in the hyperparameters can often resolve unexpected issues or improve training performance. If you have further questions or run into more challenges, feel free to ask. Happy training! 🚀