Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
8b8b7928
提交
8b8b7928
authored
6月 16, 2020
作者:
Lornatang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
There is no need to download extra packages, official bring it with you
I submitted it once in your yolov3 project, you seem to accept it? I'm not sure. I'll submit PR again.
上级
0c4b4b88
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
12 行增加
和
7 行删除
+12
-7
torch_utils.py
utils/torch_utils.py
+12
-7
没有找到文件。
utils/torch_utils.py
浏览文件 @
8b8b7928
...
...
@@ -7,6 +7,7 @@ import torch
import
torch.backends.cudnn
as
cudnn
import
torch.nn
as
nn
import
torch.nn.functional
as
F
import
torchvision.models
as
models
def
init_seeds
(
seed
=
0
):
...
...
@@ -120,18 +121,22 @@ def model_info(model, verbose=False):
def
load_classifier
(
name
=
'resnet101'
,
n
=
2
):
# Loads a pretrained model reshaped to n-class output
import
pretrainedmodels
# https://github.com/Cadene/pretrained-models.pytorch#torchvision
model
=
pretrainedmodels
.
__dict__
[
name
](
num_classes
=
1000
,
pretrained
=
'imagenet'
)
model
=
models
.
__dict__
[
name
](
pretrained
=
True
)
# Display model properties
for
x
in
[
'model.input_size'
,
'model.input_space'
,
'model.input_range'
,
'model.mean'
,
'model.std'
]:
input_size
=
[
3
,
224
,
224
]
input_space
=
'RGB'
input_range
=
[
0
,
1
]
mean
=
[
0.485
,
0.456
,
0.406
]
std
=
[
0.229
,
0.224
,
0.225
]
for
x
in
[
input_size
,
input_space
,
input_range
,
mean
,
std
]:
print
(
x
+
' ='
,
eval
(
x
))
# Reshape output to n classes
filters
=
model
.
last_linear
.
weight
.
shape
[
1
]
model
.
last_linear
.
bias
=
torch
.
nn
.
Parameter
(
torch
.
zeros
(
n
)
)
model
.
last_linear
.
weight
=
torch
.
nn
.
Parameter
(
torch
.
zeros
(
n
,
filters
)
)
model
.
last_linear
.
out_features
=
n
filters
=
model
.
fc
.
weight
.
shape
[
1
]
model
.
fc
.
bias
=
torch
.
nn
.
Parameter
(
torch
.
zeros
(
n
),
requires_grad
=
True
)
model
.
fc
.
weight
=
torch
.
nn
.
Parameter
(
torch
.
zeros
(
n
,
filters
),
requires_grad
=
True
)
model
.
fc
.
out_features
=
n
return
model
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论