Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_47816946
simple-faster-rcnn-pytorch
提交
7b8a36ed
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,体验更适合开发者的 AI 搜索 >>
提交
7b8a36ed
编写于
12月 20, 2017
作者:
C
chenyuntc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix predict mis-delete
上级
c74f2214
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
76 addition
and
1 deletion
+76
-1
model/faster_rcnn.py
model/faster_rcnn.py
+75
-0
train.py
train.py
+1
-1
未找到文件。
model/faster_rcnn.py
浏览文件 @
7b8a36ed
...
@@ -278,6 +278,81 @@ class FasterRCNN(nn.Module):
...
@@ -278,6 +278,81 @@ class FasterRCNN(nn.Module):
self
.
use_preset
(
'evaluate'
)
self
.
use_preset
(
'evaluate'
)
self
.
train
()
self
.
train
()
return
bboxes
,
labels
,
scores
return
bboxes
,
labels
,
scores
def
predict2
(
self
,
prepared_imgs
,
sizes
):
"""Detect objects from images.
This method predicts objects for each image.
Args:
imgs (iterable of numpy.ndarray): Arrays holding images.
All images are in CHW and RGB format
and the range of their value is :math:`[0, 255]`.
Returns:
tuple of lists:
This method returns a tuple of three lists,
:obj:`(bboxes, labels, scores)`.
* **bboxes**: A list of float arrays of shape :math:`(R, 4)`,
\
where :math:`R` is the number of bounding boxes in a image.
\
Each bouding box is organized by
\
:math:`(y_{min}, x_{min}, y_{max}, x_{max})`
\
in the second axis.
* **labels** : A list of integer arrays of shape :math:`(R,)`.
\
Each value indicates the class of the bounding box.
\
Values are in range :math:`[0, L - 1]`, where :math:`L` is the
\
number of the foreground classes.
* **scores** : A list of float arrays of shape :math:`(R,)`.
\
Each value indicates how confident the prediction is.
"""
self
.
eval
()
# self.use_preset('visualize')
self
.
use_preset
(
'evaluate'
)
bboxes
=
list
()
labels
=
list
()
scores
=
list
()
for
img
,
size
in
zip
(
prepared_imgs
,
sizes
):
img
=
t
.
autograd
.
Variable
(
at
.
totensor
(
img
).
float
()[
None
],
volatile
=
True
)
scale
=
img
.
shape
[
3
]
/
size
[
1
]
roi_cls_loc
,
roi_scores
,
rois
,
_
=
self
(
img
,
scale
=
scale
)
# We are assuming that batch size is 1.
# roi_cls_loc = at.tonumpy(roi_cls_locs)#.data.numpy()
roi_score
=
roi_scores
.
data
roi_cls_loc
=
roi_cls_loc
.
data
roi
=
at
.
totensor
(
rois
)
/
scale
# Convert predictions to bounding boxes in image coordinates.
# Bounding boxes are scaled to the scale of the input images.
mean
=
t
.
Tensor
(
self
.
loc_normalize_mean
).
cuda
().
\
repeat
(
self
.
n_class
)[
None
]
std
=
t
.
Tensor
(
self
.
loc_normalize_std
).
cuda
().
\
repeat
(
self
.
n_class
)[
None
]
roi_cls_loc
=
(
roi_cls_loc
*
std
+
mean
)
roi_cls_loc
=
roi_cls_loc
.
view
(
-
1
,
self
.
n_class
,
4
)
roi
=
roi
.
view
(
-
1
,
1
,
4
).
expand_as
(
roi_cls_loc
)
cls_bbox
=
loc2bbox
(
at
.
tonumpy
(
roi
).
reshape
((
-
1
,
4
)),
at
.
tonumpy
(
roi_cls_loc
).
reshape
((
-
1
,
4
)))
cls_bbox
=
at
.
totensor
(
cls_bbox
)
cls_bbox
=
cls_bbox
.
view
(
-
1
,
self
.
n_class
*
4
)
# clip bounding box
cls_bbox
[:,
0
::
2
]
=
(
cls_bbox
[:,
0
::
2
]).
clamp
(
min
=
0
,
max
=
size
[
0
])
cls_bbox
[:,
1
::
2
]
=
(
cls_bbox
[:,
1
::
2
]).
clamp
(
min
=
0
,
max
=
size
[
1
])
prob
=
at
.
tonumpy
(
F
.
softmax
(
at
.
tovariable
(
roi_score
),
dim
=
1
))
raw_cls_bbox
=
at
.
tonumpy
(
cls_bbox
)
raw_prob
=
at
.
tonumpy
(
prob
)
bbox
,
label
,
score
=
self
.
_suppress
(
raw_cls_bbox
,
raw_prob
)
bboxes
.
append
(
bbox
)
labels
.
append
(
label
)
scores
.
append
(
score
)
# self.use_preset('evaluate')
self
.
train
()
return
bboxes
,
labels
,
scores
def
get_optimizer_group
(
self
):
def
get_optimizer_group
(
self
):
self
.
lr1
,
self
.
lr2
,
self
.
lr3
=
opt
.
lr1
,
opt
.
lr2
,
opt
.
lr3
self
.
lr1
,
self
.
lr2
,
self
.
lr3
=
opt
.
lr1
,
opt
.
lr2
,
opt
.
lr3
...
...
train.py
浏览文件 @
7b8a36ed
...
@@ -22,7 +22,7 @@ def eval(dataloader, faster_rcnn, test_num=10000):
...
@@ -22,7 +22,7 @@ def eval(dataloader, faster_rcnn, test_num=10000):
gt_bboxes
,
gt_labels
,
gt_difficults
=
list
(),
list
(),
list
()
gt_bboxes
,
gt_labels
,
gt_difficults
=
list
(),
list
(),
list
()
for
ii
,
(
imgs
,
sizes
,
gt_bboxes_
,
gt_labels_
,
gt_difficults_
)
in
tqdm
(
enumerate
(
dataloader
)):
for
ii
,
(
imgs
,
sizes
,
gt_bboxes_
,
gt_labels_
,
gt_difficults_
)
in
tqdm
(
enumerate
(
dataloader
)):
sizes
=
[
sizes
[
0
][
0
],
sizes
[
1
][
0
]]
sizes
=
[
sizes
[
0
][
0
],
sizes
[
1
][
0
]]
pred_bboxes_
,
pred_labels_
,
pred_scores_
=
faster_rcnn
.
predict
(
imgs
,
[
sizes
])
pred_bboxes_
,
pred_labels_
,
pred_scores_
=
faster_rcnn
.
predict
2
(
imgs
,
[
sizes
])
gt_bboxes
+=
list
(
gt_bboxes_
.
numpy
())
gt_bboxes
+=
list
(
gt_bboxes_
.
numpy
())
gt_labels
+=
list
(
gt_labels_
.
numpy
())
gt_labels
+=
list
(
gt_labels_
.
numpy
())
gt_difficults
+=
list
(
gt_difficults_
.
numpy
())
gt_difficults
+=
list
(
gt_difficults_
.
numpy
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录