ultralytics / yolov5

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

ValueError: attempted relative import beyond top-level package #11903

Closed Beingbe7 closed 1 year ago

Beingbe7 commented 1 year ago

Search before asking

Question

When i run train.py, ValueError: attempted relative import beyond top-level package, how to 解决

Additional

No response

github-actions[bot] commented 1 year ago

👋 Hello @Beingbe7, 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 commented 1 year ago

@Beingbe7 hi there!

It seems like you're encountering a ValueError with the message "attempted relative import beyond top-level package" when running train.py. This error typically occurs when there is an issue with the way you are importing modules or packages within your code.

To help you resolve this issue, could you provide more information about your setup and the specific code where you're seeing this error? This will help us better understand the problem and provide you with a more accurate solution.

Looking forward to your response!

Beingbe7 commented 1 year ago

I have solved the problem. But now a new problem is that after I annotate the data and fill in the data set path in the data configuration file, he still reports errors:No labels found in /home/rpdzkj/Desktop/zzs/3test/yolo/image.cache, can not start training. why?Is this file being generated automatically? When is that? image c6a42918c094d1e882f3629d42999a8

There's something wrong with my data set?

glenn-jocher commented 1 year ago

@Beingbe7 it looks like you're encountering an issue with the YOLOv5 training process.

The error message indicates that no labels were found in the specified image cache path. The image cache file is typically created automatically during the annotation process.

To resolve this issue, please double-check the following:

  1. Ensure that you have correctly annotated your dataset and saved the annotations in the expected format (e.g., YOLO format).
  2. Verify that the image cache file (image.cache) is present in the specified directory (/home/rpdzkj/Desktop/zzs/3test/yolo).

If the image cache file is missing, you may need to re-annotate your dataset or check if there was an issue during the annotation process.

Please let me know if you have any further questions or if there's anything else I can assist you with.

Beingbe7 commented 1 year ago

@glenn-jocher thanks for your help! 1.This is a screenshot of the image I annotated, in the format yolo image I annotated it on a windows computer and copied it to a linux computer。

  1. The image cache file (image.cache) is present in the specified directory (/home/rpdzkj/Desktop/zzs/3test/yolo).But I don't know why there is 0 image after he scans the image.cache. Image. cache is not generated according to the image file? image Is there a problem with my folder name? I named image instead of images
glenn-jocher commented 1 year ago

@Beingbe7, thank you for providing the additional information. Let's try to troubleshoot the issue.

  1. The annotated image you shared seems to be in the correct YOLO format. The format should be <class index> <x_center> <y_center> <width> <height> for each bounding box annotation.

  2. The presence of the image cache file (image.cache) in the specified directory is a good sign. However, it seems that the training script is not able to recognize any images from the cache. This may suggest an issue with the cache file or the image file paths.

To further investigate, could you please check the following:

Regarding your folder name, the script should be able to handle an "image" folder instead of an "images" folder, as long as the folder structure and file paths are correctly indicated in the image cache file.

Please let me know if you have any further questions or if there's anything else I can assist you with.

Beingbe7 commented 1 year ago

@jkocherhans I can start training already, I just changed image to images, I want to know why

glenn-jocher commented 1 year ago

@Beingbe7 It's great to hear that you were able to start training by changing "image" to "images". The reason for this change is most likely related to the expected folder structure and naming conventions in the YOLOv5 training script.

By default, the training script expects the annotated images to be stored in a folder named "images" (plural), and the corresponding annotation files to be in the YOLO format. This is the standard convention used in YOLOv5.

In your case, changing "image" to "images" aligns with the expected folder structure, allowing the training script to locate and properly utilize your annotated image dataset.

Please let me know if you have any more questions or if there's anything else I can assist you with.

github-actions[bot] commented 1 year 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 ⭐