def testGrid2LSTMCellWithRelu(self):
with self.test_session() as sess:
with variable_scope.variable_scope(
'root', initializer=init_ops.constant_initializer(0.5)):
x = array_ops.zeros([1, 3])
m = array_ops.zeros([1, 4])
cell = grid_rnn_cell.Grid2LSTMCell(
2, use_peepholes=True, non_recurrent_fn=nn_ops.relu)
self.assertEqual(cell.state_size, 4)
g, s = cell(x, m)
self.assertEqual(g.get_shape(), (1, 2))
self.assertEqual(s.get_shape(), (1, 4))
sess.run([variables.global_variables_initializer()])
res = sess.run(
[g, s],
{x: np.array([[1., 1., 1.]]),
m: np.array([[0.1, 0.2, 0.3, 0.4]])})
self.assertEqual(res[0].shape, (1, 2))
self.assertEqual(res[1].shape, (1, 4))
self.assertAllClose(res[0], [[2.1831727, 2.1831727]])
self.assertAllClose(res[1], [[0.92270052, 1.02325559, 0.66159075,
0.70475441]])
grid_rnn_test.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录