Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_47816946
simple-faster-rcnn-pytorch
提交
ef0fa051
S
simple-faster-rcnn-pytorch
项目概览
weixin_47816946
/
simple-faster-rcnn-pytorch
与 Fork 源项目一致
从无法访问的项目Fork
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
simple-faster-rcnn-pytorch
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ef0fa051
编写于
12月 21, 2017
作者:
C
chenyuntc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
for caffe
上级
14d409ee
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
26 addition
and
33 deletion
+26
-33
data/dataset.py
data/dataset.py
+7
-13
model/faster_rcnn_vgg16.py
model/faster_rcnn_vgg16.py
+2
-1
model/utils/rpn_tools.py
model/utils/rpn_tools.py
+0
-2
train.py
train.py
+17
-17
未找到文件。
data/dataset.py
浏览文件 @
ef0fa051
...
...
@@ -4,6 +4,7 @@ from skimage import transform as sktsf
from
torchvision
import
transforms
as
tvtsf
from
.
import
util
from
util
import
array_tool
as
at
def
preprocess
(
img
,
min_size
=
600
,
max_size
=
1000
):
...
...
@@ -32,20 +33,13 @@ def preprocess(img, min_size=600, max_size=1000):
scale
=
min
(
scale1
,
scale2
)
# both the longer and shorter should be less than
# max_size and min_size
img
=
img
/
256.
img
=
img
/
255.
img
=
img
[[
2
,
1
,
0
],:,:]
#RGB-BGR
img
=
sktsf
.
resize
(
img
,
(
C
,
H
*
scale
,
W
*
scale
),
mode
=
'reflect'
)
normalize
=
tvtsf
.
Normalize
(
mean
=
[
0.485
,
0.456
,
0.406
],
std
=
[
0.229
,
0.224
,
0.225
])
img
=
normalize
(
t
.
from_numpy
(
img
))
return
img
.
numpy
()
# unNOTE: original implementation in chainer:
# mean=np.array([122.7717, 115.9465, 102.9801],
# img = (img - self.mean).astype(np.float32, copy=False)
# Answer: https://github.com/pytorch/vision/issues/223
# the input of vgg16 in pytorch:
# rgb 0 to 1, instead of bgr 0 to 255
img
=
img
*
255
mean
=
np
.
array
([
122.7717
,
115.9465
,
102.9801
]).
reshape
(
3
,
1
,
1
)
img
=
(
img
-
mean
).
astype
(
np
.
float32
,
copy
=
True
)
return
img
class
Transform
(
object
):
...
...
model/faster_rcnn_vgg16.py
浏览文件 @
ef0fa051
...
...
@@ -12,7 +12,8 @@ from config import opt
def
decom_vgg16
(
pretrained
=
True
):
# the 30th layer of features is relu of conv5_3
model
=
vgg16
(
pretrained
)
model
=
vgg16
(
pretrained
=
False
)
model
.
load_state_dict
(
'/home/a/code/pytorch/faster-rcnn/pytorch-faster-rcnn/data/imagenet_weights/vgg16.pth'
)
features
=
list
(
model
.
features
)[:
30
]
classifier
=
model
.
classifier
...
...
model/utils/rpn_tools.py
浏览文件 @
ef0fa051
...
...
@@ -54,7 +54,6 @@ class ProposalCreator():
n_train_post_nms
=
2000
,
n_test_pre_nms
=
6000
,
n_test_post_nms
=
300
,
force_cpu_nms
=
False
,
min_size
=
16
):
self
.
parent_model
=
parent_model
...
...
@@ -63,7 +62,6 @@ class ProposalCreator():
self
.
n_train_post_nms
=
n_train_post_nms
self
.
n_test_pre_nms
=
n_test_pre_nms
self
.
n_test_post_nms
=
n_test_post_nms
self
.
force_cpu_nms
=
force_cpu_nms
self
.
min_size
=
min_size
def
__call__
(
self
,
loc
,
score
,
...
...
train.py
浏览文件 @
ef0fa051
...
...
@@ -62,7 +62,7 @@ def train(**kwargs):
trainer
.
load
(
opt
.
load_path
)
print
(
'load pretrained model from %s'
%
opt
.
load_path
)
trainer
.
optimizer
=
trainer
.
faster_rcnn
.
get_great_optimizer
()
#
trainer.optimizer = trainer.faster_rcnn.get_great_optimizer()
trainer
.
vis
.
text
(
dataset
.
db
.
label_names
,
win
=
'labels'
)
best_map
=
0
for
epoch
in
range
(
opt
.
epoch
):
...
...
@@ -80,20 +80,20 @@ def train(**kwargs):
# plot loss
trainer
.
vis
.
plot_many
(
trainer
.
get_meter_data
())
# plot groud truth bboxes
ori_img_
=
(
img
*
0.225
+
0.45
).
clamp
(
min
=
0
,
max
=
1
)
*
255
gt_img
=
visdom_bbox
(
at
.
tonumpy
(
ori_img_
)[
0
],
at
.
tonumpy
(
bbox_
)[
0
],
label_
[
0
].
numpy
())
trainer
.
vis
.
img
(
'gt_img'
,
gt_img
)
# plot predicti bboxes
_bboxes
,
_labels
,
_scores
=
trainer
.
faster_rcnn
.
predict
(
ori_img
,
visualize
=
True
)
pred_img
=
visdom_bbox
(
at
.
tonumpy
(
ori_img
[
0
]),
at
.
tonumpy
(
_bboxes
[
0
]),
at
.
tonumpy
(
_labels
[
0
]).
reshape
(
-
1
),
at
.
tonumpy
(
_scores
[
0
]))
trainer
.
vis
.
img
(
'pred_img'
,
pred_img
)
#
#
plot groud truth bboxes
#
ori_img_ = (img * 0.225 + 0.45).clamp(min=0, max=1) * 255
#
gt_img = visdom_bbox(at.tonumpy(ori_img_)[0],
#
at.tonumpy(bbox_)[0],
#
label_[0].numpy())
#
trainer.vis.img('gt_img', gt_img)
#
#
plot predicti bboxes
#
_bboxes, _labels, _scores = trainer.faster_rcnn.predict(ori_img,visualize=True)
#
pred_img = visdom_bbox( at.tonumpy(ori_img[0]),
#
at.tonumpy(_bboxes[0]),
#
at.tonumpy(_labels[0]).reshape(-1),
#
at.tonumpy(_scores[0]))
#
trainer.vis.img('pred_img', pred_img)
# rpn confusion matrix(meter)
trainer
.
vis
.
text
(
str
(
trainer
.
rpn_cm
.
value
().
tolist
()),
win
=
'rpn_cm'
)
...
...
@@ -110,8 +110,8 @@ def train(**kwargs):
if
epoch
==
8
:
trainer
.
load
(
best_path
)
trainer
.
faster_rcnn
.
scale_lr
(
opt
.
lr_decay
)
if
epoch
==
0
:
trainer
.
optimizer
=
trainer
.
faster_rcnn
.
get_optimizer
()
#
if epoch ==0:
#
trainer.optimizer = trainer.faster_rcnn.get_optimizer()
trainer
.
vis
.
plot
(
'test_map'
,
eval_result
[
'map'
])
lr_
=
trainer
.
faster_rcnn
.
optimizer
.
param_groups
[
0
][
'lr'
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录