Skip to content
This repository was archived by the owner on Apr 23, 2026. It is now read-only.

Commit 9fafeaa

Browse files
committed
Fix typing issues
1 parent d87dfac commit 9fafeaa

4 files changed

Lines changed: 17 additions & 14 deletions

File tree

MLStructFP_benchmarks/ml/model/core/_model.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ def _reset() -> None:
10761076
# Collect memory
10771077
time.sleep(5)
10781078
gc.collect()
1079+
return None
10791080

10801081
def _extend_train_metadata(self) -> None:
10811082
"""
@@ -1731,6 +1732,7 @@ def compile(
17311732
raise RuntimeError(_ERROR_MODEL_TRAINED)
17321733

17331734
# Use dict
1735+
init_metrics: Union[dict, list]
17341736
if not as_list:
17351737
reqk: str = ', '.join(self._output_layers)
17361738
total_out: int = len(self._output_layers)
@@ -1790,7 +1792,6 @@ def compile(
17901792
# Check metrics
17911793
if isinstance(metrics, str):
17921794
metrics = [metrics]
1793-
init_metrics: dict
17941795
if metrics is not None:
17951796
init_metrics = metrics.copy()
17961797
else:
@@ -2197,10 +2198,10 @@ def load_session(
21972198
current_arch = self._model.to_json(indent=2)
21982199

21992200
# Calculate the difference between architectures files
2200-
arch_file = open(file_arch, 'r')
2201-
modelj: str = ''
2202-
for i in arch_file:
2203-
modelj += i
2201+
with open(file_arch, 'r') as arch_file:
2202+
modelj: str = ''
2203+
for i in arch_file:
2204+
modelj += i
22042205
arch_diff: Iterator[str] = difflib.unified_diff(
22052206
_normalize_arch_json(modelj).split('\n'),
22062207
_normalize_arch_json(current_arch).split('\n')

MLStructFP_benchmarks/ml/utils/_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def iou_metric(y_true: 'np.ndarray', y_pred: 'np.ndarray', threshold: Union[floa
5050
y_pred = y_pred.reshape((1, *y_pred.shape))
5151
for i in range(0, y_true.shape[0]):
5252
intersect = np.sum(y_true[i, :, :] * y_pred[i, :, :])
53-
union = np.sum(y_true[i, :, :]) + np.sum(y_pred[i, :, :]) - intersect + 1e-7
53+
union = np.sum(y_true[i, :, :]) + np.sum(y_pred[i, :, :]) - intersect + 1e-7 # type: ignore
5454
results.append(np.mean((intersect / union)).astype(np.float32))
5555
return float(np.mean(results))
5656

MLStructFP_benchmarks/ml/utils/keras_engine/_training_arrays.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ def fit_loop(
116116
count_mode = 'steps'
117117
else:
118118
count_mode = 'samples'
119-
_callbacks.append(
120-
cbks.ProgbarLogger(count_mode, stateful_metrics=model_stateful_metrics_names))
119+
_callbacks.append(cbks.ProgbarLogger( # type: ignore
120+
count_mode, stateful_metrics=model_stateful_metrics_names)
121+
)
121122
_callbacks += (callbacks or []) + [model.history]
122123
callbacks = cbks.CallbackList(_callbacks)
123124
out_labels = out_labels or []

MLStructFP_benchmarks/ml/utils/plot/_keras.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _model_to_dot_v2(
8787
expand_nested=False,
8888
dpi=DEFAULT_PLOT_DPI,
8989
subgraph=False
90-
) -> 'pydot.Cluster':
90+
) -> 'pydot.Cluster': # type: ignore
9191
"""
9292
Convert a Keras model to dot format.
9393
@@ -152,7 +152,7 @@ def _model_to_dot_v2(
152152
sub_w_nodes = submodel_wrapper.get_nodes()
153153
sub_w_first_node[layer.layer.name] = sub_w_nodes[0]
154154
sub_w_last_node[layer.layer.name] = sub_w_nodes[-1]
155-
dot.add_subgraph(submodel_wrapper)
155+
dot.add_subgraph(submodel_wrapper) # type: ignore
156156
else:
157157
layer_name = f'{layer_name}({layer.layer.name})'
158158
child_class_name = layer.layer.__class__.__name__
@@ -167,7 +167,7 @@ def _model_to_dot_v2(
167167
sub_n_nodes = submodel_not_wrapper.get_nodes()
168168
sub_n_first_node[layer.name] = sub_n_nodes[0]
169169
sub_n_last_node[layer.name] = sub_n_nodes[-1]
170-
dot.add_subgraph(submodel_not_wrapper)
170+
dot.add_subgraph(submodel_not_wrapper) # type: ignore
171171

172172
# Create node's label.
173173
if show_layer_names:
@@ -260,7 +260,7 @@ def _model_to_dot_v1(
260260
expand_nested=False,
261261
dpi=DEFAULT_PLOT_DPI,
262262
subgraph=False
263-
) -> 'pydot.Cluster':
263+
) -> 'pydot.Cluster': # type: ignore
264264
"""
265265
Convert a Keras model to dot format.
266266
@@ -323,7 +323,7 @@ def _model_to_dot_v1(
323323
sub_w_nodes[layer.layer.name] = submodel_wrapper.get_nodes()
324324
sub_w_first_node[layer.layer.name] = 0
325325
sub_w_last_node[layer.layer.name] = -1
326-
dot.add_subgraph(submodel_wrapper)
326+
dot.add_subgraph(submodel_wrapper) # type: ignore
327327
else:
328328
layer_name = f'{layer_name}({layer.layer.name})'
329329
child_class_name = layer.layer.__class__.__name__
@@ -338,7 +338,7 @@ def _model_to_dot_v1(
338338
sub_n_nodes[layer.name] = submodel_not_wrapper.get_nodes()
339339
sub_n_first_node[layer.name] = 0
340340
sub_n_last_node[layer.name] = -1
341-
dot.add_subgraph(submodel_not_wrapper)
341+
dot.add_subgraph(submodel_not_wrapper) # type: ignore
342342

343343
# Create node's label
344344
if show_layer_names:
@@ -486,3 +486,4 @@ def plot_model_architecture(
486486
return dimg
487487
except ImportError:
488488
pass
489+
return None

0 commit comments

Comments
 (0)