-
Notifications
You must be signed in to change notification settings - Fork 82
/
utils.py
56 lines (42 loc) · 1.3 KB
/
utils.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
54
55
56
# Standard Library
from enum import Enum
# Third Party
import tensorflow.compat.v2 as tf
from packaging import version
# Cached TF Version
TF_VERSION = version.parse(tf.__version__)
def is_greater_than_tf_2_2():
"""
TF 2.0 returns ['accuracy', 'batch', 'size'] as metric collections.
where 'batch' is the batch number and size is the batch size.
But TF 2.2 returns ['accuracy', 'batch'] in eager mode, reducing the total
number of tensor_names emitted by 1.
:return: bool
"""
if TF_VERSION >= version.parse("2.2.0"):
return True
return False
def is_greater_than_tf_2_11():
"""
Session hook is deprecated since 2.12, so we do skipping all session hook related tests
"""
if TF_VERSION >= version.parse("2.12.0") or 'rc' in tf.__version__:
return True
return False
def is_tf_2_6():
if TF_VERSION >= version.parse("2.6.0"):
return True
return False
def is_tf_2_3():
if TF_VERSION == version.parse("2.3.0"):
return True
return False
def is_tf_version_greater_than_2_4_x():
return version.parse("2.4.0") <= TF_VERSION
def is_tf_version_gte(v):
"""TF version greater than or equal to..."""
return TF_VERSION >= version.parse(v)
class ModelType(Enum):
SEQUENTIAL = 0
FUNCTIONAL = 1
SUBCLASSED = 2