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

Changed the ways model are saved and loaded to accomodate with Dynet code.

parent 758f5072
Branches
No related tags found
No related merge requests found
...@@ -43,7 +43,7 @@ std::vector<float> GeneticAlgorithm::predict(FeatureModel::FeatureDescription & ...@@ -43,7 +43,7 @@ std::vector<float> GeneticAlgorithm::predict(FeatureModel::FeatureDescription &
if (toAsk < 0 || toAsk > (int)generation.size()) if (toAsk < 0 || toAsk > (int)generation.size())
{ {
fprintf(stderr, "ERROR (%s) : trying to save \'%d\' individuals out of a population of \'%lu\'. Aborting.\n", ERRINFO, toAsk, generation.size()); fprintf(stderr, "ERROR (%s) : trying to use \'%d\' individuals out of a population of \'%lu\'. Aborting.\n", ERRINFO, toAsk, generation.size());
exit(1); exit(1);
} }
...@@ -144,7 +144,7 @@ void GeneticAlgorithm::save(const std::string & filename) ...@@ -144,7 +144,7 @@ void GeneticAlgorithm::save(const std::string & filename)
File * file = new File(filename, "w"); File * file = new File(filename, "w");
for (int i = 0; i < toSave; i++) for (int i = 0; i < toSave; i++)
fprintf(file->getDescriptor(), "%u\n", generation[i]->id); fprintf(file->getDescriptor(), "#SAVED_ID# # {1,1} 0 %u\n", generation[i]->id);
delete file; delete file;
for (int i = 0; i < toSave; i++) for (int i = 0; i < toSave; i++)
...@@ -172,7 +172,7 @@ void GeneticAlgorithm::load(const std::string & filename) ...@@ -172,7 +172,7 @@ void GeneticAlgorithm::load(const std::string & filename)
std::vector<int> ids; std::vector<int> ids;
File * file = new File(filename, "r"); File * file = new File(filename, "r");
unsigned int id; unsigned int id;
while (fscanf(file->getDescriptor(), "%u\n", &id) == 1) while (fscanf(file->getDescriptor(), "#SAVED_ID# # {1,1} 0 %u\n", &id) == 1)
ids.emplace_back(id); ids.emplace_back(id);
delete file; delete file;
......
...@@ -277,7 +277,7 @@ void MLPBase::saveStruct(const std::string & filename) ...@@ -277,7 +277,7 @@ void MLPBase::saveStruct(const std::string & filename)
for (auto & layer : layers) for (auto & layer : layers)
{ {
fprintf(fd, "Layer : %d %d %s %.2f\n", layer.input_dim, layer.output_dim, NeuralNetwork::activation2str(layer.activation).c_str(), layer.dropout_rate); fprintf(fd, "#TOPOLOGY# # {1,1} 0 Layer : %d %d %s %.2f\n", layer.input_dim, layer.output_dim, NeuralNetwork::activation2str(layer.activation).c_str(), layer.dropout_rate);
} }
} }
...@@ -305,7 +305,7 @@ void MLPBase::loadStruct(dynet::ParameterCollection & model, const std::string & ...@@ -305,7 +305,7 @@ void MLPBase::loadStruct(dynet::ParameterCollection & model, const std::string &
for (unsigned int i = 0; i < index; i++) for (unsigned int i = 0; i < index; i++)
{ {
while (fscanf(fd, "Layer : %d %d %s %f\n", &input, &output, activation, &dropout) != 4) while (fscanf(fd, "#TOPOLOGY# # {1,1} 0 Layer : %d %d %s %f\n", &input, &output, activation, &dropout) != 4)
if (fscanf(fd, "%10[^\n]\n", activation) != 1) if (fscanf(fd, "%10[^\n]\n", activation) != 1)
{ {
fprintf(stderr, "ERROR (%s) : Unexpected end of file \'%s\'. Aborting.\n", ERRINFO, file.getName().c_str()); fprintf(stderr, "ERROR (%s) : Unexpected end of file \'%s\'. Aborting.\n", ERRINFO, file.getName().c_str());
...@@ -314,10 +314,10 @@ void MLPBase::loadStruct(dynet::ParameterCollection & model, const std::string & ...@@ -314,10 +314,10 @@ void MLPBase::loadStruct(dynet::ParameterCollection & model, const std::string &
do do
{ {
} while (fscanf(fd, "Layer : %d %d %s %f\n", &input, &output, activation, &dropout) == 4); } while (fscanf(fd, "#TOPOLOGY# # {1,1} 0 Layer : %d %d %s %f\n", &input, &output, activation, &dropout) == 4);
} }
while (fscanf(fd, "Layer : %d %d %s %f\n", &input, &output, activation, &dropout) != 4) while (fscanf(fd, "#TOPOLOGY# # {1,1} 0 Layer : %d %d %s %f\n", &input, &output, activation, &dropout) != 4)
if (fscanf(fd, "%10[^\n]\n", activation) != 1) if (fscanf(fd, "%10[^\n]\n", activation) != 1)
{ {
fprintf(stderr, "ERROR (%s) : Unexpected end of file \'%s\'. Aborting.\n", ERRINFO, file.getName().c_str()); fprintf(stderr, "ERROR (%s) : Unexpected end of file \'%s\'. Aborting.\n", ERRINFO, file.getName().c_str());
...@@ -327,7 +327,7 @@ void MLPBase::loadStruct(dynet::ParameterCollection & model, const std::string & ...@@ -327,7 +327,7 @@ void MLPBase::loadStruct(dynet::ParameterCollection & model, const std::string &
do do
{ {
layers.emplace_back(input, output, dropout, NeuralNetwork::str2activation(activation)); layers.emplace_back(input, output, dropout, NeuralNetwork::str2activation(activation));
} while (fscanf(fd, "Layer : %d %d %s %f\n", &input, &output, activation, &dropout) == 4); } while (fscanf(fd, "#TOPOLOGY# # {1,1} 0 Layer : %d %d %s %f\n", &input, &output, activation, &dropout) == 4);
checkLayersCompatibility(); checkLayersCompatibility();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment