Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
525cfc71
Commit
525cfc71
authored
Aug 14, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added more tests for copy_tensor()
parent
7078cfaf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
110 additions
and
0 deletions
+110
-0
dnn.cpp
dlib/test/dnn.cpp
+110
-0
No files found.
dlib/test/dnn.cpp
View file @
525cfc71
...
...
@@ -1831,6 +1831,60 @@ namespace
}
}
}
void
test_copy_tensor_add_to_cpu
()
{
using
namespace
dlib
::
tt
;
print_spinner
();
resizable_tensor
dest
(
10
,
9
,
7
,
15
);
resizable_tensor
src1
(
10
,
3
,
7
,
15
);
resizable_tensor
src2
(
10
,
3
,
7
,
15
);
resizable_tensor
src3
(
10
,
9
,
7
,
15
);
tt
::
tensor_rand
rnd
;
rnd
.
fill_gaussian
(
dest
);
rnd
.
fill_gaussian
(
src1
);
rnd
.
fill_gaussian
(
src2
);
rnd
.
fill_gaussian
(
src3
);
const
resizable_tensor
old_dest
=
dest
;
cpu
::
copy_tensor
(
true
,
dest
,
0
,
src1
,
0
,
src1
.
k
());
//full copy src1->dest
cpu
::
copy_tensor
(
true
,
dest
,
src1
.
k
(),
src2
,
0
,
src2
.
k
());
//full copy src2->dest with offset of src1
cpu
::
copy_tensor
(
true
,
dest
,
src1
.
k
()
+
src2
.
k
(),
src3
,
3
,
3
);
//partial copy src3 into the rest place of dest
for
(
long
i
=
0
;
i
<
dest
.
num_samples
();
++
i
)
{
for
(
long
k
=
0
;
k
<
dest
.
k
();
++
k
)
{
for
(
long
r
=
0
;
r
<
dest
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
dest
.
nc
();
++
c
)
{
float
old_dest_value
=
tensor_read_cpu
(
old_dest
,
i
,
k
,
r
,
c
);
float
dest_value
=
tensor_read_cpu
(
dest
,
i
,
k
,
r
,
c
);
// first part is from src1
if
(
k
<
src1
.
k
())
{
float
src_value
=
tensor_read_cpu
(
src1
,
i
,
k
,
r
,
c
)
+
old_dest_value
;
DLIB_TEST
(
std
::
abs
(
src_value
-
dest_value
)
<
1e-6
);
}
// second part is from src2
else
if
(
k
<
src1
.
k
()
+
src2
.
k
())
{
float
src_value
=
tensor_read_cpu
(
src2
,
i
,
k
-
src1
.
k
(),
r
,
c
)
+
old_dest_value
;
DLIB_TEST
(
std
::
abs
(
src_value
-
dest_value
)
<
1e-6
);
}
// third part is from src3
else
{
float
src_value
=
tensor_read_cpu
(
src3
,
i
,
k
-
src1
.
k
()
-
src2
.
k
()
+
3
,
r
,
c
)
+
old_dest_value
;
DLIB_TEST
(
std
::
abs
(
src_value
-
dest_value
)
<
1e-6
);
}
}
}
}
}
}
#ifdef DLIB_USE_CUDA
void
test_copy_tensor_gpu
()
{
...
...
@@ -1882,6 +1936,60 @@ namespace
}
}
}
void
test_copy_tensor_add_to_gpu
()
{
using
namespace
dlib
::
tt
;
print_spinner
();
resizable_tensor
dest
(
10
,
9
,
7
,
15
);
resizable_tensor
src1
(
10
,
3
,
7
,
15
);
resizable_tensor
src2
(
10
,
3
,
7
,
15
);
resizable_tensor
src3
(
10
,
9
,
7
,
15
);
tt
::
tensor_rand
rnd
;
rnd
.
fill_gaussian
(
dest
);
rnd
.
fill_gaussian
(
src1
);
rnd
.
fill_gaussian
(
src2
);
rnd
.
fill_gaussian
(
src3
);
const
resizable_tensor
old_dest
=
dest
;
cuda
::
copy_tensor
(
true
,
dest
,
0
,
src1
,
0
,
src1
.
k
());
//full copy src1->dest
cuda
::
copy_tensor
(
true
,
dest
,
src1
.
k
(),
src2
,
0
,
src2
.
k
());
//full copy src2->dest with offset of src1
cuda
::
copy_tensor
(
true
,
dest
,
src1
.
k
()
+
src2
.
k
(),
src3
,
3
,
3
);
//partial copy src3 into the rest place of dest
for
(
long
i
=
0
;
i
<
dest
.
num_samples
();
++
i
)
{
for
(
long
k
=
0
;
k
<
dest
.
k
();
++
k
)
{
for
(
long
r
=
0
;
r
<
dest
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
dest
.
nc
();
++
c
)
{
float
old_dest_value
=
tensor_read_cpu
(
old_dest
,
i
,
k
,
r
,
c
);
float
dest_value
=
tensor_read_cpu
(
dest
,
i
,
k
,
r
,
c
);
// first part is from src1
if
(
k
<
src1
.
k
())
{
float
src_value
=
tensor_read_cpu
(
src1
,
i
,
k
,
r
,
c
)
+
old_dest_value
;
DLIB_TEST_MSG
(
std
::
abs
(
src_value
-
dest_value
)
<
1e-6
,
std
::
abs
(
src_value
-
dest_value
));
}
// second part is from src2
else
if
(
k
<
src1
.
k
()
+
src2
.
k
())
{
float
src_value
=
tensor_read_cpu
(
src2
,
i
,
k
-
src1
.
k
(),
r
,
c
)
+
old_dest_value
;
DLIB_TEST
(
std
::
abs
(
src_value
-
dest_value
)
<
1e-6
);
}
// third part is from src3
else
{
float
src_value
=
tensor_read_cpu
(
src3
,
i
,
k
-
src1
.
k
()
-
src2
.
k
()
+
3
,
r
,
c
)
+
old_dest_value
;
DLIB_TEST
(
std
::
abs
(
src_value
-
dest_value
)
<
1e-6
);
}
}
}
}
}
}
#endif//DLIB_USE_CUDA
template
<
typename
SUBNET
>
using
concat_block1
=
con
<
5
,
1
,
1
,
1
,
1
,
SUBNET
>
;
...
...
@@ -2710,6 +2818,7 @@ namespace
test_multiply_zero_padded
();
compare_adam
();
test_copy_tensor_gpu
();
test_copy_tensor_add_to_gpu
();
#endif
test_tensor_resize_bilinear
(
2
,
3
,
6
,
6
,
11
,
11
);
test_tensor_resize_bilinear
(
2
,
3
,
6
,
6
,
3
,
4
);
...
...
@@ -2747,6 +2856,7 @@ namespace
test_layers
();
test_visit_funcions
();
test_copy_tensor_cpu
();
test_copy_tensor_add_to_cpu
();
test_concat
();
test_simple_linear_regression
();
test_simple_linear_regression_with_mult_prev
();
...
...
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