Пример #1
0
 def layers(self):
     from lasagne.layers.base import Layer, MergeLayer
     from lasagne.layers.input import InputLayer
     # create two mocks of the same attributes as an InputLayer instance
     l1 = [
         Mock(InputLayer((None, )),
              output_shape=(None, ),
              get_output_kwargs=[]),
         Mock(InputLayer((None, )),
              output_shape=(None, ),
              get_output_kwargs=[])
     ]
     # create two mocks of the same attributes as a Layer instance
     l2 = [
         Mock(Layer(l1[0]), output_shape=(None, ), get_output_kwargs=[]),
         Mock(Layer(l1[1]), output_shape=(None, ), get_output_kwargs=[])
     ]
     # link them to the InputLayer mocks
     l2[0].input_layer = l1[0]
     l2[1].input_layer = l1[1]
     # create a mock that has the same attributes as a MergeLayer
     l3 = Mock(MergeLayer(l2), get_output_kwargs=['kwarg'])
     # link it to the two layer mocks, to get the following network:
     # l1[0] --> l2[0] --> l3
     # l1[1] --> l2[1] ----^
     l3.input_layers = l2
     return l1, l2, l3
Пример #2
0
 def layers(self):
     from lasagne.layers.base import Layer
     from lasagne.layers.input import InputLayer
     # create two mocks of the same attributes as an InputLayer instance
     l1 = (Mock(InputLayer((None, )),
                output_shapes=((None, ), ),
                shape=((None, ), ),
                input_layers=()),
           Mock(InputLayer((None, )),
                output_shapes=((None, ), ),
                shape=((None, ), ),
                input_layers=()))
     l1[0].get_output_shapes_for.return_value = (Mock(), )
     l1[1].get_output_shapes_for.return_value = (Mock(), )
     # create two mocks of the same attributes as a Layer instance
     l2 = (Mock(Layer(l1[0]),
                output_shapes=((None, ), ),
                input_layers=(l1[0], )),
           Mock(Layer(l1[1]),
                output_shapes=((None, ), ),
                input_layers=(l1[1], )))
     l2[0].get_output_shapes_for.return_value = (Mock(), )
     l2[1].get_output_shapes_for.return_value = (Mock(), )
     # create a mock that has the same attributes as a MergeLayer
     l3 = Mock(Layer(l2, max_inputs=2), input_layers=l2)
     l3.get_output_shapes_for.return_value = (Mock(), )
     # link it to the two layer mocks, to get the following network:
     # l1[0] --> l2[0] --> l3
     # l1[1] --> l2[1] ----^
     return l1, l2, l3
Пример #3
0
 def test_nonpositive_input_dims_raises_value_error(self, layer):
     from lasagne.layers.base import Layer
     neg_input_layer = Mock(output_shape=(None, -1, -1))
     zero_input_layer = Mock(output_shape=(None, 0, 0))
     pos_input_layer = Mock(output_shape=(None, 1, 1))
     with pytest.raises(ValueError):
         Layer(neg_input_layer)
     with pytest.raises(ValueError):
         Layer(zero_input_layer)
     Layer(pos_input_layer)
Пример #4
0
 def layers(self):
     from lasagne.layers.base import Layer
     from lasagne.layers.input import InputLayer
     # create a mock that has the same attributes as an InputLayer instance
     l1 = Mock(InputLayer((None, )), output_shape=(None, ))
     # create a mock that has the same attributes as a Layer instance
     l2 = Mock(Layer(l1), output_shape=(None, ))
     # link it to the InputLayer mock
     l2.input_layer = l1
     # create another mock that has the same attributes as a Layer instance
     l3 = Mock(Layer(l2), output_shape=(None, ))
     # link it to the first mock, to get an "l1 --> l2 --> l3" chain
     l3.input_layer = l2
     return l1, l2, l3
Пример #5
0
 def layers(self):
     from lasagne.layers.base import Layer
     from lasagne.layers.input import InputLayer
     # create a mock that has the same attributes as an InputLayer instance
     l1 = Mock(InputLayer((None, )),
               output_shapes=((None, ), ),
               input_layers=())
     l1.get_output_shapes_for.return_value = (Mock(), )
     # create a mock that has the same attributes as a Layer instance
     l2 = Mock(Layer(l1), output_shapes=((None, ), ), input_layers=(l1, ))
     l2.get_output_shapes_for.return_value = (Mock(), )
     # create another mock that has the same attributes as a Layer instance
     l3 = Mock(Layer(l2), output_shapes=((None, ), ), input_layers=(l2, ))
     l3.get_output_shapes_for.return_value = (Mock(), )
     # link it to the first mock, to get an "l1 --> l2 --> l3" chain
     return l1, l2, l3
Пример #6
0
 def layer_from_shape(self):
     from lasagne.layers.input import InputLayer
     from lasagne.layers.base import Layer
     s1 = (None, 20)
     s2 = Mock(InputLayer((None, )),
               output_shapes=((None, ), ),
               input_layers=())
     return Layer((s1, s2), max_inputs=2)
Пример #7
0
 def layer(self):
     from lasagne.layers.base import Layer
     return Layer(Mock())
Пример #8
0
 def layer_from_shape(self):
     from lasagne.layers.base import Layer
     return Layer((None, 20))
Пример #9
0
 def layer(self):
     from lasagne.layers.base import Layer
     return Layer(Mock(output_shape=(None, )))
Пример #10
0
 def named_layer(self):
     from lasagne.layers.base import Layer
     return Layer(Mock(output_shape=(None, )), name='layer_name')
Пример #11
0
 def layer_from_shape(self):
     from lasagne.layers.input import InputLayer
     from lasagne.layers.base import Layer
     return Layer([(None, 20),
                   Mock(InputLayer((None, )), output_shapes=((None, ), ))],
                  max_inputs=2)
Пример #12
0
 def layer(self):
     from lasagne.layers.base import Layer
     l1 = Layer(Mock(output_shapes=((None, 212), )))
     l2 = Layer(Mock(output_shapes=((314, None), )))
     return Layer((l1, l2), max_inputs=2)
Пример #13
0
 def test_named_layer(self):
     from lasagne.layers.base import Layer
     l = Layer(Mock(), name="foo")
     assert l.name == "foo"