-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
test_layers_scale.py
45 lines (30 loc) · 1010 Bytes
/
test_layers_scale.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import unittest
import numpy as np
import tensorflow as tf
import tensorlayer as tl
from tests.utils import CustomTestCase
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
class Layer_Scale_Test(CustomTestCase):
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass
def test_scale(self):
inputs = tl.layers.Input([8, 3])
dense = tl.layers.Dense(n_units=10)(inputs)
scalelayer = tl.layers.Scale(init_scale=0.5)
outputs = scalelayer(dense)
model = tl.models.Model(inputs=inputs, outputs=[dense, outputs])
print(scalelayer)
data = np.random.random(size=[8, 3]).astype(np.float32)
dout, fout = model(data, is_train=True)
for i in range(len(dout)):
for j in range(len(dout[i])):
self.assertEqual(dout[i][j].numpy() * 0.5, fout[i][j].numpy())
if __name__ == '__main__':
unittest.main()