- added StackCreator
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@823 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File: StackCreator.cpp
|
||||
* Author: jens
|
||||
*
|
||||
* Created on 17. Januar 2022, 18:04
|
||||
*/
|
||||
|
||||
#include "StackCreator.hpp"
|
||||
#include "DeepStack.hpp"
|
||||
#include "RnnStack.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
using namespace std;
|
||||
|
||||
StackCreator::StackCreator()
|
||||
{
|
||||
}
|
||||
|
||||
StackCreator::~StackCreator()
|
||||
{
|
||||
}
|
||||
|
||||
AStack* StackCreator::fromJson(Json::Value& project, LayerConstructor *pLayerConstructor)
|
||||
{
|
||||
const string &name = project["stack"]["name"].asString();
|
||||
Json::Value &stack = project["stack"];
|
||||
Json::Value &layers = project["stack"]["layers"];
|
||||
int type = stack["type"].asInt();
|
||||
|
||||
if (type == AStack::StackType::Deep)
|
||||
{
|
||||
return new DeepStack(name, layers, pLayerConstructor);
|
||||
}
|
||||
|
||||
if (type == AStack::StackType::Rnn)
|
||||
{
|
||||
return new RnnStack(name, layers, pLayerConstructor);
|
||||
}
|
||||
|
||||
return new DeepStack(name, layers, pLayerConstructor);
|
||||
|
||||
}
|
||||
|
||||
AStack* StackCreator::fromFile(const std::string &dir, const std::string &name, LayerConstructor *pLayerConstructor)
|
||||
{
|
||||
std::cout << "Importing Project " << name << std::endl;
|
||||
ifstream ifs(dir + "/" + name + string(".prj"));
|
||||
|
||||
Json::Value project;
|
||||
ifs >> project;
|
||||
|
||||
return fromJson(project, pLayerConstructor);
|
||||
}
|
||||
|
||||
bool StackCreator::toFile(AStack* pStack, const std::string& dir, const std::string& name)
|
||||
{
|
||||
std::cout << "Exporting Project " << name << std::endl;
|
||||
ofstream ofs(dir + "/" + name + string(".prj"));
|
||||
|
||||
Json::Value project;
|
||||
project["stack"]["name"] = name;
|
||||
project["stack"]["type_string"] = AStack::stackTypeStrings[pStack->type()];
|
||||
project["stack"]["type"] = pStack->type();
|
||||
|
||||
Json::Value layers(Json::arrayValue);
|
||||
Layer *pLayer = pStack->getLayer(0);
|
||||
while(pLayer)
|
||||
{
|
||||
layers.append(pLayer->toJson());
|
||||
pLayer = pLayer->next;
|
||||
}
|
||||
project["stack"]["layers"] = layers;
|
||||
|
||||
ofs << project;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user