Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
stoneliu1981
pytorch-image-models
提交
6f9a0c8e
P
pytorch-image-models
项目概览
stoneliu1981
/
pytorch-image-models
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
pytorch-image-models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6f9a0c8e
编写于
4月 01, 2019
作者:
R
Ross Wightman
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:rwightman/pytorch-models
上级
d87824bd
5cb1a35c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
12 addition
and
30 deletion
+12
-30
data/random_erasing.py
data/random_erasing.py
+2
-2
models/resnext.py
models/resnext.py
+10
-28
未找到文件。
data/random_erasing.py
浏览文件 @
6f9a0c8e
...
...
@@ -115,9 +115,9 @@ class RandomErasingTorch:
h
=
int
(
round
(
math
.
sqrt
(
target_area
*
aspect_ratio
)))
w
=
int
(
round
(
math
.
sqrt
(
target_area
/
aspect_ratio
)))
if
self
.
rand_color
:
c
=
torch
.
empty
(
chan
,
dtype
=
batch
.
dtype
,
device
=
self
.
device
).
normal_
()
c
=
torch
.
empty
(
(
chan
,
1
,
1
)
,
dtype
=
batch
.
dtype
,
device
=
self
.
device
).
normal_
()
elif
not
self
.
per_pixel
:
c
=
torch
.
zeros
(
chan
,
dtype
=
batch
.
dtype
,
device
=
self
.
device
)
c
=
torch
.
zeros
(
(
chan
,
1
,
1
)
,
dtype
=
batch
.
dtype
,
device
=
self
.
device
)
if
w
<
img_w
and
h
<
img_h
:
top
=
random
.
randint
(
0
,
img_h
-
h
)
left
=
random
.
randint
(
0
,
img_w
-
w
)
...
...
models/resnext.py
浏览文件 @
6f9a0c8e
...
...
@@ -19,7 +19,7 @@ class ResNeXtBottleneckC(nn.Module):
def
__init__
(
self
,
inplanes
,
planes
,
stride
=
1
,
downsample
=
None
,
cardinality
=
32
,
base_width
=
4
):
super
(
ResNeXtBottleneckC
,
self
).
__init__
()
width
=
math
.
floor
(
planes
/
64
*
cardinality
*
base_width
)
width
=
math
.
floor
(
planes
*
(
base_width
/
64
))
*
cardinality
self
.
conv1
=
nn
.
Conv2d
(
inplanes
,
width
,
kernel_size
=
1
,
bias
=
False
)
self
.
bn1
=
nn
.
BatchNorm2d
(
width
)
...
...
@@ -57,13 +57,12 @@ class ResNeXtBottleneckC(nn.Module):
class
ResNeXt
(
nn
.
Module
):
def
__init__
(
self
,
block
,
layers
,
num_classes
=
1000
,
cardinality
=
32
,
base_width
=
4
,
shortcut
=
'C'
,
def
__init__
(
self
,
block
,
layers
,
num_classes
=
1000
,
cardinality
=
32
,
base_width
=
4
,
drop_rate
=
0.
,
global_pool
=
'avg'
):
self
.
num_classes
=
num_classes
self
.
inplanes
=
64
self
.
cardinality
=
cardinality
self
.
base_width
=
base_width
self
.
shortcut
=
shortcut
self
.
drop_rate
=
drop_rate
super
(
ResNeXt
,
self
).
__init__
()
self
.
conv1
=
nn
.
Conv2d
(
3
,
64
,
kernel_size
=
7
,
stride
=
2
,
padding
=
3
,
bias
=
False
)
...
...
@@ -87,31 +86,17 @@ class ResNeXt(nn.Module):
def
_make_layer
(
self
,
block
,
planes
,
blocks
,
stride
=
1
):
downsample
=
None
reshape
=
stride
!=
1
or
self
.
inplanes
!=
planes
*
block
.
expansion
use_conv
=
(
self
.
shortcut
==
'C'
)
or
(
self
.
shortcut
==
'B'
and
reshape
)
if
use_conv
:
if
stride
!=
1
or
self
.
inplanes
!=
planes
*
block
.
expansion
:
downsample
=
nn
.
Sequential
(
nn
.
Conv2d
(
self
.
inplanes
,
planes
*
block
.
expansion
,
kernel_size
=
1
,
stride
=
stride
,
bias
=
False
),
nn
.
BatchNorm2d
(
planes
*
block
.
expansion
),
)
elif
reshape
:
downsample
=
nn
.
AvgPool2d
(
3
,
stride
=
stride
)
layers
=
[
block
(
self
.
inplanes
,
planes
,
stride
,
downsample
,
self
.
cardinality
,
self
.
base_width
)]
self
.
inplanes
=
planes
*
block
.
expansion
if
self
.
shortcut
==
'C'
:
shortcut
=
nn
.
Sequential
(
nn
.
Conv2d
(
self
.
inplanes
,
planes
*
block
.
expansion
,
kernel_size
=
1
,
stride
=
1
,
bias
=
False
),
nn
.
BatchNorm2d
(
planes
*
block
.
expansion
),
)
else
:
shortcut
=
None
for
i
in
range
(
1
,
blocks
):
layers
.
append
(
block
(
self
.
inplanes
,
planes
,
1
,
shortcut
,
self
.
cardinality
,
self
.
base_width
))
layers
.
append
(
block
(
self
.
inplanes
,
planes
,
1
,
None
,
self
.
cardinality
,
self
.
base_width
))
return
nn
.
Sequential
(
*
layers
)
...
...
@@ -151,7 +136,7 @@ class ResNeXt(nn.Module):
return
x
def
resnext50
(
cardinality
=
32
,
base_width
=
4
,
shortcut
=
'C'
,
pretrained
=
False
,
**
kwargs
):
def
resnext50
(
cardinality
=
32
,
base_width
=
4
,
pretrained
=
False
,
**
kwargs
):
"""Constructs a ResNeXt-50 model.
Args:
...
...
@@ -160,12 +145,11 @@ def resnext50(cardinality=32, base_width=4, shortcut='C', pretrained=False, **kw
shortcut ('A'|'B'|'C'): 'B' use 1x1 conv to downsample, 'C' use 1x1 conv on every residual connection
"""
model
=
ResNeXt
(
ResNeXtBottleneckC
,
[
3
,
4
,
6
,
3
],
cardinality
=
cardinality
,
base_width
=
base_width
,
shortcut
=
shortcut
,
**
kwargs
)
ResNeXtBottleneckC
,
[
3
,
4
,
6
,
3
],
cardinality
=
cardinality
,
base_width
=
base_width
,
**
kwargs
)
return
model
def
resnext101
(
cardinality
=
32
,
base_width
=
4
,
shortcut
=
'C'
,
pretrained
=
False
,
**
kwargs
):
def
resnext101
(
cardinality
=
32
,
base_width
=
4
,
pretrained
=
False
,
**
kwargs
):
"""Constructs a ResNeXt-101 model.
Args:
...
...
@@ -174,12 +158,11 @@ def resnext101(cardinality=32, base_width=4, shortcut='C', pretrained=False, **k
shortcut ('A'|'B'|'C'): 'B' use 1x1 conv to downsample, 'C' use 1x1 conv on every residual connection
"""
model
=
ResNeXt
(
ResNeXtBottleneckC
,
[
3
,
4
,
23
,
3
],
cardinality
=
cardinality
,
base_width
=
base_width
,
shortcut
=
shortcut
,
**
kwargs
)
ResNeXtBottleneckC
,
[
3
,
4
,
23
,
3
],
cardinality
=
cardinality
,
base_width
=
base_width
,
**
kwargs
)
return
model
def
resnext152
(
cardinality
=
32
,
base_width
=
4
,
shortcut
=
'C'
,
pretrained
=
False
,
**
kwargs
):
def
resnext152
(
cardinality
=
32
,
base_width
=
4
,
pretrained
=
False
,
**
kwargs
):
"""Constructs a ResNeXt-152 model.
Args:
...
...
@@ -188,6 +171,5 @@ def resnext152(cardinality=32, base_width=4, shortcut='C', pretrained=False, **k
shortcut ('A'|'B'|'C'): 'B' use 1x1 conv to downsample, 'C' use 1x1 conv on every residual connection
"""
model
=
ResNeXt
(
ResNeXtBottleneckC
,
[
3
,
8
,
36
,
3
],
cardinality
=
cardinality
,
base_width
=
base_width
,
shortcut
=
shortcut
,
**
kwargs
)
ResNeXtBottleneckC
,
[
3
,
8
,
36
,
3
],
cardinality
=
cardinality
,
base_width
=
base_width
,
**
kwargs
)
return
model
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录