Esempio n. 1
0
 def test_invalid_axis(self):
     if K.backend() != 'cntk':
         return
     from keras_ordered_neurons.cntk_backend import cumsum
     with self.assertRaises(ValueError):
         x = K.placeholder(shape=(1, 3, 4))
         f = K.function([x], [cumsum(x, axis=1)])
Esempio n. 2
0
 def test_return_last_splits(self):
     if K.backend() == 'cntk':
         return
     inputs = layers.Input(shape=(None,))
     embed = layers.Embedding(input_dim=10, output_dim=100)(inputs)
     outputs = ONLSTM(units=50, chunk_size=5, return_splits=True)(embed)
     model = models.Model(inputs=inputs, outputs=outputs)
     model.compile(optimizer='adam', loss='mse')
     model.summary(line_length=120)
     predicted = model.predict(np.random.randint(0, 10, (3, 7)))
     self.assertEqual((3, 50), predicted[0].shape)
     self.assertEqual((3, 2), predicted[1].shape)
Esempio n. 3
0
 def test_valid_last_axis(self):
     if K.backend() != 'cntk':
         return
     from keras_ordered_neurons.cntk_backend import cumsum
     x = K.placeholder(shape=(3, 4))
     f = K.function([x], [cumsum(x, axis=-1)])
     predicted = f([np.array([
         [1.0, 1.0, 1.0, 1.0],
         [1.0, 2.0, 3.0, 4.0],
         [4.0, 3.0, 2.0, 1.0],
     ])])[0]
     self.assertTrue(np.allclose(
         np.array([
             [1.0, 2.0, 3.0, 4.0],
             [1.0, 3.0, 6.0, 10.0],
             [4.0, 7.0, 9.0, 10.0],
         ]),
         predicted
     ), predicted)