Fix bug in remove_imports ()

* Fix bug in remove_imports

IndexError: list index out of range error as `model.opset_import list` is changing dynamically

* pre-commit fix
pull/1753/head
Eugene Liu 2023-02-13 11:46:24 +00:00 committed by GitHub
parent cadc2658f3
commit e519898adb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions
mmdeploy/core/optimizers

View File

@ -222,8 +222,8 @@ def remove_imports(model: onnx.ModelProto):
for node in model.graph.node:
if hasattr(node, 'module') and (node.module not in dst_domain):
dst_domain.append(node.module)
src_domains = [oi.domain for oi in model.opset_import]
src_domains = [oi for oi in model.opset_import]
for i, src_domain in enumerate(src_domains):
if src_domain not in dst_domain:
if src_domain.domain not in dst_domain:
logger.info(f'remove opset_import {src_domain}')
model.opset_import.pop(i)
model.opset_import.remove(src_domain)