-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtdv_test.py
46 lines (40 loc) · 1.11 KB
/
tdv_test.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
46
import numpy as np
import pytest
import tensorflow as tf
from tdv import TDV
def test_tdv_energy():
model = TDV(
n_macro=2,
n_scales=2,
n_filters=8,
)
shape = [1, 32, 32, 1]
res = model.energy(tf.zeros(shape))
assert res.shape.as_list() == [1, 1]
@pytest.mark.parametrize('n_macro', [2, 3])
@pytest.mark.parametrize('n_scales', [2, 3])
def test_tdv_call(n_macro, n_scales):
model = TDV(
n_macro=n_macro,
n_scales=n_scales,
n_filters=8,
)
shape = [1, 32, 32, 1]
res = model(tf.zeros(shape))
assert res.shape.as_list() == shape
def test_tdv_change():
model = TDV(
n_macro=2,
n_scales=2,
n_filters=8,
)
x = tf.random.normal((1, 32, 32, 1))
y = tf.random.normal((1, 32, 32, 1))
model(x)
before = [v.numpy() for v in model.trainable_variables]
model.compile(optimizer='sgd', loss='mse')
model.train_on_batch(x, y)
after = [v.numpy() for v in model.trainable_variables]
for b, a in zip(before, after):
assert np.any(np.not_equal(b, a))
assert not np.any(np.isnan(b))