pytorch-YOLOv4 icon indicating copy to clipboard operation
pytorch-YOLOv4 copied to clipboard

cannot find the images when training my personal dataset

Open Rich2333 opened this issue 3 years ago • 13 comments

Epoch 1/300: 0%| | 0/40 [00:00<?, ?img/s] Traceback (most recent call last): File "train.py", line 623, in train(model=model, File "train.py", line 370, in train for i, batch in enumerate(train_loader): File "/home/richlinux/anaconda3/envs/torch/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 435, in next data = self._next_data() File "/home/richlinux/anaconda3/envs/torch/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data return self._process_data(data) File "/home/richlinux/anaconda3/envs/torch/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data data.reraise() File "/home/richlinux/anaconda3/envs/torch/lib/python3.8/site-packages/torch/_utils.py", line 428, in reraise raise self.exc_type(msg) cv2.error: Caught error in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/richlinux/anaconda3/envs/torch/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop data = fetcher.fetch(index) File "/home/richlinux/anaconda3/envs/torch/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 "/home/richlinux/anaconda3/envs/torch/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 "/home/richlinux/pytorch-YOLOv4-master/dataset.py", line 298, in getitem img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-99ib2vsi/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

Rich2333 avatar Nov 22 '20 02:11 Rich2333

Are you giving it the correct dataset_dir to find your images and annotations? Note that argparse may overwrite the dataset_dir from cfg.py using its default val : https://github.com/Tianxiaomo/pytorch-YOLOv4/blob/master/train.py#L540-L541

11prateek avatar Nov 23 '20 04:11 11prateek

Do you solve this problem?My dataset_dir is correct but i still get the"cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-99ib2vsi/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'"

pengpenglab avatar Nov 25 '20 06:11 pengpenglab

Try printing out the 'img_path on this line: https://github.com/Tianxiaomo/pytorch-YOLOv4/blob/master/dataset.py#L274

Check to see if the relative path to the image is correct.

11prateek avatar Nov 26 '20 19:11 11prateek

Are you giving it the correct dataset_dir to find your images and annotations? Note that argparse may overwrite the dataset_dir from cfg.py using its default val : https://github.com/Tianxiaomo/pytorch-YOLOv4/blob/master/train.py#L540-L541

Thanks for the advice! I've checked it again and uses the absolute path, but still not work...

Rich2333 avatar Nov 27 '20 12:11 Rich2333

Try printing out the 'img_path on this line: https://github.com/Tianxiaomo/pytorch-YOLOv4/blob/master/dataset.py#L274

Check to see if the relative path to the image is correct.

Thank you! I'll try it again

Rich2333 avatar Nov 27 '20 12:11 Rich2333

Do you solve this problem?My dataset_dir is correct but i still get the"cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-99ib2vsi/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'"

No... I'm wondering if there's something wrong with my train images(e.g.: size or other properties). Actually I've tried both relative path and absolute path, but it still shows the same error. "cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-99ib2vsi/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'"

Rich2333 avatar Nov 27 '20 12:11 Rich2333

Try printing out the 'img_path on this line: https://github.com/Tianxiaomo/pytorch-YOLOv4/blob/master/dataset.py#L274

Check to see if the relative path to the image is correct.

I put the images in this path "D:\yolov4_torch\pytorch-YOLOv4-master\trainImage", then I use the command "python train.py -l 0.001 -g 0 -pretrained ./data/yolov4.conv.137.pth -classes 10 -dir D:/yolov4_torch/pytorch-YOLOv4-master/trainImage" and "python train.py -l 0.001 -g 0 -pretrained ./data/yolov4.conv.137.pth -classes 10 -dir ./trainImage". But both didn't work and shows the same error as I wrote in this issue :(

Rich2333 avatar Nov 27 '20 12:11 Rich2333

Thanks a lot for all these advice! I cannot solve, and find that yolov5 works well. lol

Rich2333 avatar Dec 05 '20 06:12 Rich2333

Do you solve this problem?My dataset_dir is correct but i still get the"cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-99ib2vsi/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'"

Do you solve this problem?I have the same problem. I have checked my dataset_dir. dataset_dir is correct.But i still get this error.

minttz avatar Mar 25 '21 09:03 minttz

Do you solve this problem?My dataset_dir is correct but i still get the"cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-99ib2vsi/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'"

Do you solve this problem?I have the same problem. I have checked my dataset_dir. dataset_dir is correct.But i still get this error.

I have the same problem then I modify the line code : img_path = os.path.join(self.cfg.dataset_dir, img_path) then it work

thienpm92 avatar Apr 28 '21 11:04 thienpm92

I solved this problem。 My dataset format is img_path x1,y1,x2,y2,1 Then I modified one place in dataset.py. previous: data = line.strip('\n').split(" ") modified: data = line.strip('\n').split(" ") Because when image is background, the img_path would be xxx.jpg\n,witch is wrong,and cv2 can't cvt it。

robot-lfr avatar Dec 09 '21 08:12 robot-lfr

I solved this problem。 My dataset format is img_path x1,y1,x2,y2,1 Then I modified one place in dataset.py. previous: data = line.strip('\n').split(" ") modified: data = line.strip('\n').split(" ") Because when image is background, the img_path would be xxx.jpg\n,witch is wrong,and cv2 can't cvt it。

It's the same before and after you changed it,and I changed it like you said,it didn't work too

wallfacer2 avatar Jan 11 '22 14:01 wallfacer2

Do you solve this problem?My dataset_dir is correct but i still get the"cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-99ib2vsi/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'"

Do you solve this problem?I have the same problem. I have checked my dataset_dir. dataset_dir is correct.But i still get this error.

I have the same problem then I modify the line code : img_path = os.path.join(self.cfg.dataset_dir, img_path) then it work

hi,repository source code in dataset.py is the code you changed, and i try it again, it doesn't work too.

wallfacer2 avatar Jan 11 '22 14:01 wallfacer2