Commit 9cf83756 authored by Sebastian Nickels's avatar Sebastian Nickels

Fixed tests

parent 3d680f2e
Pipeline #170565 passed with stages
in 9 minutes and 27 seconds
......@@ -50,7 +50,7 @@ class CNNCreator_cartpole_master_dqn:
self.networks[0] = Net_0(data_mean=data_mean, data_std=data_std)
self.networks[0].collect_params().initialize(self.weight_initializer, ctx=context)
self.networks[0].hybridize()
self.networks[0](mx.nd.zeros((1, 4,), ctx=context))
self.networks[0](mx.nd.zeros((1,4,), ctx=context))
if not os.path.exists(self._model_dir_):
os.makedirs(self._model_dir_)
......
......@@ -85,10 +85,10 @@ class Net_0(gluon.HybridBlock):
with self.name_scope():
if data_mean:
assert(data_std)
self.input_normalization_state = ZScoreNormalization(data_mean=data_mean['state'],
data_std=data_std['state'])
self.input_normalization_state_ = ZScoreNormalization(data_mean=data_mean['state_'],
data_std=data_std['state_'])
else:
self.input_normalization_state = NoNormalization()
self.input_normalization_state_ = NoNormalization()
self.fc1_ = gluon.nn.Dense(units=128, use_bias=True)
# fc1_, output shape: {[128,1,1]}
......@@ -103,14 +103,14 @@ class Net_0(gluon.HybridBlock):
def hybrid_forward(self, F, state):
outputs = []
state = self.input_normalization_state(state)
fc1_ = self.fc1_(state)
def hybrid_forward(self, F, state_):
state_ = self.input_normalization_state_(state_)
fc1_ = self.fc1_(state_)
tanh1_ = self.tanh1_(fc1_)
fc2_ = self.fc2_(tanh1_)
tanh2_ = self.tanh2_(fc2_)
fc3_ = self.fc3_(tanh2_)
outputs.append(fc3_)
qvalues_ = fc3_
return qvalues_
return outputs[0]
......@@ -29,9 +29,9 @@ public:
if(handle) MXPredFree(handle);
}
void predict(const std::vector<float> &state,
std::vector<float> &qvalues){
MXPredSetInput(handle, "data", state.data(), static_cast<mx_uint>(state.size()));
void predict(const std::vector<float> &in_state_,
std::vector<float> &out_qvalues_){
MXPredSetInput(handle, input_keys[0].c_str(), in_state_.data(), static_cast<mx_uint>(in_state_.size()));
MXPredForward(handle);
......@@ -44,8 +44,8 @@ public:
MXPredGetOutputShape(handle, output_index, &shape, &shape_len);
size = 1;
for (mx_uint i = 0; i < shape_len; ++i) size *= shape[i];
assert(size == qvalues.size());
MXPredGetOutput(handle, 0, &(qvalues[0]), qvalues.size());
assert(size == out_qvalues_.size());
MXPredGetOutput(handle, 0, &(out_qvalues_[0]), out_qvalues_.size());
}
......
......@@ -18,12 +18,12 @@ state=colvec(4);
qvalues=colvec(2);
}
void execute(){
vector<float> CNN_qvalues(2);
vector<float> state_ = CNNTranslator::translate(state);
vector<float> qvalues_(2);
_predictor_0_.predict(CNNTranslator::translate(state),
CNN_qvalues);
_predictor_0_.predict(state_, qvalues_);
qvalues = CNNTranslator::translateToCol(CNN_qvalues, std::vector<size_t> {2});
qvalues = CNNTranslator::translateToCol(qvalues_, std::vector<size_t> {2});
}
......
......@@ -50,7 +50,7 @@ class CNNCreator_mountaincar_master_actor:
self.networks[0] = Net_0(data_mean=data_mean, data_std=data_std)
self.networks[0].collect_params().initialize(self.weight_initializer, ctx=context)
self.networks[0].hybridize()
self.networks[0](mx.nd.zeros((1, 2,), ctx=context))
self.networks[0](mx.nd.zeros((1,2,), ctx=context))
if not os.path.exists(self._model_dir_):
os.makedirs(self._model_dir_)
......
......@@ -85,10 +85,10 @@ class Net_0(gluon.HybridBlock):
with self.name_scope():
if data_mean:
assert(data_std)
self.input_normalization_state = ZScoreNormalization(data_mean=data_mean['state'],
data_std=data_std['state'])
self.input_normalization_state_ = ZScoreNormalization(data_mean=data_mean['state_'],
data_std=data_std['state_'])
else:
self.input_normalization_state = NoNormalization()
self.input_normalization_state_ = NoNormalization()
self.fc1_ = gluon.nn.Dense(units=300, use_bias=True)
# fc1_, output shape: {[300,1,1]}
......@@ -104,15 +104,15 @@ class Net_0(gluon.HybridBlock):
self.tanh3_ = gluon.nn.Activation(activation='tanh')
def hybrid_forward(self, F, state):
outputs = []
state = self.input_normalization_state(state)
fc1_ = self.fc1_(state)
def hybrid_forward(self, F, state_):
state_ = self.input_normalization_state_(state_)
fc1_ = self.fc1_(state_)
relu1_ = self.relu1_(fc1_)
fc2_ = self.fc2_(relu1_)
relu2_ = self.relu2_(fc2_)
fc3_ = self.fc3_(relu2_)
tanh3_ = self.tanh3_(fc3_)
outputs.append(tanh3_)
action_ = tanh3_
return action_
return outputs[0]
......@@ -29,9 +29,9 @@ public:
if(handle) MXPredFree(handle);
}
void predict(const std::vector<float> &state,
std::vector<float> &action){
MXPredSetInput(handle, "data", state.data(), static_cast<mx_uint>(state.size()));
void predict(const std::vector<float> &in_state_,
std::vector<float> &out_action_){
MXPredSetInput(handle, input_keys[0].c_str(), in_state_.data(), static_cast<mx_uint>(in_state_.size()));
MXPredForward(handle);
......@@ -44,8 +44,8 @@ public:
MXPredGetOutputShape(handle, output_index, &shape, &shape_len);
size = 1;
for (mx_uint i = 0; i < shape_len; ++i) size *= shape[i];
assert(size == action.size());
MXPredGetOutput(handle, 0, &(action[0]), action.size());
assert(size == out_action_.size());
MXPredGetOutput(handle, 0, &(out_action_[0]), out_action_.size());
}
......
......@@ -18,12 +18,12 @@ state=colvec(2);
action=colvec(1);
}
void execute(){
vector<float> CNN_action(1);
vector<float> state_ = CNNTranslator::translate(state);
vector<float> action_(1);
_predictor_0_.predict(CNNTranslator::translate(state),
CNN_action);
_predictor_0_.predict(state_, action_);
action = CNNTranslator::translateToCol(CNN_action, std::vector<size_t> {1});
action = CNNTranslator::translateToCol(action_, std::vector<size_t> {1});
}
......
......@@ -50,7 +50,7 @@ class CNNCreator_mountaincar_agent_mountaincarCritic:
self.networks[0] = Net_0(data_mean=data_mean, data_std=data_std)
self.networks[0].collect_params().initialize(self.weight_initializer, ctx=context)
self.networks[0].hybridize()
self.networks[0](mx.nd.zeros((1, 2,), ctx=context), mx.nd.zeros((1, 1,), ctx=context))
self.networks[0](mx.nd.zeros((1,2,), ctx=context), mx.nd.zeros((1,1,), ctx=context))
if not os.path.exists(self._model_dir_):
os.makedirs(self._model_dir_)
......
......@@ -85,10 +85,10 @@ class Net_0(gluon.HybridBlock):
with self.name_scope():
if data_mean:
assert(data_std)
self.input_normalization_state = ZScoreNormalization(data_mean=data_mean['state'],
data_std=data_std['state'])
self.input_normalization_state_ = ZScoreNormalization(data_mean=data_mean['state_'],
data_std=data_std['state_'])
else:
self.input_normalization_state = NoNormalization()
self.input_normalization_state_ = NoNormalization()
self.fc2_1_ = gluon.nn.Dense(units=400, use_bias=True)
# fc2_1_, output shape: {[400,1,1]}
......@@ -99,10 +99,10 @@ class Net_0(gluon.HybridBlock):
if data_mean:
assert(data_std)
self.input_normalization_action = ZScoreNormalization(data_mean=data_mean['action'],
data_std=data_std['action'])
self.input_normalization_action_ = ZScoreNormalization(data_mean=data_mean['action_'],
data_std=data_std['action_'])
else:
self.input_normalization_action = NoNormalization()
self.input_normalization_action_ = NoNormalization()
self.fc2_2_ = gluon.nn.Dense(units=300, use_bias=True)
# fc2_2_, output shape: {[300,1,1]}
......@@ -113,17 +113,17 @@ class Net_0(gluon.HybridBlock):
def hybrid_forward(self, F, state, action):
outputs = []
state = self.input_normalization_state(state)
fc2_1_ = self.fc2_1_(state)
def hybrid_forward(self, F, state_, action_):
state_ = self.input_normalization_state_(state_)
fc2_1_ = self.fc2_1_(state_)
relu2_1_ = self.relu2_1_(fc2_1_)
fc3_1_ = self.fc3_1_(relu2_1_)
action = self.input_normalization_action(action)
fc2_2_ = self.fc2_2_(action)
action_ = self.input_normalization_action_(action_)
fc2_2_ = self.fc2_2_(action_)
add4_ = fc3_1_ + fc2_2_
relu4_ = self.relu4_(add4_)
fc4_ = self.fc4_(relu4_)
outputs.append(fc4_)
qvalues_ = fc4_
return qvalues_
return outputs[0]
......@@ -50,7 +50,7 @@ class CNNCreator_torcs_agent_torcsAgent_dqn:
self.networks[0] = Net_0(data_mean=data_mean, data_std=data_std)
self.networks[0].collect_params().initialize(self.weight_initializer, ctx=context)
self.networks[0].hybridize()
self.networks[0](mx.nd.zeros((1, 5,), ctx=context))
self.networks[0](mx.nd.zeros((1,5,), ctx=context))
if not os.path.exists(self._model_dir_):
os.makedirs(self._model_dir_)
......
......@@ -85,10 +85,10 @@ class Net_0(gluon.HybridBlock):
with self.name_scope():
if data_mean:
assert(data_std)
self.input_normalization_state = ZScoreNormalization(data_mean=data_mean['state'],
data_std=data_std['state'])
self.input_normalization_state_ = ZScoreNormalization(data_mean=data_mean['state_'],
data_std=data_std['state_'])
else:
self.input_normalization_state = NoNormalization()
self.input_normalization_state_ = NoNormalization()
self.fc1_ = gluon.nn.Dense(units=512, use_bias=True)
# fc1_, output shape: {[512,1,1]}
......@@ -103,14 +103,14 @@ class Net_0(gluon.HybridBlock):
def hybrid_forward(self, F, state):
outputs = []
state = self.input_normalization_state(state)
fc1_ = self.fc1_(state)
def hybrid_forward(self, F, state_):
state_ = self.input_normalization_state_(state_)
fc1_ = self.fc1_(state_)
tanh1_ = self.tanh1_(fc1_)
fc2_ = self.fc2_(tanh1_)
tanh2_ = self.tanh2_(fc2_)
fc3_ = self.fc3_(tanh2_)
outputs.append(fc3_)
qvalues_ = fc3_
return qvalues_
return outputs[0]
......@@ -29,9 +29,9 @@ public:
if(handle) MXPredFree(handle);
}
void predict(const std::vector<float> &state,
std::vector<float> &qvalues){
MXPredSetInput(handle, "data", state.data(), static_cast<mx_uint>(state.size()));
void predict(const std::vector<float> &in_state_,
std::vector<float> &out_qvalues_){
MXPredSetInput(handle, input_keys[0].c_str(), in_state_.data(), static_cast<mx_uint>(in_state_.size()));
MXPredForward(handle);
......@@ -44,8 +44,8 @@ public:
MXPredGetOutputShape(handle, output_index, &shape, &shape_len);
size = 1;
for (mx_uint i = 0; i < shape_len; ++i) size *= shape[i];
assert(size == qvalues.size());
MXPredGetOutput(handle, 0, &(qvalues[0]), qvalues.size());
assert(size == out_qvalues_.size());
MXPredGetOutput(handle, 0, &(out_qvalues_[0]), out_qvalues_.size());
}
......
......@@ -19,12 +19,12 @@ state=colvec(5);
qvalues=colvec(discrete_actions);
}
void execute(){
vector<float> CNN_qvalues(30);
vector<float> state_ = CNNTranslator::translate(state);
vector<float> qvalues_(30);
_predictor_0_.predict(CNNTranslator::translate(state),
CNN_qvalues);
_predictor_0_.predict(state_, qvalues_);
qvalues = CNNTranslator::translateToCol(CNN_qvalues, std::vector<size_t> {30});
qvalues = CNNTranslator::translateToCol(qvalues_, std::vector<size_t> {30});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment