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

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

Closed
1 task done
Yuanchihwei opened this issue Dec 31, 2023 · 7 comments
Labels
question Further information is requested Stale

Comments

@Yuanchihwei
Copy link

Yuanchihwei commented Dec 31, 2023

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

@Yuanchihwei Yuanchihwei added the question Further information is requested label Dec 31, 2023
Copy link
Contributor

👋 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

@Yuanchihwei Yuanchihwei changed the title How to convert from json format with Polygon labels to YOLOv5 instance segmentation Without Roboflow? How to convert from json format with Polygon labels to YOLOv7 instance segmentation Without Roboflow? Dec 31, 2023
@glenn-jocher
Copy link
Member

@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!

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 Jan 31, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 11, 2024
@mature-1111
Copy link

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
Copy link
Member

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
Copy link

mature-1111 commented Apr 18, 2024 via email

@glenn-jocher
Copy link
Member

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! 🚀

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

3 participants