-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_toy_model.py
More file actions
52 lines (42 loc) · 1.67 KB
/
test_toy_model.py
File metadata and controls
52 lines (42 loc) · 1.67 KB
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
from __future__ import print_function
import toy_model
from toy_model import ToyModel
from constants import generate_random_hparam
import unittest
import os
import shutil
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
class ToyModelTestCase(unittest.TestCase):
def setUp(self):
if os.path.isdir('savedata'):
shutil.rmtree('savedata', ignore_errors=True)
os.mkdir('savedata')
self.hparam = generate_random_hparam()
self.hparam['h_0'] = 1.0
self.hparam['h_1'] = 0.0
def test_basic(self):
toy_model.main(self.hparam, 0, 'savedata/model_', '', 1)
def test_model_class_init(self):
model = ToyModel(0, self.hparam, 'savedata/model_')
def test_model_class_train(self):
model = ToyModel(0, self.hparam, 'savedata/model_')
acc1 = model.get_accuracy()
epoch1 = model.epoches_trained
model.train(1, 1)
acc2 = model.get_accuracy()
epoch2 = model.epoches_trained
self.assertNotEqual(acc1, acc2)
self.assertEqual(epoch1+1, epoch2)
def test_save_load(self):
step1, acc = toy_model.main(self.hparam, 0, 'savedata/model_', '', 10)
step2, acc = toy_model.main(self.hparam, 0, 'savedata/model_', '', 10)
step3, acc = toy_model.main(self.hparam, 1, 'savedata/model_', '', 10)
self.assertEqual(step1, 10)
self.assertEqual(step2, 20)
self.assertEqual(step3, 10)
if os.path.isdir('savedata'):
shutil.rmtree('savedata', ignore_errors=True)
os.mkdir('savedata')
step4, acc = toy_model.main(self.hparam, 0, 'savedata/model_', '', 10)
self.assertEqual(step4, 10)
unittest.main(verbosity=2)