- refactored

git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@824 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2022-01-17 20:22:10 +00:00
parent e55f8e2153
commit 51e6eef12e
8 changed files with 34 additions and 62 deletions
-37
View File
@@ -26,10 +26,6 @@ AStack::AStack(StackType type, const std::string &name)
{
}
AStack::AStack(const AStack& orig)
{
}
AStack::~AStack()
{
Layer *pLayer = m_pLayers;
@@ -41,39 +37,6 @@ AStack::~AStack()
}
}
AStack::AStack(StackType type, const std::string &name, Json::Value& layers, LayerConstructor* pLayerConstructor)
: m_type(type)
, m_name(name)
, m_pLayers(nullptr)
{
for (int i=0; i < layers.size(); i++)
{
Json::Value &layer = layers[i];
string layername = layer["name"].asString();
int numVisibleX = layer["numVisibleX"].asInt();
int numVisibleY = layer["numVisibleY"].asInt();
int numHidden = layer["numHidden"].asInt();
int numContext = layer["numContext"].asInt();
Layer *pLayer = nullptr;
if (!pLayerConstructor)
{
pLayer = new Layer(layername, i, numVisibleX, numVisibleY, numHidden, numContext);
}
else
{
pLayer = pLayerConstructor->onConstruct(this, layername, i, numVisibleX, numVisibleY, numHidden, numContext);
}
assert(pLayer != nullptr);
pLayer->fromJson(layer["rbm"]);
addLayer(pLayer);
}
}
AStack::StackType AStack::type()
{
return m_type;
+1 -2
View File
@@ -48,8 +48,7 @@ public:
static const char *stackTypeStrings[NUM_STACKTYPES];
AStack(StackType type, const std::string &name);
AStack(StackType type, const std::string &name, Json::Value &layers, LayerConstructor *pLayerConstructor=nullptr);
AStack(const AStack& orig);
AStack(const AStack& orig) = delete;
virtual ~AStack();
StackType type();
-6
View File
@@ -20,12 +20,6 @@ DeepStack::DeepStack(const std::string &name)
{
}
DeepStack::DeepStack(const std::string &name, Json::Value& layers, LayerConstructor* pLayerConstructor)
: AStack(StackType::Deep, name, layers, pLayerConstructor)
{
}
DeepStack::~DeepStack()
{
}
-1
View File
@@ -25,7 +25,6 @@ class DeepStack : public AStack
{
public:
DeepStack(const std::string &name);
DeepStack(const std::string &name, Json::Value &layers, LayerConstructor *pLayerConstructor=nullptr);
DeepStack(const DeepStack& orig) = delete;
virtual ~DeepStack();
-1
View File
@@ -587,7 +587,6 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
projectNameLabel->setText(m_file.getFileNameWithoutExtension(), NotificationType::dontSendNotification);
AStack *pStack = StackCreator::fromFile(m_file.getParentDirectory().getFullPathName().toStdString(), std::string(projectNameLabel->getText().getCharPointer()), this);
m_stack = reinterpret_cast<DeepStack*>(pStack);
// m_stack->load(this);
m_stack->loadWeights(m_dir);
m_rbmSelect->clear(dontSendNotification);
-6
View File
@@ -18,12 +18,6 @@ RnnStack::RnnStack(const std::string &name)
{
}
RnnStack::RnnStack(const std::string &name, Json::Value& layers, LayerConstructor* pLayerConstructor)
: AStack(StackType::Rnn, name, layers, pLayerConstructor)
{
}
RnnStack::~RnnStack()
{
}
-1
View File
@@ -20,7 +20,6 @@ class RnnStack : public AStack
{
public:
RnnStack(const std::string &name);
RnnStack(const std::string &name, Json::Value &layers, LayerConstructor *pLayerConstructor=nullptr);
RnnStack(const RnnStack& orig) = delete;
virtual ~RnnStack();
+33 -8
View File
@@ -35,18 +35,43 @@ AStack* StackCreator::fromJson(Json::Value& project, LayerConstructor *pLayerCon
Json::Value &layers = project["stack"]["layers"];
int type = stack["type"].asInt();
if (type == AStack::StackType::Deep)
{
return new DeepStack(name, layers, pLayerConstructor);
}
AStack *pStack = nullptr;
if (type == AStack::StackType::Rnn)
{
return new RnnStack(name, layers, pLayerConstructor);
pStack = new RnnStack(name);
}
else
{
pStack = new DeepStack(name);
}
return new DeepStack(name, layers, pLayerConstructor);
for (int i=0; i < layers.size(); i++)
{
Json::Value &layer = layers[i];
string layername = layer["name"].asString();
int numVisibleX = layer["numVisibleX"].asInt();
int numVisibleY = layer["numVisibleY"].asInt();
int numHidden = layer["numHidden"].asInt();
int numContext = layer["numContext"].asInt();
Layer *pLayer = nullptr;
if (!pLayerConstructor)
{
pLayer = new Layer(layername, i, numVisibleX, numVisibleY, numHidden, numContext);
}
else
{
pLayer = pLayerConstructor->onConstruct(pStack, layername, i, numVisibleX, numVisibleY, numHidden, numContext);
}
assert(pLayer != nullptr);
pLayer->fromJson(layer["rbm"]);
pStack->addLayer(pLayer);
}
return pStack;
}
AStack* StackCreator::fromFile(const std::string &dir, const std::string &name, LayerConstructor *pLayerConstructor)