Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
SOLOv2-pytorch
Commits
09c3bc4c
Commit
09c3bc4c
authored
Dec 10, 2018
by
yhcao6
Browse files
rename
parent
4fcdf6e9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
11 deletions
+19
-11
configs/faster_rcnn_ohem_r50_fpn_1x.py
configs/faster_rcnn_ohem_r50_fpn_1x.py
+0
-0
mmdet/core/bbox/samplers/ohem_sampler.py
mmdet/core/bbox/samplers/ohem_sampler.py
+14
-6
mmdet/core/loss/losses.py
mmdet/core/loss/losses.py
+2
-2
mmdet/models/bbox_heads/bbox_head.py
mmdet/models/bbox_heads/bbox_head.py
+2
-2
mmdet/models/detectors/two_stage.py
mmdet/models/detectors/two_stage.py
+1
-1
No files found.
configs/faster_rcnn_r50_fpn_
ohem_
1x.py
→
configs/faster_rcnn_
ohem_
r50_fpn_1x.py
View file @
09c3bc4c
File moved
mmdet/core/bbox/samplers/ohem_sampler.py
View file @
09c3bc4c
...
@@ -21,8 +21,12 @@ class OHEMSampler(BaseSampler):
...
@@ -21,8 +21,12 @@ class OHEMSampler(BaseSampler):
self
.
bbox_roi_extractor
=
bbox_roi_extractor
self
.
bbox_roi_extractor
=
bbox_roi_extractor
self
.
bbox_head
=
bbox_head
self
.
bbox_head
=
bbox_head
def
_sample_pos
(
self
,
assign_result
,
num_expected
,
bboxes
=
None
,
def
_sample_pos
(
self
,
feats
=
None
,
**
kwargs
):
assign_result
,
num_expected
,
bboxes
=
None
,
feats
=
None
,
**
kwargs
):
"""Hard sample some positive samples."""
"""Hard sample some positive samples."""
pos_inds
=
torch
.
nonzero
(
assign_result
.
gt_inds
>
0
)
pos_inds
=
torch
.
nonzero
(
assign_result
.
gt_inds
>
0
)
if
pos_inds
.
numel
()
!=
0
:
if
pos_inds
.
numel
()
!=
0
:
...
@@ -42,12 +46,16 @@ class OHEMSampler(BaseSampler):
...
@@ -42,12 +46,16 @@ class OHEMSampler(BaseSampler):
label_weights
=
cls_score
.
new_ones
(
cls_score
.
size
(
0
)),
label_weights
=
cls_score
.
new_ones
(
cls_score
.
size
(
0
)),
bbox_targets
=
None
,
bbox_targets
=
None
,
bbox_weights
=
None
,
bbox_weights
=
None
,
reduc
tion
=
False
)[
'loss_cls'
]
reduc
e
=
False
)[
'loss_cls'
]
_
,
topk_loss_pos_inds
=
loss_pos
.
topk
(
num_expected
)
_
,
topk_loss_pos_inds
=
loss_pos
.
topk
(
num_expected
)
return
pos_inds
[
topk_loss_pos_inds
]
return
pos_inds
[
topk_loss_pos_inds
]
def
_sample_neg
(
self
,
assign_result
,
num_expected
,
bboxes
=
None
,
def
_sample_neg
(
self
,
feats
=
None
,
**
kwargs
):
assign_result
,
num_expected
,
bboxes
=
None
,
feats
=
None
,
**
kwargs
):
"""Hard sample some negative samples."""
"""Hard sample some negative samples."""
neg_inds
=
torch
.
nonzero
(
assign_result
.
gt_inds
==
0
)
neg_inds
=
torch
.
nonzero
(
assign_result
.
gt_inds
==
0
)
if
neg_inds
.
numel
()
!=
0
:
if
neg_inds
.
numel
()
!=
0
:
...
@@ -67,6 +75,6 @@ class OHEMSampler(BaseSampler):
...
@@ -67,6 +75,6 @@ class OHEMSampler(BaseSampler):
label_weights
=
cls_score
.
new_ones
(
cls_score
.
size
(
0
)),
label_weights
=
cls_score
.
new_ones
(
cls_score
.
size
(
0
)),
bbox_targets
=
None
,
bbox_targets
=
None
,
bbox_weights
=
None
,
bbox_weights
=
None
,
reduc
tion
=
False
)[
'loss_cls'
]
reduc
e
=
False
)[
'loss_cls'
]
_
,
topk_loss_neg_inds
=
loss_neg
.
topk
(
num_expected
)
_
,
topk_loss_neg_inds
=
loss_neg
.
topk
(
num_expected
)
return
neg_inds
[
topk_loss_neg_inds
]
return
neg_inds
[
topk_loss_neg_inds
]
mmdet/core/loss/losses.py
View file @
09c3bc4c
...
@@ -11,11 +11,11 @@ def weighted_nll_loss(pred, label, weight, avg_factor=None):
...
@@ -11,11 +11,11 @@ def weighted_nll_loss(pred, label, weight, avg_factor=None):
def
weighted_cross_entropy
(
pred
,
label
,
weight
,
avg_factor
=
None
,
def
weighted_cross_entropy
(
pred
,
label
,
weight
,
avg_factor
=
None
,
reduc
tion
=
True
):
reduc
e
=
True
):
if
avg_factor
is
None
:
if
avg_factor
is
None
:
avg_factor
=
max
(
torch
.
sum
(
weight
>
0
).
float
().
item
(),
1.
)
avg_factor
=
max
(
torch
.
sum
(
weight
>
0
).
float
().
item
(),
1.
)
raw
=
F
.
cross_entropy
(
pred
,
label
,
reduction
=
'none'
)
raw
=
F
.
cross_entropy
(
pred
,
label
,
reduction
=
'none'
)
if
reduc
tion
:
if
reduc
e
:
return
torch
.
sum
(
raw
*
weight
)[
None
]
/
avg_factor
return
torch
.
sum
(
raw
*
weight
)[
None
]
/
avg_factor
else
:
else
:
return
raw
*
weight
/
avg_factor
return
raw
*
weight
/
avg_factor
...
...
mmdet/models/bbox_heads/bbox_head.py
View file @
09c3bc4c
...
@@ -79,11 +79,11 @@ class BBoxHead(nn.Module):
...
@@ -79,11 +79,11 @@ class BBoxHead(nn.Module):
return
cls_reg_targets
return
cls_reg_targets
def
loss
(
self
,
cls_score
,
bbox_pred
,
labels
,
label_weights
,
bbox_targets
,
def
loss
(
self
,
cls_score
,
bbox_pred
,
labels
,
label_weights
,
bbox_targets
,
bbox_weights
,
reduc
tion
=
True
):
bbox_weights
,
reduc
e
=
True
):
losses
=
dict
()
losses
=
dict
()
if
cls_score
is
not
None
:
if
cls_score
is
not
None
:
losses
[
'loss_cls'
]
=
weighted_cross_entropy
(
losses
[
'loss_cls'
]
=
weighted_cross_entropy
(
cls_score
,
labels
,
label_weights
,
reduc
tion
=
reduc
tion
)
cls_score
,
labels
,
label_weights
,
reduc
e
=
reduc
e
)
losses
[
'acc'
]
=
accuracy
(
cls_score
,
labels
)
losses
[
'acc'
]
=
accuracy
(
cls_score
,
labels
)
if
bbox_pred
is
not
None
:
if
bbox_pred
is
not
None
:
losses
[
'loss_reg'
]
=
weighted_smoothl1
(
losses
[
'loss_reg'
]
=
weighted_smoothl1
(
...
...
mmdet/models/detectors/two_stage.py
View file @
09c3bc4c
...
@@ -119,7 +119,7 @@ class TwoStageDetector(BaseDetector, RPNTestMixin, BBoxTestMixin,
...
@@ -119,7 +119,7 @@ class TwoStageDetector(BaseDetector, RPNTestMixin, BBoxTestMixin,
proposal_list
[
i
],
proposal_list
[
i
],
gt_bboxes
[
i
],
gt_bboxes
[
i
],
gt_labels
[
i
],
gt_labels
[
i
],
feats
=
[
xx
[
i
][
None
]
for
xx
in
x
])
feats
=
[
lvl_feat
[
i
][
None
]
for
lvl_feat
in
x
])
assign_results
.
append
(
assign_result
)
assign_results
.
append
(
assign_result
)
sampling_results
.
append
(
sampling_result
)
sampling_results
.
append
(
sampling_result
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment