leap-model-parser 0.1.243.dev1__py3-none-any.whl → 0.1.243.dev3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- leap_model_parser/model_parser.py +9 -46
- {leap_model_parser-0.1.243.dev1.dist-info → leap_model_parser-0.1.243.dev3.dist-info}/METADATA +1 -1
- {leap_model_parser-0.1.243.dev1.dist-info → leap_model_parser-0.1.243.dev3.dist-info}/RECORD +6 -6
- {leap_model_parser-0.1.243.dev1.dist-info → leap_model_parser-0.1.243.dev3.dist-info}/LICENSE +0 -0
- {leap_model_parser-0.1.243.dev1.dist-info → leap_model_parser-0.1.243.dev3.dist-info}/WHEEL +0 -0
- {leap_model_parser-0.1.243.dev1.dist-info → leap_model_parser-0.1.243.dev3.dist-info}/entry_points.txt +0 -0
|
@@ -34,46 +34,7 @@ if spec is not None:
|
|
|
34
34
|
import onnx # type: ignore
|
|
35
35
|
|
|
36
36
|
onnx_imported = True
|
|
37
|
-
|
|
38
|
-
GIT_LFS_CONTENT = b"version https://git-lfs.github.com/spec/v1"
|
|
39
|
-
|
|
40
|
-
class InvalidModelFile(Exception):
|
|
41
|
-
pass
|
|
42
|
-
|
|
43
|
-
def _is_git_lfs_pointer(path: str) -> bool:
|
|
44
|
-
try:
|
|
45
|
-
with open(path, "rb") as f:
|
|
46
|
-
return f.read(128).startswith(GIT_LFS_CONTENT)
|
|
47
|
-
except OSError:
|
|
48
|
-
return False
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def _text_snippet(path: str, n: int = 200) -> Optional[str]:
|
|
52
|
-
try:
|
|
53
|
-
with open(path, "rb") as f:
|
|
54
|
-
b = f.read(n)
|
|
55
|
-
if b"\x00" in b:
|
|
56
|
-
return None
|
|
57
|
-
s = b.decode("utf-8", errors="replace").strip()
|
|
58
|
-
return s or None
|
|
59
|
-
except OSError:
|
|
60
|
-
return None
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def _raise_model_file_error(path: str, kind: str, original_exc: Exception) -> None:
|
|
64
|
-
suffix = Path(path).suffix
|
|
65
|
-
if _is_git_lfs_pointer(path):
|
|
66
|
-
raise InvalidModelFile(
|
|
67
|
-
f"This {suffix} file is a Git LFS pointer, not the actual model binary. "
|
|
68
|
-
"Run `git lfs pull` (or re-download the artifact) to fetch the real file."
|
|
69
|
-
) from original_exc
|
|
70
|
-
snippet = _text_snippet(path)
|
|
71
|
-
if snippet is not None:
|
|
72
|
-
raise InvalidModelFile(
|
|
73
|
-
f"The provided model is not a real {kind} model binary although its suffix is {suffix}. "
|
|
74
|
-
f"File's content starts with:\n{snippet}."
|
|
75
|
-
) from original_exc
|
|
76
|
-
raise InvalidModelFile(f"Failed to open {kind} model file: {original_exc}") from original_exc
|
|
37
|
+
|
|
77
38
|
|
|
78
39
|
class ModelParser:
|
|
79
40
|
def __init__(self, should_transform_inputs_and_outputs=False,
|
|
@@ -173,11 +134,10 @@ class ModelParser:
|
|
|
173
134
|
def convert_onnx_model(self, file_path: str) -> Tuple[Dict[str, Node], Model, Optional[str]]:
|
|
174
135
|
if not onnx_imported:
|
|
175
136
|
raise OnnxUnsupported()
|
|
176
|
-
|
|
177
137
|
try:
|
|
178
138
|
onnx_model = onnx.load_model(file_path)
|
|
179
|
-
except
|
|
180
|
-
|
|
139
|
+
except:
|
|
140
|
+
raise Exception(f"I caught onnx error: {file_path}")
|
|
181
141
|
input_all = [_input.name for _input in onnx_model.graph.input]
|
|
182
142
|
input_initializer = [
|
|
183
143
|
node.name for node in onnx_model.graph.initializer]
|
|
@@ -195,9 +155,12 @@ class ModelParser:
|
|
|
195
155
|
try:
|
|
196
156
|
return load_model(file_path, custom_objects=custom_objects, compile=False)
|
|
197
157
|
except OSError as e:
|
|
198
|
-
if
|
|
199
|
-
|
|
200
|
-
|
|
158
|
+
if 'signature' in str(e):
|
|
159
|
+
raise Exception('Unable to open model file. The model might be corrupted or not a valid.')
|
|
160
|
+
else:
|
|
161
|
+
raise e
|
|
162
|
+
except:
|
|
163
|
+
raise Exception(f"I caught h5 error: {file_path}")
|
|
201
164
|
|
|
202
165
|
def convert_h5_model(self, file_path: str) -> Tuple[Dict[str, Node], Model, Optional[str]]:
|
|
203
166
|
imported_model = self._load_keras_model_with_custom_layers(file_path)
|
{leap_model_parser-0.1.243.dev1.dist-info → leap_model_parser-0.1.243.dev3.dist-info}/RECORD
RENAMED
|
@@ -7,7 +7,7 @@ leap_model_parser/contract/nodedata.py,sha256=1_ML0nzp3QUZ0_9mGSLhfO4_hqjYMwi0DW
|
|
|
7
7
|
leap_model_parser/contract/ui_components.json,sha256=0lsxwOLElW1E-imCcdh3zKPWgzFuQ_bApG6aHvYfTvo,410591
|
|
8
8
|
leap_model_parser/keras_json_model_import.py,sha256=h9-eb41W67goutRV5c3VkStxvntgb6EmPFdPeshhtsY,17058
|
|
9
9
|
leap_model_parser/leap_graph_editor.py,sha256=s6iVO06xM6LJ8ZjSxkr1srYxsHhGl2KnQjQoc9g4_iE,14329
|
|
10
|
-
leap_model_parser/model_parser.py,sha256=
|
|
10
|
+
leap_model_parser/model_parser.py,sha256=0IdlHBiyoAHrTPVtKarSgyKee_IL8MeyBxvYmf6Qt08,8685
|
|
11
11
|
leap_model_parser/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
leap_model_parser/utils/layerpedia/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
leap_model_parser/utils/layerpedia/layerpedia.py,sha256=1syubfXBTB630TVkgcQ-Ge7Qe9Zbr6EtZRreuqCJnQ8,9292
|
|
@@ -18,8 +18,8 @@ leap_model_parser/utils/uicomponents/generatenodedata.py,sha256=LRaPlO5jJ9pUtkvL
|
|
|
18
18
|
leap_model_parser/utils/uicomponents/tensorflowinscpection.py,sha256=ym613z9iQKPDBpr0RYD35bTABdm1L-Ez86G47BYT7qw,6775
|
|
19
19
|
leap_model_parser/utils/uicomponents/ui_components.json,sha256=0lsxwOLElW1E-imCcdh3zKPWgzFuQ_bApG6aHvYfTvo,410591
|
|
20
20
|
leap_model_parser/utils/uicomponents/ui_components_config.yaml,sha256=cRH8T-c3TAL0nfefRvt9pFsjbTWNEg38NRyHR7RpJsk,19534
|
|
21
|
-
leap_model_parser-0.1.243.
|
|
22
|
-
leap_model_parser-0.1.243.
|
|
23
|
-
leap_model_parser-0.1.243.
|
|
24
|
-
leap_model_parser-0.1.243.
|
|
25
|
-
leap_model_parser-0.1.243.
|
|
21
|
+
leap_model_parser-0.1.243.dev3.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
|
22
|
+
leap_model_parser-0.1.243.dev3.dist-info/METADATA,sha256=HcB70PhiMFYh9qAmtWaQP9znwjAc7wPDwdiQrgaviio,1109
|
|
23
|
+
leap_model_parser-0.1.243.dev3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
24
|
+
leap_model_parser-0.1.243.dev3.dist-info/entry_points.txt,sha256=ZvV6EuQt1uAqwapNg5Lo2qjJM9ZG5g2wfzZoLh_Ztyk,77
|
|
25
|
+
leap_model_parser-0.1.243.dev3.dist-info/RECORD,,
|
{leap_model_parser-0.1.243.dev1.dist-info → leap_model_parser-0.1.243.dev3.dist-info}/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|