Skip to content
Snippets Groups Projects
Commit b0f2f464 authored by Franck Dary's avatar Franck Dary
Browse files

Made sure dynet is only initialized once

parent d3876e0c
Branches
No related tags found
No related merge requests found
...@@ -69,6 +69,7 @@ class MLP ...@@ -69,6 +69,7 @@ class MLP
void loadStruct(const std::string & filename); void loadStruct(const std::string & filename);
void loadParameters(const std::string & filename); void loadParameters(const std::string & filename);
void load(const std::string & filename); void load(const std::string & filename);
void initDynet();
public : public :
......
...@@ -67,10 +67,21 @@ MLP::Activation MLP::str2activation(std::string s) ...@@ -67,10 +67,21 @@ MLP::Activation MLP::str2activation(std::string s)
return LINEAR; return LINEAR;
} }
void MLP::initDynet()
{
static bool init = false;
if(init)
return;
init = true;
dynet::initialize(getDefaultParams());
}
MLP::MLP(std::vector<Layer> layers) MLP::MLP(std::vector<Layer> layers)
: layers(layers), trainer(model, 0.001, 0.9, 0.999, 1e-8) : layers(layers), trainer(model, 0.001, 0.9, 0.999, 1e-8)
{ {
dynet::initialize(getDefaultParams()); initDynet();
trainMode = true; trainMode = true;
dropoutActive = true; dropoutActive = true;
...@@ -441,7 +452,7 @@ void MLP::loadParameters(const std::string & filename) ...@@ -441,7 +452,7 @@ void MLP::loadParameters(const std::string & filename)
MLP::MLP(const std::string & filename) MLP::MLP(const std::string & filename)
: trainer(model, 0.001, 0.9, 0.999, 1e-8) : trainer(model, 0.001, 0.9, 0.999, 1e-8)
{ {
dynet::initialize(getDefaultParams()); initDynet();
trainMode = false; trainMode = false;
dropoutActive = false; dropoutActive = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment