Closed AshingTsai closed 4 years ago
Hello @AshingTsai, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook , Docker Image, and Google Cloud Quickstart Guide for example environments.
If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.
If this is a custom model or data training question, please note that Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:
For more information please visit https://www.ultralytics.com.
ok,I got solution soon,
just put init.py in the models folder.
@AshingTsai thank you! Can you submit a PR for this please?
@glenn-jocher I use this account to submit tths PR ,thanks.
Thank you, I see it and I've merged it now!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
ok,I got solution soon,
just put init.py in the models folder. @AshingTsai where is the init.py
@AshingTsai 我也遇到了这个问题,可以详细告诉我一下怎么做嘛,谢谢
@chaishazi 我现在也遇到这个问题了,请问你现在解决了么
@glenn-jocher ,
I got the same issue today.
I follow the steps below to generate exe and run it: 1) clone the code: https://github.com/ultralytics/yolov3 2) pip install pyinstaller 3) pyinstaller detect.py 4) run detect.exe dist/detect, I got the following issue:
Traceback (most recent call last):
File "detect_image.py", line 405, in <module>
File "detect_image.py", line 365, in main
File "detect_image.py", line 293, in detection_alertarea
File "detect_image.py", line 79, in __init__
File "models\experimental.py", line 137, in attempt_load
File "torch\serialization.py", line 594, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "torch\serialization.py", line 853, in _load
result = unpickler.load()
ModuleNotFoundError: No module named 'models.yolo'
[12976] Failed to execute script detect_image
in addition, detect.py could correctly run in pycharm. I run the exe in dist/detect folder without moving it.
there is indeed a folder models, and a file named experimental.py in it. The py file could correctly used when I run detect.py in pycharm.
@glenn-jocher ,
I got the same issue today.
I follow the steps below to generate exe and run it:
- clone the code: https://github.com/ultralytics/yolov3
- pip install pyinstaller
- pyinstaller detect.py
- run detect.exe dist/detect, I got the following issue:
Traceback (most recent call last): File "detect_image.py", line 405, in <module> File "detect_image.py", line 365, in main File "detect_image.py", line 293, in detection_alertarea File "detect_image.py", line 79, in __init__ File "models\experimental.py", line 137, in attempt_load File "torch\serialization.py", line 594, in load return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args) File "torch\serialization.py", line 853, in _load result = unpickler.load() ModuleNotFoundError: No module named 'models.yolo' [12976] Failed to execute script detect_image
in addition, detect.py could correctly run in pycharm. I run the exe in dist/detect folder without moving it.
there is indeed a folder models, and a file named experimental.py in it. The py file could correctly used when I run detect.py in pycharm. @ardeal Have you solved it ? Could you provide the solution.
@PudPawat ,
see the links: https://github.com/pyinstaller/pyinstaller/issues/5531 https://github.com/ultralytics/yolov3/issues/1680
besides the upper link, there are 2 folders generated by pyinstaller, and you should run the exe in correct folder.
For anyone who is still looking for details, whenever load('weights.pt')
is called, pytorch looks for model config in path
enviornment variable, and thats where you get the error ModuleNotFoundError: No module named 'models.yolo'
.
If you are trying to load without __init__.py
or global path
variable, just add 'models' folder absolute path, load weights, and then destroy it. In case of yolov5, it can be achieved using context manager like this (Code from yolov5-pip project):
def load(weights):
yolov5_folder_dir = str(Path(__file__).parents[1].absolute()) # or models folder path
try:
sys.path.insert(0, yolov5_folder_dir)
yield # For context management OR add your model loading code here
finally:
sys.path.remove(yolov5_folder_dir)
@muhammad-tayyab Could you please tell me exactly where this code is? Thank you
这是来自QQ邮箱的假期自动回复邮件。 您好,您的来信我已收到,非常感谢。
@muhammad-tayyab Could you please tell me exactly where this code is? Thank you
That code is not part of this repo, I took it from yolov5-pip, to make it usable with pyinstaller
My solution:
这是来自QQ邮箱的假期自动回复邮件。 您好,您的来信我已收到,非常感谢。
ok,I got solution soon,
just put init.py in the models folder.
where to put init.py in the models folder
这是来自QQ邮箱的假期自动回复邮件。 您好,您的来信我已收到,非常感谢。
@wqysq hi,
Thank you for reaching out to us. I understand that you are facing an issue with the ModuleNotFoundError: No module named 'models.yolo'
when running the YOLOv5 detection script.
To resolve this issue, please make sure that there is an __init__.py
file present in the models
folder. This file is necessary for Python to recognize the folder as a package and to import the modules correctly.
You can simply create an empty __init__.py
file and place it in the models
folder. Once this file is added, the issue should be resolved, and you should be able to run the script without any problem.
Please let me know if you have any further questions or issues.
Thank you for your understanding and support.
Best regards,
Glenn Jocher
thank you for addressing the issue but I am finding the issue while running yolov3 pytorch detection script
@AyanPaul2210 hi,
Thank you for bringing this to our attention. We apologize for any confusion caused.
To better assist you with the YOLOv3 PyTorch detection script issue, could you please provide more details about the specific error message you are encountering? Additionally, it would be helpful if you could share any relevant code snippets or steps you have taken to reproduce the problem.
With this information, we will be able to investigate the issue further and provide you with a solution or guidance. We appreciate your patience and cooperation.
Kind regards,
Glenn Jocher
/content/yolov3 Namespace(epochs=100, batch_size=16, accumulate=4, cfg='cfg/yolov3-spp.cfg', data='data/roboflow.data', multi_scale=False, img_size=[416], rect=False, resume=False, nosave=False, notest=False, evolve=False, bucket='', cache_images=False, weights='weights/yolov3-spp-ultralytics.pt', name='', device='', adam=False, single_cls=False, var=None) Using CUDA device0 _CudaDeviceProperties(name='Tesla T4', total_memory=15101MB)
2023-06-24 14:38:20.281926: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-06-24 14:38:21.189957: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
WARNING: smart bias initialization failure.
WARNING: smart bias initialization failure.
WARNING: smart bias initialization failure.
Model Summary: 225 layers, 6.29987e+07 parameters, 6.29987e+07 gradients
Traceback (most recent call last):
File "/content/yolov3/train.py", line 433, in
code used
%cd /content/yolov3 !python3 train.py --data data/roboflow.data --epochs 100
@AyanPaul2210 hi,
Thank you for reaching out. From the error message you shared, it seems like the script is unable to find the module 'models.yolo' and is throwing a "ModuleNotFoundError: No module named 'models.yolo'" error.
This error typically occurs when the path to the 'models' package is not set correctly. Please double-check that the 'models' package is available and accessible in the specified file path.
Additionally, ensure that you have the necessary dependencies installed and that your environment is properly configured.
If the issue persists, please provide more details about the steps you have taken and any modifications made to the code or file structure. This will help us understand the problem better and provide you with more accurate guidance.
Looking forward to your reply.
Regards, Glenn Jocher
Hi,all
I have no idea. //---------------------------------------------------------------------------------------------------------------- Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='', fourcc='mp4v', half=False, img_size=640, iou_thres=0.5, output='inference/output', save_txt=False, source='test1.mp4', view_img=False, weights='weights/yolov5s.pt') Using CUDA device0 _CudaDeviceProperties(name='Graphics Device', total_memory=7979MB)
Traceback (most recent call last): File "detect.py", line 157, in
detect()
File "detect.py", line 21, in detect
model = torch.load(weights, map_location=device)['model']
File "/home/ashing/miniconda3/envs/pytorch/lib/python3.6/site-packages/torch/serialization.py", line 593, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "/home/ashing/miniconda3/envs/pytorch/lib/python3.6/site-packages/torch/serialization.py", line 773, in _legacy_load
result = unpickler.load()
ModuleNotFoundError: No module named 'models.yolo'
//---------------------------------------------------------------------------------------------------