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
OpenDAS
dlib
Commits
f0c0b307
Unverified
Commit
f0c0b307
authored
Dec 08, 2021
by
Adrià Arrufat
Committed by
GitHub
Dec 07, 2021
Browse files
Fix crash when truth center is outside of the image (#2471)
parent
a2c47603
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
dlib/dnn/loss.h
dlib/dnn/loss.h
+4
-4
No files found.
dlib/dnn/loss.h
View file @
f0c0b307
...
@@ -3682,7 +3682,7 @@ namespace dlib
...
@@ -3682,7 +3682,7 @@ namespace dlib
tensor
&
grad
=
layer
<
TAG_TYPE
>
(
sub
).
get_gradient_input
();
tensor
&
grad
=
layer
<
TAG_TYPE
>
(
sub
).
get_gradient_input
();
DLIB_CASSERT
(
input_tensor
.
num_samples
()
==
grad
.
num_samples
());
DLIB_CASSERT
(
input_tensor
.
num_samples
()
==
grad
.
num_samples
());
DLIB_CASSERT
(
input_tensor
.
num_samples
()
==
output_tensor
.
num_samples
());
DLIB_CASSERT
(
input_tensor
.
num_samples
()
==
output_tensor
.
num_samples
());
const
doub
le
input_
a
re
a
=
input_tensor
.
nr
()
*
input_tensor
.
nc
();
const
rectang
le
input_re
ct
(
input_tensor
.
nr
()
,
input_tensor
.
nc
()
)
;
float
*
g
=
grad
.
host
();
float
*
g
=
grad
.
host
();
// Compute the objectness loss for all grid cells
// Compute the objectness loss for all grid cells
...
@@ -3709,7 +3709,7 @@ namespace dlib
...
@@ -3709,7 +3709,7 @@ namespace dlib
double
best_iou
=
0
;
double
best_iou
=
0
;
for
(
const
yolo_rect
&
truth_box
:
*
truth
)
for
(
const
yolo_rect
&
truth_box
:
*
truth
)
{
{
if
(
truth_box
.
ignore
)
if
(
truth_box
.
ignore
||
!
input_rect
.
contains
(
center
(
truth_box
.
rect
))
)
continue
;
continue
;
best_iou
=
std
::
max
(
best_iou
,
box_intersection_over_union
(
truth_box
.
rect
,
pred
.
rect
));
best_iou
=
std
::
max
(
best_iou
,
box_intersection_over_union
(
truth_box
.
rect
,
pred
.
rect
));
}
}
...
@@ -3724,7 +3724,7 @@ namespace dlib
...
@@ -3724,7 +3724,7 @@ namespace dlib
// Now find the best anchor box for each truth box
// Now find the best anchor box for each truth box
for
(
const
yolo_rect
&
truth_box
:
*
truth
)
for
(
const
yolo_rect
&
truth_box
:
*
truth
)
{
{
if
(
truth_box
.
ignore
)
if
(
truth_box
.
ignore
||
!
input_rect
.
contains
(
center
(
truth_box
.
rect
))
)
continue
;
continue
;
const
dpoint
t_center
=
dcenter
(
truth_box
);
const
dpoint
t_center
=
dcenter
(
truth_box
);
double
best_iou
=
0
;
double
best_iou
=
0
;
...
@@ -3780,7 +3780,7 @@ namespace dlib
...
@@ -3780,7 +3780,7 @@ namespace dlib
const
double
th
=
truth_box
.
rect
.
height
()
/
(
anchors
[
a
].
height
+
truth_box
.
rect
.
height
());
const
double
th
=
truth_box
.
rect
.
height
()
/
(
anchors
[
a
].
height
+
truth_box
.
rect
.
height
());
// Scale regression error according to the truth size
// Scale regression error according to the truth size
const
double
scale_box
=
options
.
lambda_box
*
(
2
-
truth_box
.
rect
.
area
()
/
input_area
);
const
double
scale_box
=
options
.
lambda_box
*
(
2
-
truth_box
.
rect
.
area
()
/
input_
rect
.
area
()
);
// Compute the gradient for the box coordinates
// Compute the gradient for the box coordinates
g
[
x_idx
]
=
scale_box
*
(
out_data
[
x_idx
]
-
tx
);
g
[
x_idx
]
=
scale_box
*
(
out_data
[
x_idx
]
-
tx
);
...
...
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