Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors for single-node graph #94

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nn_meter/ir_converter/onnx_converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, model):
self.graph = inferred_model.graph

self.tensors = {}
for tensor in chain(self.graph.input, self.graph.value_info, self.graph.output):
for tensor in chain(self.graph.input, self.graph.value_info, self.graph.initializer, self.graph.output):
self.tensors[tensor.name] = {
"shape": get_tensor_shape(tensor),
"inputs": [],
Expand Down
8 changes: 6 additions & 2 deletions nn_meter/ir_converter/onnx_converter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
# Licensed under the MIT license.
def get_tensor_shape(tensor):
shape = []
for dim in tensor.type.tensor_type.shape.dim:
shape.append(dim.dim_value)
try:
for dim in tensor.type.tensor_type.shape.dim:
shape.append(dim.dim_value)
except AttributeError:
# initializer
shape += tensor.dims
if len(shape) == 4:
shape = [shape[0], shape[2], shape[3], shape[1]]
return shape
3 changes: 3 additions & 0 deletions nn_meter/utils/graph_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def node(self, name, inbound_nodes=None):
self.graph[node]["outbounds"].append(name)

def refresh(self):
if len(self.graph) <= 1:
return

last_remove_nodes_cnt = -1
while True:
for name in self.graph.keys():
Expand Down