You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_layers_scale.py 1.1 kB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import unittest
  5. os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
  6. import tensorlayer as tl
  7. from tests.utils import CustomTestCase
  8. class Layer_Scale_Test(CustomTestCase):
  9. @classmethod
  10. def setUpClass(cls):
  11. pass
  12. @classmethod
  13. def tearDownClass(cls):
  14. pass
  15. def test_scale(self):
  16. class model(tl.layers.Module):
  17. def __init__(self):
  18. super(model, self).__init__()
  19. self.dense = tl.layers.Dense(n_units=10)
  20. self.scalelayer = tl.layers.Scale(init_scale=0.5)
  21. def forward(self, inputs):
  22. output1 = self.dense(inputs)
  23. output2 = self.scalelayer(output1)
  24. return output1, output2
  25. input = tl.layers.Input((8, 3), init=tl.initializers.random_normal())
  26. net = model()
  27. net.set_train()
  28. dout, fout = net(input)
  29. for i in range(len(dout)):
  30. for j in range(len(dout[i])):
  31. self.assertEqual(dout[i][j].numpy() * 0.5, fout[i][j].numpy())
  32. if __name__ == '__main__':
  33. unittest.main()

TensorLayer3.0 是一款兼容多种深度学习框架为计算后端的深度学习库。计划兼容TensorFlow, Pytorch, MindSpore, Paddle.