torchvision.models.resnet和torch.hub.load的不同之处是什么?

发布于 2025-01-30 03:25:04 字数 292 浏览 4 评论 0原文

有两种使用Pytorch重新系统的方法。

方法1:

import torch
model = torch.hub.load('pytorch/vision:v0.10.0', 'resnet50', pretrained=True)
model.eval()

方法2:

import torch    
net = models.resnet50(pretrained=True)

它们是否加载相同的模型。如果不是,有什么区别?

There are two method for using resnet of pytorch.

methods 1:

import torch
model = torch.hub.load('pytorch/vision:v0.10.0', 'resnet50', pretrained=True)
model.eval()

methods 2:

import torch    
net = models.resnet50(pretrained=True)

Are they load the same model. If not what is the difference?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柏拉图鍀咏恒 2025-02-06 03:25:04

如果您以这种方式加载模型,则唯一的区别是层的数量,因为您正在加载resnet18使用 torch hub resnet50带有模型(因此,也是预验证的权重)。它们的行为不同,您可以在

Torch Hub 还可以让您在存储库中发布预估计的模型,但是由于您是从'pytorch/vision加载它的:v0.10.0.0'(它是从相同的存储库模型正在加载神经网络),之间应没有区别

model = torch.hub.load('pytorch/vision', 'resnet18', pretrained=True)

model = models.resnet18(pretrained=True)

The only difference that there is between your models if you load them in that way it's the number of layers, since you're loading resnet18 with Torch Hub and resnet50 with Models (thus, also the pretrained weights). They behave differently, you can see more about that in this paper.

Torch Hub also lets you publish pretrained models in your repository, but since you're loading it from 'pytorch/vision:v0.10.0' (which is the same repository from which Models is loading the neural networks), there should be no difference between:

model = torch.hub.load('pytorch/vision', 'resnet18', pretrained=True)

and

model = models.resnet18(pretrained=True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文