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
60dad52c
Commit
60dad52c
authored
Jan 18, 2020
by
Adrià Arrufat
Committed by
Davis E. King
Jan 17, 2020
Browse files
add visitor to count net parameters (#1977)
parent
356bba38
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
dlib/dnn/utilities.h
dlib/dnn/utilities.h
+29
-0
dlib/dnn/utilities_abstract.h
dlib/dnn/utilities_abstract.h
+14
-0
No files found.
dlib/dnn/utilities.h
View file @
60dad52c
...
...
@@ -273,6 +273,35 @@ namespace dlib
// ----------------------------------------------------------------------------------------
namespace
impl
{
class
visitor_count_parameters
{
public:
visitor_count_parameters
(
size_t
&
num_parameters_
)
:
num_parameters
(
num_parameters_
)
{}
void
operator
()(
size_t
,
const
tensor
&
t
)
{
num_parameters
+=
t
.
size
();
}
private:
size_t
&
num_parameters
;
};
}
template
<
typename
net_type
>
inline
size_t
count_parameters
(
const
net_type
&
net
)
{
size_t
num_parameters
=
0
;
impl
::
visitor_count_parameters
temp
(
num_parameters
);
visit_layer_parameters
(
net
,
temp
);
return
num_parameters
;
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_DNn_UTILITIES_H_
...
...
dlib/dnn/utilities_abstract.h
View file @
60dad52c
...
...
@@ -120,6 +120,20 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
net_type
>
inline
size_t
count_parameters
(
const
net_type
&
net
);
/*!
requires
- net_type is an object of type add_layer, add_loss_layer, add_skip_layer, or
add_tag_layer.
ensures
- This function returns the number of parameters of net if it has been properly
initialized and 0 otherwise.
!*/
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_DNn_UTILITIES_ABSTRACT_H_
...
...
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