-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathut_ml.py
More file actions
103 lines (86 loc) · 2.45 KB
/
Copy pathut_ml.py
File metadata and controls
103 lines (86 loc) · 2.45 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
"""
TF2 docker unit test package for regression testing.
Make sure all the necessary tf python packages are bueno
"""
__author__ = 'Dave Turvene'
__email__ = 'dturvene at dahetral.com'
__copyright__ = 'Copyright (c) 2019 Dahetral Systems'
__version__ = '0.1'
__date__ = '20191105'
import sys
from os import path
import unittest
from pdb import set_trace as bp
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import seaborn as sns
import tensorflow as tf
def plt_setup():
'''configure matplotlib'''
font = {'family': 'sans-serif',
'weight': 'normal',
'size': 10}
matplotlib.rc('font', **font)
plt.style.use(['ggplot'])
def ut_tensor():
'''
work with tensors (ml-glossary.md#tensor)
https://www.tensorflow.org/guide/tensor
https://www.tensorflow.org/api_docs/python/tf/Tensor
'''
print('create tensors and compute some values')
c = tf.constant([[1.0, 2.0], [3.0, 4.0]])
d = tf.constant([[1.0, 1.0], [0.0, 1.0]])
e = tf.matmul(c, d)
print(e)
# tf.Tensor([[1., 3.], [3., 7.]], shape=(2, 2), dtype=float32)
# bp()
def ut_plt():
'''
test plt display of images
'''
imgfiles=['strawberry.jpg', 'beagle-pup.png']
fig = plt.figure(figsize=(8, 12))
rows=2
columns=1
i=1
for f in imgfiles:
fpath=path.join('/data/TEST_IMAGES/', f)
img = mpimg.imread(fpath)
a=fig.add_subplot(rows,columns,i)
a.set_title(f)
i+=1
plt.imshow(img)
plt.tight_layout(h_pad=10.0, w_pad=10.0)
plt.show()
class Ut(unittest.TestCase):
def setUp(self):
plt_setup()
def tearDown(self):
pass
# @unittest.skip('good')
def test1(self):
'''basic sanity test'''
print('tf functions')
print(tf.reduce_sum(tf.random.normal([1000,1000])))
# @unittest.skip('good')
def test2(self):
ut_tensor()
# @unittest.skip('good')
def test3(self):
'''plot images using matplotlib'''
print('check image API')
ut_plt()
if __name__ == '__main__':
# exec(open('ut_ml.py').read())
print(f'Check package versions')
print(f'python ver={sys.version}')
print(f'numpy ver={np.__version__}')
print(f'seaborn ver={sns.__version__}')
print(f'matplotlib ver={matplotlib.__version__}')
print(f'tf ver={tf.__version__}')
unittest.main(exit=False)