From 309f96b8f5fbd13bbd967cc6adafcfa89d8eace8 Mon Sep 17 00:00:00 2001 From: AntreasAntoniou Date: Fri, 24 Nov 2017 14:00:14 +0000 Subject: [PATCH 1/3] Fix bug that rendered StochasticLayerWithParameters un-updatable --- mlp/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlp/models.py b/mlp/models.py index b2be888..63d034f 100644 --- a/mlp/models.py +++ b/mlp/models.py @@ -131,7 +131,7 @@ class MultipleLayerModel(object): inputs = activations[-i - 2] outputs = activations[-i - 1] grads_wrt_inputs = layer.bprop(inputs, outputs, grads_wrt_outputs) - if isinstance(layer, LayerWithParameters): + if isinstance(layer, LayerWithParameters) or isinstance(layer, StochasticLayerWithParameters): grads_wrt_params += layer.grads_wrt_params( inputs, grads_wrt_outputs)[::-1] grads_wrt_outputs = grads_wrt_inputs From 1d2aabc2b393b4e7e5dee27960a1e356c9db87be Mon Sep 17 00:00:00 2001 From: AntreasAntoniou Date: Fri, 24 Nov 2017 16:25:59 +0000 Subject: [PATCH 2/3] Update models.py --- mlp/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlp/models.py b/mlp/models.py index 63d034f..7f1273e 100644 --- a/mlp/models.py +++ b/mlp/models.py @@ -80,7 +80,7 @@ class MultipleLayerModel(object): """A list of all of the parameters of the model.""" params = [] for layer in self.layers: - if isinstance(layer, LayerWithParameters): + if isinstance(layer, LayerWithParameters) or isinstance(layer, StochasticLayerWithParameters): params += layer.params return params From 65508a7712c0fa878b22c170b7086d063be96de3 Mon Sep 17 00:00:00 2001 From: AntreasAntoniou Date: Sat, 25 Nov 2017 16:43:33 +0000 Subject: [PATCH 3/3] Added generation routine for cross correlation --- scripts/generate_conv_test.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/scripts/generate_conv_test.py b/scripts/generate_conv_test.py index 82d6e79..4fe6120 100644 --- a/scripts/generate_conv_test.py +++ b/scripts/generate_conv_test.py @@ -19,8 +19,6 @@ def generate_inputs(student_id): tests[0, 1, :, :] = float(student_number[7]) / 10 - 5 return tests - - test_inputs = generate_inputs(student_id) test_grads_wrt_outputs = np.arange(-20, 16).reshape((2, 2, 3, 3)) inputs = np.arange(96).reshape((2, 3, 4, 4)) @@ -36,11 +34,26 @@ conv_bprop = activation_layer.bprop( test_inputs, conv_fprop, test_grads_wrt_outputs) conv_grads_wrt_params = activation_layer.grads_wrt_params(test_inputs, test_grads_wrt_outputs) - test_output = "ConvolutionalLayer:\nFprop: {}\nBprop: {}\n" \ "Grads_wrt_params: {}\n".format(conv_fprop, conv_bprop, conv_grads_wrt_params) +cross_correlation_kernels = kernels[:, :, ::-1, ::-1] +activation_layer = ConvolutionalLayer(num_input_channels=3, num_output_channels=2, input_dim_1=4, input_dim_2=4, + kernel_dim_1=2, kernel_dim_2=2) +activation_layer.params = [cross_correlation_kernels, biases] +conv_fprop = activation_layer.fprop(test_inputs) +conv_bprop = activation_layer.bprop( + test_inputs, conv_fprop, test_grads_wrt_outputs) +conv_grads_wrt_params = activation_layer.grads_wrt_params(test_inputs, + test_grads_wrt_outputs) + +test_cross_correlation_output = "Cross_Correlation_ConvolutionalLayer:\nFprop: {}\nBprop: {}\n" \ + "Grads_wrt_params: {}\n".format(conv_fprop, + conv_bprop, + conv_grads_wrt_params) + +test_output = test_output + "\n" + test_cross_correlation_output with open("{}_conv_test_file.txt".format(student_id), "w+") as out_file: out_file.write(test_output) \ No newline at end of file