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

Image not found yolo v8l #11890

Closed
puneet2059 opened this issue Jul 22, 2023 · 19 comments
Closed

Image not found yolo v8l #11890

puneet2059 opened this issue Jul 22, 2023 · 19 comments
Labels

Comments

@puneet2059
Copy link

I am training a yolo v8l model with input image 512*512 (3400 images) .
Model will run for 35 epochs and then show

AssertionError Traceback (most recent call last)
in <cell line: 3>()
1 from ultralytics import YOLO
2 model=YOLO("yolov8l.yaml")
----> 3 results=model.train(data="/content/drive/MyDrive/Colab Notebooks/yolo/data.yaml",epochs=50,batch=2)

7 frames
/usr/local/lib/python3.10/dist-packages/torch/_utils.py in reraise(self)
642 # instantiate since we don't know how to
643 raise RuntimeError(msg) from None
--> 644 raise exception
645
646

AssertionError: Caught AssertionError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.10/dist-packages/ultralytics/yolo/data/base.py", line 180, in getitem
return self.transforms(self.get_label_info(index))
File "/usr/local/lib/python3.10/dist-packages/ultralytics/yolo/data/base.py", line 184, in get_label_info
label["img"], label["ori_shape"], label["resized_shape"] = self.load_image(index)
File "/usr/local/lib/python3.10/dist-packages/ultralytics/yolo/data/base.py", line 123, in load_image
assert im is not None, f"Image Not Found {f}"
AssertionError: Image Not Found /content/drive/MyDrive/Colab Notebooks/yolo/train/images/sub_image_1_0_IMG_0393.JPG

This error keeps changing with different image names, but when I check my images and label folder, everything is there. I referred to previously given solutions like removing the cache file if present and checking the presence of image and the right format.
But everything looks pefect.

@github-actions
Copy link
Contributor

👋 Hello @puneet2059, 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.7.0 with all requirements.txt installed including PyTorch>=1.7. 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
Copy link
Member

@puneet2059 make sure to verify that the image paths in your dataset configuration file (data.yaml) are correct. The error message suggests that the DataLoader is unable to find the image at the specified path (/content/drive/MyDrive/Colab Notebooks/yolo/train/images/sub_image_1_0_IMG_0393.JPG).

Please double-check the following:

  • The image file exists in the specified directory.
  • The file name is spelled correctly, including the file extension.
  • The path is correctly specified in the data.yaml file.

If you have confirmed that the image paths are correct, try printing out some of the image paths during data loading to see if there is anything unusual. You can add a few lines of code to YOLOv5's load_image function to print the image path before the assertion:

...
def load_image(self, index):
    image_path = self.image_files[index]  # Add this line to print the image path
    print(f"Loading image: {image_path}")
    im = ...
    ...

Please let me know if you continue to encounter issues or need any further assistance.

@puneet2059
Copy link
Author

puneet2059 commented Jul 24, 2023

hi I did this to check whether I have all the files or not
import os

def check_files_exist(image_folder, label_folder):
image_files = os.listdir(image_folder)
label_files = os.listdir(label_folder)

missing_images = []
missing_labels = []

for image_file in image_files:
    image_path = os.path.join(image_folder, image_file)
    label_file = image_file.replace(".jpg", ".txt")
    label_path = os.path.join(label_folder, label_file)
    
    if not os.path.exists(image_path):
        missing_images.append(image_file)
    
    if not os.path.exists(label_path):
        missing_labels.append(label_file)

return missing_images, missing_labels

Example usage:

images_folder = "/content/drive/MyDrive/Colab Notebooks/train/images"
labels_folder = "/content/drive/MyDrive/Colab Notebooks/train/labels"

missing_images, missing_labels = check_files_exist(images_folder, labels_folder)

if len(missing_images) > 0:
print("Missing image files:")
for image_file in missing_images:
print(image_file)

if len(missing_labels) > 0:
print("Missing label files:")
for label_file in missing_labels:
print(label_file)
it is showing names of the missing label with respect to images but if I search for these files in my drive they are present there with the proper label and images,
what should I do ?

@glenn-jocher
Copy link
Member

@puneet2059 it seems that the code you provided is correctly checking for missing image and label files in the specified directories. However, it is strange that the missing files are being reported even though they are present in your drive.

To troubleshoot this issue, I recommend the following steps:

  1. Double-check the file paths: Verify that the images_folder and labels_folder variables in your code accurately point to the correct directory where the image and label files are located. Make sure there are no typos or incorrect paths.

  2. Confirm the file extensions: Ensure that the file extensions for the images and labels match the expected format. In your code, you are checking for images with the ".jpg" extension and corresponding label files with the ".txt" extension. Make sure the actual files have the correct extensions.

  3. Check for case sensitivity: File system behavior can vary depending on the operating system. Ensure that the filenames and paths in your code match the case sensitivity of the actual files in your drive. For example, if your code is looking for "image.jpg" but the file is actually named "Image.jpg", it may not be recognized.

  4. Verify permissions: Make sure you have read permissions for the directories and files in question. If the files are located in a different directory or accessible only to specific users, you may encounter issues when trying to access them.

If you have completed these steps and are still experiencing the issue, please provide more context or additional code snippets that may help us understand and debug the problem further.

@puneet2059
Copy link
Author

AssertionError Traceback (most recent call last)
in <cell line: 7>()
5
6 # Train the model
----> 7 results = model.train(data="/content/drive/MyDrive/Colab Notebooks/data.yaml", epochs=50)
8
9

7 frames
/usr/local/lib/python3.10/dist-packages/ultralytics/yolo/engine/model.py in train(self, **kwargs)
205 self.trainer.model = self.trainer.get_model(weights=self.model if self.ckpt else None, cfg=self.model.yaml)
206 self.model = self.trainer.model
--> 207 self.trainer.train()
208 # update model and cfg after training
209 self.model, _ = attempt_load_one_weight(str(self.trainer.best))

/usr/local/lib/python3.10/dist-packages/ultralytics/yolo/engine/trainer.py in train(self)
181 ddp_cleanup(command, self)
182 else:
--> 183 self._do_train(int(os.getenv("RANK", -1)), world_size)
184
185 def _setup_ddp(self, rank, world_size):

/usr/local/lib/python3.10/dist-packages/ultralytics/yolo/engine/trainer.py in _do_train(self, rank, world_size)
282 self.tloss = None
283 self.optimizer.zero_grad()
--> 284 for i, batch in pbar:
285 self.run_callbacks("on_train_batch_start")
286 # Warmup

/usr/local/lib/python3.10/dist-packages/tqdm/std.py in iter(self)
1176
1177 try:
-> 1178 for obj in iterable:
1179 yield obj
1180 # Update and possibly print the progressbar.

/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py in next(self)
631 # TODO(pytorch/pytorch#76750)
632 self._reset() # type: ignore[call-arg]
--> 633 data = self._next_data()
634 self._num_yielded += 1
635 if self._dataset_kind == _DatasetKind.Iterable and \

/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py in _next_data(self)
1343 else:
1344 del self._task_info[idx]
-> 1345 return self._process_data(data)
1346
1347 def _try_put_index(self):

/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py in _process_data(self, data)
1369 self._try_put_index()
1370 if isinstance(data, ExceptionWrapper):
-> 1371 data.reraise()
1372 return data
1373

/usr/local/lib/python3.10/dist-packages/torch/_utils.py in reraise(self)
642 # instantiate since we don't know how to
643 raise RuntimeError(msg) from None
--> 644 raise exception
645
646

AssertionError: Caught AssertionError in DataLoader worker process 1.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.10/dist-packages/ultralytics/yolo/data/base.py", line 180, in getitem
return self.transforms(self.get_label_info(index))
File "/usr/local/lib/python3.10/dist-packages/ultralytics/yolo/data/base.py", line 184, in get_label_info
label["img"], label["ori_shape"], label["resized_shape"] = self.load_image(index)
File "/usr/local/lib/python3.10/dist-packages/ultralytics/yolo/data/base.py", line 123, in load_image
assert im is not None, f"Image Not Found {f}"
AssertionError: Image Not Found /content/drive/MyDrive/Colab Notebooks/train/images/sub_image_0_3_IMG_0486.JPG
still facing same error but at 47 epoch it keeps on changing I checked everything.

@puneet2059
Copy link
Author

do you think changing image and label name can help ?
for example :sub_image_0_0_IMG_0193 to IMG0193

@glenn-jocher
Copy link
Member

@puneet2059 changing the image and label names may help resolve the issue you are facing. By simplifying the names and removing special characters, you can eliminate any potential file naming discrepancies that might cause the DataLoader to fail in finding the images.

I suggest modifying the names to a simple format, such as 'IMG0193.jpg' for the image and 'IMG0193.txt' for the corresponding label. Ensure that both the image and label files have the same base name and appropriate extensions.

After making the changes, update your dataset configuration file (data.yaml) to reflect the new file names. Verify that the image_folder and label_folder paths in your code also match the updated file names.

Once you have made these adjustments, try running the training process again and see if the error persists.

Let me know if you have any further questions or encounter any other issues.

@puneet2059
Copy link
Author

But there is one thing that I have already run this model on the same images but at that time they were unprocessed and then it was working. But now it is very weird that I am getting this error.

@glenn-jocher
Copy link
Member

@puneet2059 hi,

It's strange that you are encountering this error after running the model on the same images without any issues before. It's possible that some changes or processing done to the images may be causing the problem.

To troubleshoot this issue, I recommend the following steps:

  1. Verify the changes: Review any recent modifications or processing steps applied to the images. Check if any transformations or resizing could potentially impact the loading of images in the training process.

  2. Confirm the image format: Ensure that the images are in a compatible format supported by YOLOv5 (e.g., JPEG or PNG). If the images were converted to a different format or have unusual file extensions, it may cause the DataLoader to fail.

  3. Check the image paths: Double-check that the image paths specified in your dataset configuration file (data.yaml) are correct and match the new image names or directory structure.

  4. Validate the data preprocessing: Verify that the data preprocessing steps applied to the images are correctly handled and synchronized with the training process. Ensure that any resizing, cropping, or augmentation operations are properly implemented and do not cause image loading issues.

By carefully reviewing these factors, you should be able to pinpoint the cause of the error and resolve it. If you have any further questions or need additional assistance, please don't hesitate to ask.

Thank you.

@puneet2059
Copy link
Author

Is it by any chance that since I am using free version of google collab and that's the reason why its showing error after sometime ?

@glenn-jocher
Copy link
Member

@puneet2059 hi there,

Using the free version of Google Colab should not be the cause of the error you are experiencing while running YOLOv5. The free version of Google Colab provides limited computational resources, such as GPU and storage space, but it should not impact the functionality or stability of the model itself.

The error you are facing might be related to other factors, such as incorrect image or label file paths, unsupported image formats, or issues with the data preprocessing steps. I recommend double-checking these aspects to ensure everything is set up correctly.

If you are still encountering the error after verifying these factors, please provide more details, such as the specific error message or traceback, any recent changes you made to the code or data, and any other relevant information. This will help us further investigate and assist you in resolving the issue.

Let me know if you have any more questions or need additional help.

Thank you.

@puneet2059
Copy link
Author

I tried again with same image name but the only difference was that i used 1300 images and it ran successfully with 50 epochs .

@glenn-jocher
Copy link
Member

@puneet2059 hi there,

That's great to hear that you were able to run the YOLOv5 model successfully with 1300 images and 50 epochs! It's possible that the previous error you encountered was specific to the image processing or data loading for a particular subset of images.

If you encounter any further issues or have any questions, feel free to ask. We're here to assist you.

Thank you.

@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 Aug 31, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 10, 2023
@yiluzhou1
Copy link

I did have exactly the same issue "AssertionError: Image Not Found" after a certain number of epochs. With the same dataset in the folder, for most times, it can run successfully for 150 epochs... Not sure why sometimes it stuck after several epochs at a random Image Not Found. I've verified that the image file did exist there.
I've searched around, and found many people have the same issue. I wonder if it is concurrency issue, I'll try num_workers=1, and see if this problem can go away.

@puneet2059
Copy link
Author

I tried this with Google Colab plus it worked fine every time I run. That's the only change I did.

@glenn-jocher
Copy link
Member

@yiluzhou1 hi there,

Thank you for sharing your experience with running YOLOv5 on Google Colab. It's great to hear that you were able to run it successfully without encountering the "Image Not Found" issue.

In some cases, running the code on different platforms or environments can have an impact on the execution and stability of the training process. It's possible that the issue you encountered previously may have been specific to your local setup.

If you have any further questions or concerns, feel free to reach out. We're here to assist you.

Thank you.

@yiluzhou1
Copy link

@yiluzhou1 hi there,

Thank you for sharing your experience with running YOLOv5 on Google Colab. It's great to hear that you were able to run it successfully without encountering the "Image Not Found" issue.

In some cases, running the code on different platforms or environments can have an impact on the execution and stability of the training process. It's possible that the issue you encountered previously may have been specific to your local setup.

If you have any further questions or concerns, feel free to reach out. We're here to assist you.

Thank you.

@yiluzhou1 hi there,

Thank you for sharing your experience with running YOLOv5 on Google Colab. It's great to hear that you were able to run it successfully without encountering the "Image Not Found" issue.

In some cases, running the code on different platforms or environments can have an impact on the execution and stability of the training process. It's possible that the issue you encountered previously may have been specific to your local setup.

If you have any further questions or concerns, feel free to reach out. We're here to assist you.

Thank you.

Thanks for your response! I've tried num_workers=1, the "Image Not Found" issue persists occasionally. Unfortunately, I couldn't use other platforms or Google Colab, as I'm doing training on internal clinical images. Probably I can add "try... except" in dataloaders.py to bypass this error in case of unsuccessful read images.

@glenn-jocher
Copy link
Member

@yiluzhou1 thanks for your response! It's unfortunate that the "Image Not Found" issue still persists occasionally even after trying num_workers=1. Considering your specific use case with internal clinical images, using other platforms or Google Colab may not be feasible.

One possible approach to handle the "Image Not Found" issue is to add a try... except block in the dataloader.py file. By implementing error handling, you can bypass the error and continue the training process even in cases where the images are not successfully read.

Feel free to give this approach a try and let us know if it resolves the issue for you. If you have any further questions or need additional assistance, feel free to ask. We're here to help.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants