This commit is contained in:
Davis King 2017-05-07 17:32:42 -04:00
commit 0f6ddb6471
3 changed files with 37 additions and 5 deletions

View File

@ -1595,14 +1595,17 @@ namespace dlib
friend void to_xml(const affine_& item, std::ostream& out)
{
out << "<affine";
if (item.mode==CONV_MODE)
out << " mode='conv'";
out << "<affine_con>\n";
else
out << " mode='fc'";
out << ">\n";
out << "<affine_fc>\n";
out << mat(item.params);
out << "</affine>\n";
if (item.mode==CONV_MODE)
out << "</affine_con>\n";
else
out << "</affine_fc>\n";
}
private:

View File

@ -6,6 +6,7 @@
#include "core.h"
#include "utilities_abstract.h"
#include "../geometry.h"
#include <fstream>
namespace dlib
{
@ -103,9 +104,22 @@ namespace dlib
std::ostream& out
)
{
auto old_precision = out.precision(9);
out << "<net>\n";
visit_layers(net, impl::visitor_net_to_xml(out));
out << "</net>\n";
// restore the original stream precision.
out.precision(old_precision);
}
template <typename net_type>
void net_to_xml (
const net_type& net,
const std::string& filename
)
{
std::ofstream fout(filename);
net_to_xml(net, fout);
}
// ----------------------------------------------------------------------------------------

View File

@ -56,6 +56,21 @@ namespace dlib
stream.
!*/
template <typename net_type>
void net_to_xml (
const net_type& net,
const std::string& filename
);
/*!
requires
- net_type is an object of type add_layer, add_loss_layer, add_skip_layer, or
add_tag_layer.
- All layers in the net must provide to_xml() functions.
ensures
- This function is just like the above net_to_xml(), except it writes to a file
rather than an ostream.
!*/
// ----------------------------------------------------------------------------------------
template <typename net_type>