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

关于调用推理代码块遇到的与一些问题 #2207

Open
1 of 2 tasks
Pandoravirus-N-T opened this issue Apr 26, 2024 · 8 comments
Open
1 of 2 tasks

关于调用推理代码块遇到的与一些问题 #2207

Pandoravirus-N-T opened this issue Apr 26, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@Pandoravirus-N-T
Copy link

Search before asking

  • I have searched the YOLOv3 issues and found no similar bug report.

YOLOv3 Component

No response

Bug

D:\anaconda\envs\master1\lib\site-packages\torch\hub.py:268: UserWarning: You are about to download and run code from an untrusted repository. In a future release, this won't be allowed. To add the repository to your trusted list, change the command to {calling_fn}(..., trust_repo=False) and a command prompt will appear asking for an explicit confirmation of trust, or load(..., trust_repo=True), which will assume that the prompt is to be answered with 'yes'. You can also use load(..., trust_repo='check') which will only prompt for confirmation if the repo is not already trusted. This will eventually be the default behaviour
"You are about to download and run code from an untrusted repository. In a future release, this won't "
Downloading: "https://github.com/ultralytics/yolov3/zipball/master" to C:\Users\Lenovo/.cache\torch\hub\master.zip
Traceback (most recent call last):
File "C:\Users\Lenovo\Desktop\xin\KinD-master\evaluate.py", line 118, in
model = torch.hub.load("ultralytics/yolov3", "yolov3") # or yolov5n - yolov5x6, custom
File "D:\anaconda\envs\KinD-master1\lib\site-packages\torch\hub.py", line 542, in load
model = _load_local(repo_or_dir, model, *args, **kwargs)
File "D:\anaconda\envs\KinD-master1\lib\site-packages\torch\hub.py", line 571, in _load_local
entry = _load_entry_from_hubconf(hub_module, model)
File "D:\anaconda\envs\KinD-master1\lib\site-packages\torch\hub.py", line 321, in _load_entry_from_hubconf
raise RuntimeError('Cannot find callable {} in hubconf'.format(model))
RuntimeError: Cannot find callable yolov3 in hubconf

Environment

用的pyton3.7版本

Minimal Reproducible Example

No response

Additional

是不是这个路径出了一些问题呀作者,期待您的回复

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@Pandoravirus-N-T Pandoravirus-N-T added the bug Something isn't working label Apr 26, 2024
Copy link

👋 Hello @Pandoravirus-N-T, thank you for your interest in YOLOv3 🚀! 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/yolov3  # clone
cd yolov3
pip install -r requirements.txt  # install

Environments

YOLOv3 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv3 CI

If this badge is green, all YOLOv3 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv3 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

您好!👋

看起来您在尝试通过 torch.hub.load 加载YOLOv3时遇到了问题。这个错误可能是因为您尝试加载的模型名称不正确,或者是使用方式有所偏差。

确保您正在使用的Torch版本与YOLOv3兼容。对于这个具体的问题,建议使用以下代码示例正确加载模型:

import torch

# 确保模型名称是正确的
model = torch.hub.load('ultralytics/yolov3', 'yolov3', pretrained=True)

如果您仍然遇到问题,请参考我们的官方文档 https://docs.ultralytics.com/ 获取更多帮助和指导。

祝编码愉快!如果有进一步的问题,我们一直在这里帮助您。

@Pandoravirus-N-T
Copy link
Author

Pandoravirus-N-T commented Apr 27, 2024

你好这是我的代码
import torch
from torchvision.models import detection

Model

model = torch.hub.load("ultralytics/yolov3", "yolov3", trust_repo=True)
model.load_state_dict(torch.load(r"\yolov3-tiny.pt")) # Load pretrained weights from local file

Images

img = r"results\test.png" # or file, Path, PIL, OpenCV, numpy, list

Inference

results = model(img)

Results

results.print() # or .show(), .save(), .crop(), .pandas(), etc.
我的报错为
RuntimeError: Cannot find callable yolov3 in hubconf
我不知道如何修改了,我的理解是位置变动或者因为网络不好造成的,有没有比如调包的方式在本地运行

@glenn-jocher
Copy link
Member

您好!😊

遇到的问题可能是由于尝试用torch.hub.load直接加载"yolov3"模型时发生的一些混淆,以及在加载本地权重文件时的用法上有点小错误。给您提供一下建议:

确保模型正确加载,后续再用本地权重更新模型,可以使用以下代码:

import torch

# 正确加载模型
model = torch.hub.load('ultralytics/yolov3', 'yolov3', pretrained=True, trust_repo=True)

# 加载本地权重文件(如果你有YOLOv3的权重,并希望用它来更新模型)
weights_path = "path/to/your/yolov3-tiny.pt"  # 请确保这里的路径是正确的
model.load_state_dict(torch.load(weights_path))

注意,请替换 "path/to/your/yolov3-tiny.pt" 为您本地权重文件的实际路径。

如果您要处理的是本地图片文件,可以这样使用:

img_path = "path/to/your/test.png"  # 确保这里的路径是正确的
results = model(img_path)
results.print()  # 或其他结果处理方式,如.show(), .save()等

希望这能帮到您!如果仍有疑问,请随时向我们反馈。👍

@Pandoravirus-N-T
Copy link
Author

按您的方法修改后还是报错
import torch

正确加载模型

model = torch.hub.load('ultralytics/yolov3', 'yolov3', pretrained=True, trust_repo=True)

加载本地权重文件(如果你有YOLOv3的权重,并希望用它来更新模型)

weights_path = r“\yolov3-tiny.pt" # 请确保这里的路径是正确的
model.load_state_dict(torch.load(weights_path))
img_path = r"test_kindle.png" # 确保这里的路径是正确的
results = model(img_path)
results.print() # 或其他结果处理方式,如.show(), .save()等
报错为
Using cache found in C:\Users\Lenovo/.cache\torch\hub\ultralytics_yolov3_master
Traceback (most recent call last):
File "C:\Users\Lenovo\Desktop\pythonProject\main.py", line 4, in
model = torch.hub.load('ultralytics/yolov3', 'yolov3', pretrained=True, trust_repo=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\torch\hub.py", line 566, in load
model = _load_local(repo_or_dir, model, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\torch\hub.py", line 594, in _load_local
entry = _load_entry_from_hubconf(hub_module, model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python\Lib\site-packages\torch\hub.py", line 348, in _load_entry_from_hubconf
raise RuntimeError(f'Cannot find callable {model} in hubconf')
RuntimeError: Cannot find callable yolov3 in hubconf
好像还是不太行,有没有办法单独把框架下载下来,是不是只能把项目拉下来在本地运行了

@glenn-jocher
Copy link
Member

您好!😊

看起来问题仍然存在,可能是因为torch.hub在查找模型时遇到了一些困难。这种情况下,一个可行的解决方案是直接从GitHub克隆YOLOv3的仓库,并使用本地版本运行模型。这样可以避开torch.hub.load可能遇到的问题。请按照以下步骤操作:

  1. 从GitHub克隆YOLOv3仓库到您的本地环境。
  2. 使用本地代码加载模型及权重。

下面的代码示例假设您已经将YOLOv3仓库克隆到本地,并在相应的环境中运行:

import torch
from models import *  # 确保这是从您克隆的YOLOv3仓库中导入的
from utils import *   # 同上

# 初始化模型
model = Darknet('path/to/your/yolov3.cfg').cuda()  # 配置文件路径
model.load_weights('path/to/your/yolov3-tiny.pt')  # 权重文件路径

# 加载图片
img_path = 'path/to/your/test.png'
img = load_images(img_path)  # 使用YOLOv3仓库中的utils函数或自定义的加载图片方法

# 推理
results = model(img)
results.print()  # 或使用其他方式处理结果

请确保替换所有的'path/to/...'为您的实际文件路径。

希望这个方法对您有所帮助!如果还有其他问题,请随时告诉我们。

@Pandoravirus-N-T
Copy link
Author

嗯好的,谢谢作者您的答复。我在下载模型和参数时发现都是v5的模型,影响吗,因为我的python解释器是3.7版本的

@glenn-jocher
Copy link
Member

您好!😊

非常高兴能帮到您。使用v5模型在Python 3.7上是没问题的,只要确保您的环境中安装了兼容的Torch版本即可。YOLOv5是YOLO系列中的最新版,提供了许多改进和新功能,应该能够很好地满足您的需求。

如果您的项目特定需要使用YOLOv3并且您已经下载了YOLOv5的模型,建议您访问YOLOv3的GitHub页面或使用YOLOv3的直接下载链接来获取YOLOv3模型和权重文件。

祝您编码愉快!如果还有其他问题,请随时联系。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants