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
0e923cff
Commit
0e923cff
authored
Apr 18, 2020
by
Davis King
Browse files
A little bit of cleanup
parent
55e9c890
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
5 deletions
+9
-5
dlib/cuda/cuda_dlib.h
dlib/cuda/cuda_dlib.h
+8
-4
dlib/test/dnn.cpp
dlib/test/dnn.cpp
+1
-1
No files found.
dlib/cuda/cuda_dlib.h
View file @
0e923cff
...
@@ -498,6 +498,8 @@ namespace dlib
...
@@ -498,6 +498,8 @@ namespace dlib
mutable
cuda_data_void_ptr
buf
;
mutable
cuda_data_void_ptr
buf
;
};
};
// ----------------------------------------------------------------------------------------
class
compute_loss_multiclass_log_per_pixel
class
compute_loss_multiclass_log_per_pixel
{
{
/*!
/*!
...
@@ -557,6 +559,8 @@ namespace dlib
...
@@ -557,6 +559,8 @@ namespace dlib
mutable
cuda_data_void_ptr
buf
;
mutable
cuda_data_void_ptr
buf
;
};
};
// ----------------------------------------------------------------------------------------
class
compute_loss_mean_squared_per_channel_and_pixel
class
compute_loss_mean_squared_per_channel_and_pixel
{
{
/*!
/*!
...
@@ -581,15 +585,15 @@ namespace dlib
...
@@ -581,15 +585,15 @@ namespace dlib
)
const
)
const
{
{
const
auto
image_size
=
subnetwork_output
.
nr
()
*
subnetwork_output
.
nc
()
*
subnetwork_output
.
k
();
const
auto
image_size
=
subnetwork_output
.
nr
()
*
subnetwork_output
.
nc
()
*
subnetwork_output
.
k
();
const
size_t
bytes_per_
plan
e
=
image_size
*
sizeof
(
float
);
const
size_t
bytes_per_
imag
e
=
image_size
*
sizeof
(
float
);
// Allocate a cuda buffer to store all the truth images and also one float
// Allocate a cuda buffer to store all the truth images and also one float
// for the scalar loss output.
// for the scalar loss output.
buf
=
device_global_buffer
(
subnetwork_output
.
num_samples
()
*
bytes_per_
plan
e
+
sizeof
(
float
));
buf
=
device_global_buffer
(
subnetwork_output
.
num_samples
()
*
bytes_per_
imag
e
+
sizeof
(
float
));
cuda_data_ptr
<
float
>
loss_buf
=
static_pointer_cast
<
float
>
(
buf
,
1
);
cuda_data_ptr
<
float
>
loss_buf
=
static_pointer_cast
<
float
>
(
buf
,
1
);
buf
=
buf
+
sizeof
(
float
);
buf
=
buf
+
sizeof
(
float
);
const
size_t
bytes_per_
chan
ne
l
=
subnetwork_output
.
nr
()
*
subnetwork_output
.
nc
()
*
sizeof
(
float
);
const
size_t
bytes_per_
pla
ne
=
subnetwork_output
.
nr
()
*
subnetwork_output
.
nc
()
*
sizeof
(
float
);
// copy the truth data into a cuda buffer.
// copy the truth data into a cuda buffer.
for
(
long
i
=
0
;
i
<
subnetwork_output
.
num_samples
();
++
i
,
++
truth
)
for
(
long
i
=
0
;
i
<
subnetwork_output
.
num_samples
();
++
i
,
++
truth
)
...
@@ -599,7 +603,7 @@ namespace dlib
...
@@ -599,7 +603,7 @@ namespace dlib
for
(
size_t
j
=
0
;
j
<
t
.
size
();
++
j
)
{
for
(
size_t
j
=
0
;
j
<
t
.
size
();
++
j
)
{
DLIB_ASSERT
(
t
[
j
].
nr
()
==
subnetwork_output
.
nr
());
DLIB_ASSERT
(
t
[
j
].
nr
()
==
subnetwork_output
.
nr
());
DLIB_ASSERT
(
t
[
j
].
nc
()
==
subnetwork_output
.
nc
());
DLIB_ASSERT
(
t
[
j
].
nc
()
==
subnetwork_output
.
nc
());
memcpy
(
buf
+
i
*
bytes_per_
plan
e
+
j
*
bytes_per_
chan
ne
l
,
&
t
[
j
](
0
,
0
),
bytes_per_
chan
ne
l
);
memcpy
(
buf
+
i
*
bytes_per_
imag
e
+
j
*
bytes_per_
pla
ne
,
&
t
[
j
](
0
,
0
),
bytes_per_
pla
ne
);
}
}
}
}
...
...
dlib/test/dnn.cpp
View file @
0e923cff
...
@@ -2640,7 +2640,7 @@ namespace
...
@@ -2640,7 +2640,7 @@ namespace
tensor
&
grad
=
net
.
subnet
().
get_gradient_input
();
tensor
&
grad
=
net
.
subnet
().
get_gradient_input
();
cuda_compute
(
labels
.
begin
(),
output_tensor
,
grad
,
cuda_loss
);
cuda_compute
(
labels
.
begin
(),
output_tensor
,
grad
,
cuda_loss
);
cpu_compute
(
labels
.
begin
(),
output_tensor
,
grad
,
cpu_loss
);
cpu_compute
(
labels
.
begin
(),
output_tensor
,
grad
,
cpu_loss
);
const
auto
err
=
::
std
::
abs
<
double
>
(
cuda_loss
-
cpu_loss
)
/
cpu_loss
;
const
auto
err
=
abs
(
cuda_loss
-
cpu_loss
)
/
cpu_loss
;
DLIB_TEST_MSG
(
err
<
1e-6
,
"multi channel cuda and cpu losses differ"
);
DLIB_TEST_MSG
(
err
<
1e-6
,
"multi channel cuda and cpu losses differ"
);
#endif
#endif
}
}
...
...
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