"tools/git@developer.sourcefind.cn:OpenDAS/dlib.git" did not exist on "312157ab18ea4ea7dc9b23c7209c4dee83f9fcab"
Commit 60dad52c authored by Adrià Arrufat's avatar Adrià Arrufat Committed by Davis E. King
Browse files

add visitor to count net parameters (#1977)

parent 356bba38
...@@ -273,6 +273,35 @@ namespace dlib ...@@ -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_ #endif // DLIB_DNn_UTILITIES_H_
......
...@@ -120,6 +120,20 @@ namespace dlib ...@@ -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_ #endif // DLIB_DNn_UTILITIES_ABSTRACT_H_
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment