- added simple command parsing
git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@845 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+41
-17
@@ -34,35 +34,59 @@ class RbmListener : public Rbm::IListener
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#define CREATE_TRAINING 0
|
||||
#define DO_TRAINING 1
|
||||
#define DO_FORWARD 1
|
||||
|
||||
int main()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#if CREATE_TRAINING
|
||||
enum Command {Nop, Create, Reset, Train, Forward};
|
||||
Command command = Nop;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
char cmd_token = *argv[1];
|
||||
if (cmd_token == 'c')
|
||||
{
|
||||
command = Command::Create;
|
||||
}
|
||||
else if (cmd_token == 'r')
|
||||
{
|
||||
command = Command::Reset;
|
||||
}
|
||||
else if (cmd_token == 't')
|
||||
{
|
||||
command = Command::Train;
|
||||
}
|
||||
else if (cmd_token == 'f')
|
||||
{
|
||||
command = Command::Forward;
|
||||
}
|
||||
}
|
||||
|
||||
if (command == Command::Create)
|
||||
{
|
||||
arma::mat batch = RnnTextHelper::createTraining("moby_ch1.txt", RnnTextHelper::SEQ_LENGTH);
|
||||
batch.save("poet2.training.dat", arma::arma_ascii);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Load project
|
||||
RnnStack *stack = reinterpret_cast<RnnStack*>(StackCreator::fromFile(".", "poet_2v_5s"));
|
||||
|
||||
// Load weights
|
||||
bool weight_loaded = stack->loadWeights(".");
|
||||
stack->loadWeights(".");
|
||||
|
||||
// Load training
|
||||
stack->loadTrainingBatch(".");
|
||||
arma::mat t_vc = stack->trainingBatch();
|
||||
|
||||
bool do_training = not weight_loaded;
|
||||
#if DO_TRAINING
|
||||
do_training = true;
|
||||
#endif
|
||||
if (command == Command::Reset)
|
||||
{
|
||||
for (int i=0; i < stack->numLayers(); i++)
|
||||
{
|
||||
stack->getLayer(i)->weightsInit(0.01);
|
||||
}
|
||||
stack->saveWeights(".");
|
||||
}
|
||||
|
||||
if (do_training)
|
||||
if (command == Command::Train)
|
||||
{
|
||||
RbmListener listener;
|
||||
|
||||
@@ -90,7 +114,8 @@ int main()
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
#if DO_FORWARD
|
||||
if (command == Command::Forward)
|
||||
{
|
||||
arma::mat state;
|
||||
arma::mat curr;
|
||||
arma::mat next;
|
||||
@@ -118,8 +143,7 @@ int main()
|
||||
}
|
||||
cout << "Curr: " << curr_str << std::endl;
|
||||
cout << "Next: " << next_str << std::endl;
|
||||
#endif
|
||||
|
||||
}
|
||||
printf("\nEnd of program\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user