Commit 948dfb62 authored by Julian Dierkes's avatar Julian Dierkes

adjusted tests

parent 90023d67
Pipeline #264315 failed with stages
......@@ -16,8 +16,12 @@ import de.monticore.lang.monticar.cnnarch.generator.CNNTrainGenerator;
import de.monticore.lang.monticar.cnnarch.generator.DataPathConfigParser;
import de.monticore.lang.monticar.cnnarch.gluongenerator.CNNTrain2Gluon;
import de.monticore.lang.monticar.cnnarch.gluongenerator.annotations.ArchitectureAdapter;
import de.monticore.lang.monticar.cnnarch.gluongenerator.preprocessing.PreprocessingComponentParameterAdapter;
import de.monticore.lang.monticar.cnnarch.gluongenerator.preprocessing.PreprocessingPortChecker;
import de.monticore.lang.monticar.cnntrain._cocos.CNNTrainCocos;
import de.monticore.lang.monticar.cnntrain._symboltable.ConfigurationSymbol;
import de.monticore.lang.monticar.cnntrain._symboltable.LearningMethod;
import de.monticore.lang.monticar.cnntrain._symboltable.PreprocessingComponentSymbol;
import de.monticore.lang.monticar.emadl._cocos.DataPathCocos;
import de.monticore.lang.monticar.emadl._cocos.EMADLCocos;
import de.monticore.lang.monticar.emadl.tagging.dltag.DataPathSymbol;
......@@ -30,6 +34,7 @@ import de.monticore.lang.monticar.generator.pythonwrapper.GeneratorPythonWrapper
import de.monticore.lang.monticar.generator.cpp.converter.TypeConverter;
import de.monticore.lang.monticar.generator.pythonwrapper.GeneratorPythonWrapperFactory;
import de.monticore.lang.monticar.generator.pythonwrapper.GeneratorPythonWrapperStandaloneApi;
import de.monticore.lang.monticar.generator.pythonwrapper.symbolservices.data.ComponentPortInformation;
import de.monticore.lang.tagging._symboltable.TagSymbol;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.Scope;
......@@ -621,7 +626,6 @@ public class EMADLGenerator {
}
discriminator.get().setComponentName(fullDiscriminatorName);
configuration.setDiscriminatorNetwork(new ArchitectureAdapter(fullDiscriminatorName, discriminator.get()));
//CNNTrainCocos.checkCriticCocos(configuration);
}
// Resolve QNetwork if present
......@@ -643,11 +647,16 @@ public class EMADLGenerator {
}
qnetwork.get().setComponentName(fullQNetworkName);
configuration.setQNetwork(new ArchitectureAdapter(fullQNetworkName, qnetwork.get()));
//CNNTrainCocos.checkCriticCocos(configuration);
}
if (configuration.getLearningMethod() == LearningMethod.GAN)
CNNTrainCocos.checkGANCocos(configuration);
if (configuration.hasPreprocessor()) {
String fullPreprocessorName = configuration.getPreprocessingName().get();
PreprocessingComponentSymbol preprocessingSymbol = configuration.getPreprocessingComponent().get();
List<String> fullNameOfComponent = preprocessingSymbol.getPreprocessingComponentName();
String fullPreprocessorName = String.join(".", fullNameOfComponent);
int indexOfFirstNameCharacter = fullPreprocessorName.lastIndexOf('.') + 1;
fullPreprocessorName = fullPreprocessorName.substring(0, indexOfFirstNameCharacter)
+ fullPreprocessorName.substring(indexOfFirstNameCharacter, indexOfFirstNameCharacter + 1).toUpperCase()
......@@ -671,7 +680,11 @@ public class EMADLGenerator {
}
String targetPath = getGenerationTargetPath();
pythonWrapper.generateAndTryBuilding(processor_instance, targetPath + "/pythonWrapper", targetPath);
ComponentPortInformation componentPortInformation;
componentPortInformation = pythonWrapper.generateAndTryBuilding(processor_instance, targetPath + "/pythonWrapper", targetPath);
PreprocessingComponentParameterAdapter componentParameter = new PreprocessingComponentParameterAdapter(componentPortInformation);
PreprocessingPortChecker.check(componentParameter);
preprocessingSymbol.setPreprocessingComponentParameter(componentParameter);
}
cnnTrainGenerator.setInstanceName(componentInstance.getFullName().replaceAll("\\.", "_"));
......
......@@ -22,7 +22,7 @@ public class RewardFunctionCppGenerator implements RewardFunctionSourceGenerator
.<EMAComponentInstanceSymbol>resolve(rootModel, EMAComponentInstanceSymbol.KIND);
if (!instanceSymbol.isPresent()) {
Log.error("Generation of reward function is not possible: Cannot resolve component instance "
Log.error("Generation of component is not possible: Cannot resolve component instance "
+ rootModel);
}
......@@ -40,7 +40,7 @@ public class RewardFunctionCppGenerator implements RewardFunctionSourceGenerator
try {
generator.generate(componentInstanceSymbol, taggingResolver);
} catch (IOException e) {
Log.error("Generation of reward function is not possible: " + e.getMessage());
Log.error("Generation of rd function is not possible: " + e.getMessage());
}
}
......
......@@ -58,3 +58,17 @@ class CNNCreator_mnist_mnistClassifier_net:
for i, network in self.networks.items():
network.export(self._model_dir_ + self._model_prefix_ + "_" + str(i), epoch=0)
def getInputs(self):
inputs = {}
input_dimensions = (1,28,28,)
input_domains = (int,0.0,255.0,)
inputs["image_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (10,1,1,)
output_domains = (float,0.0,1.0,)
outputs["predictions_"] = output_domains + (output_dimensions,)
return outputs
......@@ -4,7 +4,6 @@ import mxnet as mx
import logging
import sys
import numpy as np
import cv2
import importlib
from mxnet import nd
......@@ -78,6 +77,7 @@ class CNNDataLoader_mnist_mnistClassifier_net:
train_label = {}
data_mean = {}
data_std = {}
train_images = {}
shape_output = self.preprocess_data(instance, inp, 0, train_h5)
train_len = len(train_h5[self._input_names_[0]])
......@@ -140,6 +140,7 @@ class CNNDataLoader_mnist_mnistClassifier_net:
for output_name in self._output_names_:
test_label[output_name][i] = getattr(shape_output, output_name + "_out")
test_images = {}
if 'images' in test_h5:
test_images = test_h5['images']
......@@ -151,103 +152,7 @@ class CNNDataLoader_mnist_mnistClassifier_net:
def preprocess_data(self, instance_wrapper, input_wrapper, index, data_h5):
for input_name in self._input_names_:
data = data_h5[input_name][0]
attr = getattr(input_wrapper, input_name)
if (type(data)) == np.ndarray:
data = np.asfortranarray(data).astype(attr.dtype)
else:
data = type(attr)(data)
setattr(input_wrapper, input_name, data)
for output_name in self._output_names_:
data = data_h5[output_name][0]
attr = getattr(input_wrapper, output_name)
if (type(data)) == np.ndarray:
data = np.asfortranarray(data).astype(attr.dtype)
else:
data = type(attr)(data)
setattr(input_wrapper, output_name, data)
return instance_wrapper.execute(input_wrapper)
def load_preprocessed_data(self, batch_size, preproc_lib):
train_h5, test_h5 = self.load_h5_files()
wrapper = importlib.import_module(preproc_lib)
instance = getattr(wrapper, preproc_lib)()
instance.init()
lib_head, _sep, tail = preproc_lib.rpartition('_')
inp = getattr(wrapper, lib_head + "_input")()
train_data = {}
train_label = {}
data_mean = {}
data_std = {}
shape_output = self.preprocess_data(instance, inp, 0, train_h5)
train_len = len(train_h5[self._input_names_[0]])
for input_name in self._input_names_:
if type(getattr(shape_output, input_name + "_out")) == np.ndarray:
cur_shape = (train_len,) + getattr(shape_output, input_name + "_out").shape
else:
cur_shape = (train_len, 1)
train_data[input_name] = mx.nd.zeros(cur_shape)
for output_name in self._output_names_:
if type(getattr(shape_output, output_name + "_out")) == nd.array:
cur_shape = (train_len,) + getattr(shape_output, output_name + "_out").shape
else:
cur_shape = (train_len, 1)
train_label[output_name] = mx.nd.zeros(cur_shape)
for i in range(train_len):
output = self.preprocess_data(instance, inp, i, train_h5)
for input_name in self._input_names_:
train_data[input_name][i] = getattr(output, input_name + "_out")
for output_name in self._output_names_:
train_label[output_name][i] = getattr(shape_output, output_name + "_out")
for input_name in self._input_names_:
data_mean[input_name + '_'] = nd.array(train_data[input_name][:].mean(axis=0))
data_std[input_name + '_'] = nd.array(train_data[input_name][:].asnumpy().std(axis=0) + 1e-5)
train_iter = mx.io.NDArrayIter(data=train_data,
label=train_label,
batch_size=batch_size)
test_data = {}
test_label = {}
shape_output = self.preprocess_data(instance, inp, 0, test_h5)
test_len = len(test_h5[self._input_names_[0]])
for input_name in self._input_names_:
if type(getattr(shape_output, input_name + "_out")) == np.ndarray:
cur_shape = (test_len,) + getattr(shape_output, input_name + "_out").shape
else:
cur_shape = (test_len, 1)
test_data[input_name] = mx.nd.zeros(cur_shape)
for output_name in self._output_names_:
if type(getattr(shape_output, output_name + "_out")) == nd.array:
cur_shape = (test_len,) + getattr(shape_output, output_name + "_out").shape
else:
cur_shape = (test_len, 1)
test_label[output_name] = mx.nd.zeros(cur_shape)
for i in range(test_len):
output = self.preprocess_data(instance, inp, i, test_h5)
for input_name in self._input_names_:
test_data[input_name][i] = getattr(output, input_name + "_out")
for output_name in self._output_names_:
test_label[output_name][i] = getattr(shape_output, output_name + "_out")
test_iter = mx.io.NDArrayIter(data=test_data,
label=test_label,
batch_size=batch_size)
return train_iter, test_iter, data_mean, data_std
def preprocess_data(self, instance_wrapper, input_wrapper, index, data_h5):
for input_name in self._input_names_:
data = data_h5[input_name][0]
data = data_h5[input_name][index]
attr = getattr(input_wrapper, input_name)
if (type(data)) == np.ndarray:
data = np.asfortranarray(data).astype(attr.dtype)
......@@ -255,7 +160,7 @@ class CNNDataLoader_mnist_mnistClassifier_net:
data = type(attr)(data)
setattr(input_wrapper, input_name, data)
for output_name in self._output_names_:
data = data_h5[output_name][0]
data = data_h5[output_name][index]
attr = getattr(input_wrapper, output_name)
if (type(data)) == np.ndarray:
data = np.asfortranarray(data).astype(attr.dtype)
......
......@@ -148,16 +148,3 @@ class Net_0(gluon.HybridBlock):
return predictions_
def getInputs(self):
inputs = {}
input_dimensions = (1,28,28)
input_domains = (int,0.0,255.0)
inputs["image_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (10,1,1)
output_domains = (float,0.0,1.0)
outputs["predictions_"] = output_domains + (output_dimensions,)
return outputs
......@@ -21,6 +21,7 @@ if __name__ == "__main__":
batch_size=64,
num_epoch=11,
context='gpu',
preprocessing=False,
eval_metric='accuracy',
eval_metric_params={
},
......
......@@ -58,3 +58,17 @@ class CNNCreator_cartpole_master_dqn:
for i, network in self.networks.items():
network.export(self._model_dir_ + self._model_prefix_ + "_" + str(i), epoch=0)
def getInputs(self):
inputs = {}
input_dimensions = (4,)
input_domains = (float,0,1,)
inputs["state_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (2,1,1,)
output_domains = (float,float('-inf'),float('inf'),)
outputs["qvalues_"] = output_domains + (output_dimensions,)
return outputs
......@@ -123,17 +123,3 @@ class Net_0(gluon.HybridBlock):
return qvalues_
def getInputs(self):
inputs = {}
input_dimensions = (4)
input_domains = (float,float('-inf'),float('inf'))
input_domains = (float,0,1)
inputs["state_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (2,1,1)
output_domains = (float,float('-inf'),float('inf'))
outputs["qvalues_"] = output_domains + (output_dimensions,)
return outputs
......@@ -58,3 +58,17 @@ class CNNCreator_mountaincar_master_actor:
for i, network in self.networks.items():
network.export(self._model_dir_ + self._model_prefix_ + "_" + str(i), epoch=0)
def getInputs(self):
inputs = {}
input_dimensions = (2,)
input_domains = (float,0,1,)
inputs["state_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (1,1,1,)
output_domains = (float,-1.0,1.0,)
outputs["action_"] = output_domains + (output_dimensions,)
return outputs
......@@ -125,16 +125,3 @@ class Net_0(gluon.HybridBlock):
return action_
def getInputs(self):
inputs = {}
input_dimensions = (2)
input_domains = (float,0,1)
inputs["state_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (1,1,1)
output_domains = (float,-1.0,1.0)
outputs["action_"] = output_domains + (output_dimensions,)
return outputs
......@@ -58,3 +58,20 @@ class CNNCreator_mountaincar_agent_mountaincarCritic:
for i, network in self.networks.items():
network.export(self._model_dir_ + self._model_prefix_ + "_" + str(i), epoch=0)
def getInputs(self):
inputs = {}
input_dimensions = (2,)
input_domains = (float,0,1,)
inputs["state_"] = input_domains + (input_dimensions,)
input_dimensions = (1,)
input_domains = (float,-1.0,1.0,)
inputs["action_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (1,1,1,)
output_domains = (float,float('-inf'),float('inf'),)
outputs["qvalues_"] = output_domains + (output_dimensions,)
return outputs
......@@ -136,20 +136,3 @@ class Net_0(gluon.HybridBlock):
return qvalues_
def getInputs(self):
inputs = {}
input_dimensions = (2)
input_domains = (float,float('-inf'),float('inf'))
input_domains = (float,0,1)
inputs["state_"] = input_domains + (input_dimensions,)
input_dimensions = (1)
input_domains = (float,-1.0,1.0)
inputs["action_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (1,1,1)
output_domains = (float,float('-inf'),float('inf'))
outputs["qvalues_"] = output_domains + (output_dimensions,)
return outputs
......@@ -58,3 +58,17 @@ class CNNCreator_torcs_agent_torcsAgent_dqn:
for i, network in self.networks.items():
network.export(self._model_dir_ + self._model_prefix_ + "_" + str(i), epoch=0)
def getInputs(self):
inputs = {}
input_dimensions = (5,)
input_domains = (float,0,1,)
inputs["state_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (30,1,1,)
output_domains = (float,float('-inf'),float('inf'),)
outputs["qvalues_"] = output_domains + (output_dimensions,)
return outputs
......@@ -123,16 +123,3 @@ class Net_0(gluon.HybridBlock):
return qvalues_
def getInputs(self):
inputs = {}
input_dimensions = (5)
input_domains = (float,0,1)
inputs["state_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (30,1,1)
output_domains = (float,float('-inf'),float('inf'))
outputs["qvalues_"] = output_domains + (output_dimensions,)
return outputs
......@@ -58,3 +58,17 @@ class CNNCreator_torcs_agent_torcsAgent_actor:
for i, network in self.networks.items():
network.export(self._model_dir_ + self._model_prefix_ + "_" + str(i), epoch=0)
def getInputs(self):
inputs = {}
input_dimensions = (29,)
input_domains = (float,0,1,)
inputs["state_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (3,1,1,)
output_domains = (float,-1.0,1.0,)
outputs["commands_"] = output_domains + (output_dimensions,)
return outputs
......@@ -125,16 +125,3 @@ class Net_0(gluon.HybridBlock):
return commands_
def getInputs(self):
inputs = {}
input_dimensions = (29)
input_domains = (float,0,1)
inputs["state_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (3,1,1)
output_domains = (float,-1.0,1.0)
outputs["commands_"] = output_domains + (output_dimensions,)
return outputs
......@@ -58,3 +58,20 @@ class CNNCreator_torcs_agent_network_torcsCritic:
for i, network in self.networks.items():
network.export(self._model_dir_ + self._model_prefix_ + "_" + str(i), epoch=0)
def getInputs(self):
inputs = {}
input_dimensions = (29,)
input_domains = (float,0,1,)
inputs["state_"] = input_domains + (input_dimensions,)
input_dimensions = (3,)
input_domains = (float,-1.0,1.0,)
inputs["action_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (1,1,1,)
output_domains = (float,float('-inf'),float('inf'),)
outputs["qvalues_"] = output_domains + (output_dimensions,)
return outputs
......@@ -132,19 +132,3 @@ class Net_0(gluon.HybridBlock):
return qvalues_
def getInputs(self):
inputs = {}
input_dimensions = (29)
input_domains = (float,0,1)
inputs["state_"] = input_domains + (input_dimensions,)
input_dimensions = (3)
input_domains = (float,-1.0,1.0)
inputs["action_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (1,1,1)
output_domains = (float,float('-inf'),float('inf'))
outputs["qvalues_"] = output_domains + (output_dimensions,)
return outputs
Epoch[0] Train-accuracy=0.100000
Epoch[0] Time cost=0.049
Epoch[0] Validation-accuracy=0.200000
Epoch[1] Train-accuracy=0.100000
Epoch[1] Time cost=0.051
Epoch[0] Time cost=0.076
Epoch[0] Validation-accuracy=0.500000
Epoch[1] Train-accuracy=0.500000
Epoch[1] Time cost=0.061
Epoch[1] Validation-accuracy=0.300000
Epoch[2] Train-accuracy=0.600000
Epoch[2] Time cost=0.049
Epoch[2] Validation-accuracy=0.200000
Epoch[3] Train-accuracy=0.700000
Epoch[3] Time cost=0.045
Epoch[3] Validation-accuracy=0.100000
Epoch[4] Train-accuracy=0.500000
Epoch[4] Time cost=0.069
Epoch[2] Time cost=0.096
Epoch[2] Validation-accuracy=0.300000
Epoch[3] Train-accuracy=0.500000
Epoch[3] Time cost=0.076
Epoch[3] Validation-accuracy=0.200000
Epoch[4] Train-accuracy=0.600000
Epoch[4] Time cost=0.048
Saved checkpoint to "model/instanceTestCifar.CifarNetwork/model-0005.params"
Epoch[4] Validation-accuracy=0.200000
Epoch[5] Train-accuracy=0.500000
Epoch[5] Time cost=0.055
Epoch[5] Train-accuracy=0.400000
Epoch[5] Time cost=0.070
Epoch[5] Validation-accuracy=0.200000
Epoch[6] Train-accuracy=0.500000
Epoch[6] Time cost=0.068
Epoch[6] Validation-accuracy=0.200000
Epoch[7] Train-accuracy=0.400000
Epoch[7] Time cost=0.076
Epoch[7] Validation-accuracy=0.200000
Epoch[6] Train-accuracy=0.400000
Epoch[6] Time cost=0.062
Epoch[6] Validation-accuracy=0.100000
Epoch[7] Train-accuracy=0.500000
Epoch[7] Time cost=0.046
Epoch[7] Validation-accuracy=0.100000
Epoch[8] Train-accuracy=0.400000
Epoch[8] Time cost=0.051
Epoch[8] Validation-accuracy=0.200000
Epoch[8] Time cost=0.061
Epoch[8] Validation-accuracy=0.100000
Epoch[9] Train-accuracy=0.400000
Epoch[9] Time cost=0.052
Epoch[9] Time cost=0.066
Saved checkpoint to "model/instanceTestCifar.CifarNetwork/model-0010.params"
Epoch[9] Validation-accuracy=0.100000
Saved checkpoint to "model/instanceTestCifar.CifarNetwork/model-0010.params"
......
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