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
038c73d8
Commit
038c73d8
authored
Dec 06, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up the tensor_conv interface a little. Also fixed an error in the spec
for this object.
parent
83ecf1d9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
67 deletions
+87
-67
cudnn_dlibapi.cpp
dlib/dnn/cudnn_dlibapi.cpp
+44
-7
cudnn_dlibapi.h
dlib/dnn/cudnn_dlibapi.h
+32
-24
tensor_tools.cpp
dlib/dnn/tensor_tools.cpp
+3
-17
tensor_tools.h
dlib/dnn/tensor_tools.h
+8
-19
No files found.
dlib/dnn/cudnn_dlibapi.cpp
View file @
038c73d8
...
...
@@ -265,10 +265,6 @@ namespace dlib
)
:
filter_handle
(
nullptr
),
conv_handle
(
nullptr
),
out_num_samples
(
0
),
out_k
(
0
),
out_nr
(
0
),
out_nc
(
0
),
forward_algo
(
0
),
forward_workspace_size_in_bytes
(
0
),
forward_workspace
(
nullptr
),
...
...
@@ -279,6 +275,7 @@ namespace dlib
backward_filters_workspace_size_in_bytes
(
0
),
backward_filters_workspace
(
nullptr
)
{
clear
();
}
void
tensor_conv
::
...
...
@@ -313,6 +310,17 @@ namespace dlib
backward_filters_workspace
=
nullptr
;
backward_filters_algo
=
0
;
backward_filters_workspace_size_in_bytes
=
0
;
stride_y
=
0
;
stride_x
=
0
;
data_num_samples
=
0
;
data_k
=
0
;
data_nr
=
0
;
data_nc
=
0
;
filters_num_samples
=
0
;
filters_k
=
0
;
filters_nr
=
0
;
filters_nc
=
0
;
}
void
tensor_conv
::
...
...
@@ -324,11 +332,36 @@ namespace dlib
)
{
DLIB_CASSERT
(
data
.
k
()
==
filters
.
k
(),
""
);
// if the last call to setup gave the same exact settings then don't do
// anything.
if
(
stride_y_
==
stride_y
&&
stride_x_
==
stride_x
&&
data_num_samples
==
data
.
num_samples
()
&&
data_k
==
data
.
k
()
&&
data_nr
==
data
.
nr
()
&&
data_nc
==
data
.
nc
()
&&
filters_num_samples
==
filters
.
num_samples
()
&&
filters_k
==
filters
.
k
()
&&
filters_nr
==
filters
.
nr
()
&&
filters_nc
==
filters
.
nc
())
{
return
;
}
clear
();
try
{
stride_y
=
stride_y_
;
stride_x
=
stride_x_
;
data_num_samples
=
data
.
num_samples
();
data_k
=
data
.
k
();
data_nr
=
data
.
nr
();
data_nc
=
data
.
nc
();
filters_num_samples
=
filters
.
num_samples
();
filters_k
=
filters
.
k
();
filters_nr
=
filters
.
nr
();
filters_nc
=
filters
.
nc
();
CHECK_CUDNN
(
cudnnCreateFilterDescriptor
((
cudnnFilterDescriptor_t
*
)
&
filter_handle
));
CHECK_CUDNN
(
cudnnSetFilter4dDescriptor
((
cudnnFilterDescriptor_t
)
filter_handle
,
...
...
@@ -446,18 +479,22 @@ namespace dlib
void
tensor_conv
::
operator
()
(
resizable_tensor
&
output
,
const
tensor
&
data
,
const
tensor
&
filters
const
tensor
&
filters
,
int
stride_y
,
int
stride_x
)
{
DLIB_ASSERT
(
is_same_object
(
output
,
data
)
==
false
,
""
);
DLIB_ASSERT
(
is_same_object
(
output
,
filters
)
==
false
,
""
);
setup
(
data
,
filters
,
stride_y
,
stride_x
);
output
.
set_size
(
out_num_samples
,
out_k
,
out_nr
,
out_nc
);
DLIB_ASSERT
(
output
.
num_samples
()
==
data
.
num_samples
(),
out_num_samples
<<
" "
<<
data
.
num_samples
());
DLIB_ASSERT
(
output
.
k
()
==
filters
.
num_samples
(),
""
);
DLIB_ASSERT
(
output
.
nr
()
==
1
+
(
data
.
nr
()
-
1
)
/
stride_y
,
""
);
DLIB_ASSERT
(
output
.
nc
()
==
1
+
(
data
.
nc
()
-
1
)
/
stride_x
,
""
);
DLIB_ASSERT
(
output
.
nr
()
==
1
+
(
data
.
nr
()
-
filters
.
nr
()
%
2
)
/
stride_y
,
""
);
DLIB_ASSERT
(
output
.
nc
()
==
1
+
(
data
.
nc
()
-
filters
.
nc
()
%
2
)
/
stride_x
,
output
.
nc
()
<<
" "
<<
1
+
(
data
.
nc
()
-
1
)
/
stride_x
<<
" : "
<<
data
.
nc
()
<<
" "
<<
stride_x
);
const
float
alpha
=
1
;
const
float
beta
=
0
;
...
...
dlib/dnn/cudnn_dlibapi.h
View file @
038c73d8
...
...
@@ -144,31 +144,20 @@ namespace dlib
void
clear
(
);
void
setup
(
const
tensor
&
data
,
const
tensor
&
filters
,
int
stride_y
,
int
stride_x
);
/*!
requires
- filters.k() == data.k()
- stride_y > 0
- stride_x > 0
!*/
~
tensor_conv
(
);
void
operator
()
(
resizable_tensor
&
output
,
const
tensor
&
data
,
const
tensor
&
filters
const
tensor
&
filters
,
int
stride_y
,
int
stride_x
);
/*!
requires
-
The dimensions of data and filters are the same as the ones given
to the last call to setup().
-
stride_y > 0
- stride_x > 0
- is_same_object(output,data) == false
- is_same_object(output,filters) == false
ensures
...
...
@@ -176,8 +165,8 @@ namespace dlib
- filters contains filters.num_samples() filters.
- #output.num_samples() == data.num_samples()
- #output.k() == filters.num_samples()
- #output.nr() == 1+(data.nr()-
1
)/stride_y
- #output.nc() == 1+(data.nc()-
1
)/stride_x
- #output.nr() == 1+(data.nr()-
filters.nr()%2
)/stride_y
- #output.nc() == 1+(data.nc()-
filters.nc()%2
)/stride_x
!*/
void
get_gradient_for_data
(
...
...
@@ -188,9 +177,9 @@ namespace dlib
/*!
requires
- filters has the same dimensions as the filters object give to the
last call to
setup
().
last call to
operator
().
- data_gradient has the same dimensions as the data object give to the
last call to
setup
().
last call to
operator
().
- gradient_input has the same dimensions as the output of operator().
- is_same_object(data_gradient,filters) == false
- is_same_object(data_gradient,gradient_input) == false
...
...
@@ -209,9 +198,9 @@ namespace dlib
/*!
requires
- filters_gradient has the same dimensions as the filters object give
to the last call to
setup
().
to the last call to
operator
().
- data has the same dimensions as the data object give to the last call
to
setup
().
to
operator
().
- gradient_input has the same dimensions as the output of operator().
- is_same_object(filters_gradient,data) == false
- is_same_object(filters_gradient,gradient_input) == false
...
...
@@ -223,10 +212,29 @@ namespace dlib
!*/
private
:
void
*
filter_handle
;
void
*
conv_handle
;
void
setup
(
const
tensor
&
data
,
const
tensor
&
filters
,
int
stride_y
,
int
stride_x
);
/*!
requires
- filters.k() == data.k()
- stride_y > 0
- stride_x > 0
!*/
// These variables record the type of data given to the last call to setup().
int
stride_y
;
int
stride_x
;
long
data_num_samples
,
data_k
,
data_nr
,
data_nc
;
long
filters_num_samples
,
filters_k
,
filters_nr
,
filters_nc
;
void
*
filter_handle
;
void
*
conv_handle
;
// dimensions of the output tensor from operator()
int
out_num_samples
;
...
...
dlib/dnn/tensor_tools.cpp
View file @
038c73d8
...
...
@@ -277,7 +277,8 @@ namespace dlib { namespace tt
}
void
tensor_conv
::
setup
(
operator
()
(
resizable_tensor
&
output
,
const
tensor
&
data
,
const
tensor
&
filters
,
int
stride_y
,
...
...
@@ -285,22 +286,7 @@ namespace dlib { namespace tt
)
{
#ifdef DLIB_USE_CUDA
impl
.
setup
(
data
,
filters
,
stride_y
,
stride_x
);
#else
// TODO
DLIB_CASSERT
(
false
,
""
);
#endif
}
void
tensor_conv
::
operator
()
(
resizable_tensor
&
output
,
const
tensor
&
data
,
const
tensor
&
filters
)
{
#ifdef DLIB_USE_CUDA
impl
(
output
,
data
,
filters
);
impl
(
output
,
data
,
filters
,
stride_y
,
stride_x
);
#else
// TODO
DLIB_CASSERT
(
false
,
""
);
...
...
dlib/dnn/tensor_tools.h
View file @
038c73d8
...
...
@@ -397,7 +397,8 @@ namespace dlib { namespace tt
void
clear
(
);
void
setup
(
void
operator
()
(
resizable_tensor
&
output
,
const
tensor
&
data
,
const
tensor
&
filters
,
int
stride_y
,
...
...
@@ -405,20 +406,8 @@ namespace dlib { namespace tt
);
/*!
requires
- filters.k() == data.k()
- stride_y > 0
- stride_x > 0
!*/
void
operator
()
(
resizable_tensor
&
output
,
const
tensor
&
data
,
const
tensor
&
filters
);
/*!
requires
- The dimensions of data and filters are the same as the ones given
to the last call to setup().
- is_same_object(output,data) == false
- is_same_object(output,filters) == false
ensures
...
...
@@ -426,8 +415,8 @@ namespace dlib { namespace tt
- filters contains filters.num_samples() filters.
- #output.num_samples() == data.num_samples()
- #output.k() == filters.num_samples()
- #output.nr() == 1+(data.nr()-
1
)/stride_y
- #output.nc() == 1+(data.nc()-
1
)/stride_x
- #output.nr() == 1+(data.nr()-
filters.nr()%2
)/stride_y
- #output.nc() == 1+(data.nc()-
filters.nc()%2
)/stride_x
!*/
void
get_gradient_for_data
(
...
...
@@ -438,9 +427,9 @@ namespace dlib { namespace tt
/*!
requires
- filters has the same dimensions as the filters object give to the last
call to
setup
().
call to
operator
().
- data_gradient has the same dimensions as the data object give to the last
call to
setup
().
call to
operator
().
- gradient_input has the same dimensions as the output of operator().
- is_same_object(data_gradient,filters) == false
- is_same_object(data_gradient,gradient_input) == false
...
...
@@ -459,9 +448,9 @@ namespace dlib { namespace tt
/*!
requires
- filters_gradient has the same dimensions as the filters object give to
the last call to
setup
().
the last call to
operator
().
- data has the same dimensions as the data object give to the last call to
setup
().
operator
().
- gradient_input has the same dimensions as the output of operator().
- is_same_object(filters_gradient,data) == false
- is_same_object(filters_gradient,gradient_input) == false
...
...
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