Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
keras-team
GitHub Repository: keras-team/keras-io
Path: blob/master/scripts/api_audit.py
3273 views
1
from master import MASTER
2
import keras
3
import tensorflow
4
5
MODULE_CLS = type(keras)
6
7
8
def audit_api_docs():
9
all_documented_symbols = set()
10
11
def process_doc_module(module):
12
if "generate" in module:
13
for symbol in module["generate"]:
14
try:
15
symbol = eval(symbol)
16
except NameError:
17
continue
18
all_documented_symbols.add(symbol)
19
if "children" in module:
20
for child in module["children"]:
21
process_doc_module(child)
22
23
for child in MASTER["children"]:
24
process_doc_module(child)
25
26
missing = []
27
28
def walk_module(module_path):
29
module = eval(module_path)
30
elements = dir(module)
31
for name in elements:
32
if name.startswith("_"):
33
continue
34
element_path = module_path + "." + name
35
element = eval(element_path)
36
37
if isinstance(element, MODULE_CLS):
38
walk_module(element_path)
39
else:
40
if element not in all_documented_symbols:
41
missing.append(element_path)
42
43
walk_module("keras")
44
for path in missing:
45
print("Undocumented:", path)
46
47
48
def compare_two_modules(ref_module_path, target_module_path):
49
missing = []
50
different = []
51
ref_module = eval(ref_module_path)
52
target_module = eval(target_module_path)
53
ref_elements = dir(ref_module)
54
target_elements = dir(target_module)
55
for name in ref_elements:
56
if name.startswith("_"):
57
continue
58
ref_element_path = ref_module_path + "." + name
59
if name not in target_elements:
60
print("Missing:", ref_element_path)
61
missing.append(ref_element_path)
62
else:
63
ref_element = eval(ref_element_path)
64
target_element_path = target_module_path + "." + name
65
if isinstance(ref_element, MODULE_CLS):
66
missing_2, different_2 = compare_two_modules(
67
ref_element_path, target_element_path
68
)
69
missing += missing_2
70
different += different_2
71
else:
72
target_element = eval(target_element_path)
73
if target_element is not ref_element:
74
different.append(ref_element_path)
75
print("Different:", ref_element_path)
76
return missing, different
77
78
79
def audit_keras_vs_tf_keras():
80
compare_two_modules("tensorflow.keras", "keras")
81
82
83
def list_all_keras_ops():
84
all_ops = [e for e in dir(keras.ops) if not e.startswith("_")]
85
for o in all_ops:
86
print(o)
87
print("total", len(all_ops))
88
89
np_ops = [e for e in dir(keras.ops.numpy) if not e.startswith("_")]
90
print("numpy", len(np_ops))
91
92
93
if __name__ == "__main__":
94
audit_api_docs()
95
96