-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmodel_test.py
53 lines (40 loc) · 1.65 KB
/
model_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
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
import numpy as np
import unittest
from dataset import Dataset
from model import Model
DEBUG_TEST_SAVING = False
class ModeTest(unittest.TestCase):
def test_init(self):
dataset = Dataset(scale=1.0)
model = Model(iteration=1)
model.train(dataset)
images = dataset.get_images(0)
rs, r_tds, rh, error_tds = model.apply_images(images, training=True)
self.assertEqual(rs.shape, (96,))
self.assertEqual(r_tds.shape, (96,))
self.assertEqual(rh.shape, (128,))
self.assertEqual(error_tds.shape, (96,))
patch_rec1 = model.reconstruct(rs, level=1)
self.assertEqual(patch_rec1.shape, (16, 26))
patch_rec2 = model.reconstruct(rh, level=2)
self.assertEqual(patch_rec2.shape, (16, 26))
bar_images_short = dataset.get_bar_images(is_short=True)
rs, r_tds, rh, error_tds = model.apply_images(bar_images_short, training=False)
self.assertEqual(rs.shape, (96,))
self.assertEqual(r_tds.shape, (96,))
self.assertEqual(rh.shape, (128,))
self.assertEqual(error_tds.shape, (96,))
bar_images_long = dataset.get_bar_images(is_short=False)
rs, r_tds, rh, error_tds = model.apply_images(bar_images_long, training=False)
self.assertEqual(rs.shape, (96,))
self.assertEqual(r_tds.shape, (96,))
self.assertEqual(rh.shape, (128,))
self.assertEqual(error_tds.shape, (96,))
def test_save(self):
if DEBUG_TEST_SAVING:
model = Model(iteration=1)
model.save("tmp")
model.load("tmp")
if __name__ == '__main__':
unittest.main()