Commit 9f4c888c authored by Julian Dierkes's avatar Julian Dierkes

fixed old tests

parent d1f9eed1
......@@ -55,7 +55,7 @@ class ${tc.fileNameWithoutEnding}:
self.networks[${networkInstruction?index}] = Net_${networkInstruction?index}(data_mean=data_mean, data_std=data_std)
self.networks[${networkInstruction?index}].collect_params().initialize(self.weight_initializer, ctx=context)
self.networks[${networkInstruction?index}].hybridize()
self.networks[${networkInstruction?index}](<#list tc.getStreamInputDimensions(networkInstruction.body) as dimensions>mx.nd.zeros((1, ${tc.join(dimensions, ",")},), ctx=context)<#sep>, </#list>)
self.networks[${networkInstruction?index}](<#list tc.getStreamInputDimensions(networkInstruction.body) as dimensions>mx.nd.zeros((1, ${tc.join(tc.cutDimensions(dimensions), ",")},), ctx=context)<#sep>, </#list>)
</#list>
if not os.path.exists(self._model_dir_):
......@@ -70,8 +70,8 @@ class ${tc.fileNameWithoutEnding}:
<#assign dimensions = (tc.getStreamInputs(stream, false))>
<#assign domains = (tc.getStreamInputDomains(stream))>
<#list tc.getStreamInputVariableNames(stream, false) as name>
input_dimensions = (${tc.join(dimensions[name], ",")})
input_domains = (${tc.join(domains[name], ",")})
input_dimensions = (${tc.join(dimensions[name], ",")},)
input_domains = (${tc.join(domains[name], ",")},)
inputs["${name}"] = input_domains + (input_dimensions,)
</#list>
</#list>
......@@ -83,8 +83,8 @@ class ${tc.fileNameWithoutEnding}:
<#assign dimensions = (tc.getStreamOutputs(stream, false))>
<#assign domains = (tc.getStreamOutputDomains(stream))>
<#list tc.getStreamOutputVariableNames(stream, false) as name>
output_dimensions = (${tc.join(dimensions[name], ",")})
output_domains = (${tc.join(domains[name], ",")})
output_dimensions = (${tc.join(dimensions[name], ",")},)
output_domains = (${tc.join(domains[name], ",")},)
outputs["${name}"] = output_domains + (output_dimensions,)
</#list>
</#list>
......
......@@ -68,40 +68,6 @@ def visualize(img_arr):
img_np = img_np.reshape((s[0], s[1]))
pyplot.imshow(img_np, cmap = 'Greys')
# ugly hardcoded
def getDataIter(ctx, batch_size=64, Z=100):
img_number = 500
mnist_train = mx.gluon.data.vision.datasets.MNIST(train=True)
mnist_test = mx.gluon.data.vision.datasets.MNIST(train=False)
X = np.zeros((img_number, 28, 28))
for i in range(img_number/2):
X[i] = mnist_train[i][0].asnumpy()[:,:,0]
for i in range(img_number/2):
X[img_number/2+i] = mnist_test[i][0].asnumpy()[:,:,0]
#X = np.zeros((img_number, 28, 28))
#for i, (data, label) in enumerate(mnist_train):
# X[i] = mnist_train[i][0].asnumpy()[:,:,0]
#for i, (data, label) in enumerate(mnist_test):
# X[len(mnist_train)+i] = data.asnumpy()[:,:,0]
np.random.seed(1)
p = np.random.permutation(X.shape[0])
X = X[p]
import cv2
#X = np.asarray([cv2.resize(x, (64,64)) for x in X])
X = X.astype(np.float32, copy=False)/(255.0/2) - 1.0
X = X.reshape((img_number, 1, 28, 28))
X = np.tile(X, (1, 1, 1, 1))
data = mx.nd.array(X)
image_iter = mx.io.NDArrayIter(data, batch_size=batch_size)
return image_iter
# ugly hardcoded end
class ${tc.fileNameWithoutEnding}:
def __init__(self, data_loader, net_constructor_gen, net_constructor_dis, net_constructor_qnet = None):
......@@ -176,7 +142,6 @@ class ${tc.fileNameWithoutEnding}:
else:
self._data_loader._input_names_ = cGAN_input_names + [gen_output_name]
# train_iter = getDataIter(mx_context, batch_size, 100)
if preprocessing:
train_iter, test_iter, data_mean, data_std, _, _ = self._data_loader.load_preprocessed_data(batch_size, preproc_lib)
else:
......@@ -265,7 +230,7 @@ class ${tc.fileNameWithoutEnding}:
if self.use_qnet:
qnet_trainer = mx.gluon.Trainer(q_net.collect_params(), discriminator_optimizer, discriminator_optimizer_params)
dis_loss = mx.gluon.loss.SigmoidBinaryCrossEntropyLoss()
dis_loss = mx.gluon.loss.SigmoidBinaryCrossEntropyLoss(from_sigmoid=True)
if not generator_loss == None:
if generator_loss == "l2":
......
......@@ -40,8 +40,8 @@ if __name__ == "__main__":
<#if (config.context)??>
context='${config.context}',
</#if>
<#if (config.preprocessingName)??>
preprocessing=${config.preprocessingName???string("True","False")},
<#if (config.preprocessor)??>
preprocessing=${config.preprocessor?string("True","False")},
</#if>
<#if (config.normalize)??>
normalize=${config.normalize?string("True","False")},
......@@ -52,9 +52,6 @@ if __name__ == "__main__":
<#if (config.clipGlobalGradNorm)??>
clip_global_grad_norm=${config.clipGlobalGradNorm},
</#if>
<#if (config.preprocessingName)??>
preprocessing=${config.preprocessingName???string("True","False")},
</#if>
<#if (config.useTeacherForcing)??>
use_teacher_forcing='${config.useTeacherForcing?string("True","False")}',
</#if>
......
......@@ -61,8 +61,8 @@ if __name__ == "__main__":
<#if (config.normalize)??>
normalize=${config.normalize?string("True","False")},
</#if>
<#if (config.preprocessingName)??>
preprocessing=${config.preprocessingName???string("True","False")},
<#if (config.preprocessor)??>
preprocessing=${config.preprocessor?string("True","False")},
</#if>
<#if (config.evalMetric)??>
eval_metric='${config.evalMetric}',
......@@ -122,6 +122,7 @@ if __name__ == "__main__":
'spread_value': ${config.noiseDistribution.spread_value}
</#if>
},
</#if>
<#if (config.KValue)??>
k_value=${config.KValue},
</#if>
......@@ -146,6 +147,5 @@ if __name__ == "__main__":
<#if (config.printImages)??>
print_images=${config.printImages?string("True","False")},
</#if>)
</#if>
......@@ -58,3 +58,17 @@ class CNNCreator_Alexnet:
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 = (3,224,224,)
input_domains = (int,0.0,255.0,)
inputs["data_"] = 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
......@@ -58,3 +58,17 @@ class CNNCreator_CifarClassifierNetwork:
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 = (3,32,32,)
input_domains = (int,0.0,255.0,)
inputs["data_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (10,1,1,)
output_domains = (float,0.0,1.0,)
outputs["softmax_"] = output_domains + (output_dimensions,)
return outputs
......@@ -58,3 +58,17 @@ class CNNCreator_VGG16:
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 = (3,224,224,)
input_domains = (int,0.0,255.0,)
inputs["data_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (1000,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_Alexnet:
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_Alexnet:
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,7 +152,7 @@ class CNNDataLoader_Alexnet:
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)
......@@ -159,7 +160,7 @@ class CNNDataLoader_Alexnet:
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)
......
......@@ -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_CifarClassifierNetwork:
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_CifarClassifierNetwork:
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,7 +152,7 @@ class CNNDataLoader_CifarClassifierNetwork:
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)
......@@ -159,7 +160,7 @@ class CNNDataLoader_CifarClassifierNetwork:
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)
......
......@@ -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_VGG16:
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_VGG16:
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,7 +152,7 @@ class CNNDataLoader_VGG16:
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)
......@@ -159,7 +160,7 @@ class CNNDataLoader_VGG16:
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)
......
......@@ -283,16 +283,3 @@ class Net_0(gluon.HybridBlock):
return predictions_
def getInputs(self):
inputs = {}
input_dimensions = (3,224,224)
input_domains = (int,0.0,255.0)
inputs["data_"] = 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
......@@ -476,16 +476,3 @@ class Net_0(gluon.HybridBlock):
return softmax_
def getInputs(self):
inputs = {}
input_dimensions = (3,32,32)
input_domains = (int,0.0,255.0)
inputs["data_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (10,1,1)
output_domains = (float,0.0,1.0)
outputs["softmax_"] = output_domains + (output_dimensions,)
return outputs
......@@ -301,16 +301,3 @@ class Net_0(gluon.HybridBlock):
return predictions_
def getInputs(self):
inputs = {}
input_dimensions = (3,224,224)
input_domains = (int,0.0,255.0)
inputs["data_"] = input_domains + (input_dimensions,)
return inputs
def getOutputs(self):
outputs = {}
output_dimensions = (1000,1,1)
output_domains = (float,0.0,1.0)
outputs["predictions_"] = output_domains + (output_dimensions,)
return outputs
......@@ -18,4 +18,5 @@ if __name__ == "__main__":
)
emptyConfig_trainer.train(
preprocessing=False,
)
......@@ -22,6 +22,7 @@ if __name__ == "__main__":
num_epoch=5,
load_checkpoint=True,
context='gpu',
preprocessing=False,
normalize=True,
eval_metric='mse',
eval_metric_params={
......
......@@ -20,6 +20,7 @@ if __name__ == "__main__":
simpleConfig_trainer.train(
batch_size=100,
num_epoch=50,
preprocessing=False,
loss='cross_entropy',
optimizer='adam',
optimizer_params={
......
......@@ -58,3 +58,20 @@ class CNNCreator_CriticNetwork:
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 = (8,)
input_domains = (float,float('-inf'),float('inf'),)
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
......@@ -140,19 +140,3 @@ class Net_0(gluon.HybridBlock):
return qvalues_
def getInputs(self):
inputs = {}
input_dimensions = (8)
input_domains = (float,float('-inf'),float('inf'))
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
......@@ -58,3 +58,20 @@ class CNNCreator_RosCriticNetwork:
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 = (8,)
input_domains = (float,float('-inf'),float('inf'),)
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
......@@ -140,19 +140,3 @@ class Net_0(gluon.HybridBlock):
return qvalues_
def getInputs(self):
inputs = {}
input_dimensions = (8)
input_domains = (float,float('-inf'),float('inf'))
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
......@@ -58,3 +58,20 @@ class CNNCreator_CriticNetwork:
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 = (8,)
input_domains = (float,float('-inf'),float('inf'),)
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
......@@ -140,19 +140,3 @@ class Net_0(gluon.HybridBlock):
return qvalues_
def getInputs(self):
inputs = {}
input_dimensions = (8)
input_domains = (float,float('-inf'),float('inf'))
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
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