microsoft / microsoft/onnxruntime

Segmentation fault : onnxruntime infer all outputs include all nodes with python API

Open
#10,044 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api core runtime feature request
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 8h
Merged PRs (30d)
179

Description

Describe the bug
Segmentation fault (core dumped)

System information

  • OS Platform and Distribution: Ubuntu 18.04.5 LTS
  • ONNX Runtime installed from (source or binary): binary
  • ONNX Runtime version: Version: 1.6.0
  • Python version: Python 3.8.10

To Reproduce
model:https://github.com/onnx/models/blob/master/vision/classification/inception_and_googlenet/inception_v1/model/inception-v1-9.onnx

#test.py

  import onnx
  import onnx.numpy_helper
  import onnxruntime as ort
  from collections import OrderedDict
  
  
  def readArrayFromPB(file):
      tensor = onnx.TensorProto()
      with open(file, "rb") as f:
          tensor.ParseFromString(f.read())
      array = onnx.numpy_helper.to_array(tensor)
      return array
  
  def writeArrayToPB(file, array):
      tensor = onnx.numpy_helper.from_array(array)
      with open(file, "wb") as f:
          f.write(tensor.SerializeToString())
  
  if __name__=="__main__":
      model = onnx.load_model("/home/wang/wangxudong/RPP_iTest/netmodel/save_model_all_nodes/inception-v1-9/inception-v1-9.onnx")
  
      OutputNameLists = []
      for i in range(len(model.graph.node)):
          OutputNameLists.extend(model.graph.node[i].output)    
  
      OutputNameList = []
      for i in range(len(model.graph.output)):
          OutputNameList.append(model.graph.output[i].name)
  
      all_outs = list(set(OutputNameLists) - set(OutputNameList))
      all_outs = [onnx.ValueInfoProto(name=x) for x in all_outs]
      print("all_outs:{0}".format(all_outs))
  
      model.graph.output.extend(all_outs)
  
      ort_session = ort.InferenceSession(model.SerializeToString())
  
      ort_ins = {}
      ort_ins.update({"data_0":readArrayFromPB("/home/wang/wangxudong/RPP_iTest/netmodel/save_model_all_nodes/inception-v1-9/test_data_set_0/input_0.pb")})
      
      # ort_outnames = ["prob_1"]
      ort_outnames = [x.name for x in ort_session.get_outputs()]
      print("ort_outnames:{0}".format(ort_outnames))
      
      ort_array = ort_session.run(ort_outnames, ort_ins)
  
      ort_outs = OrderedDict(zip(ort_outnames, ort_array))
      ort_outshapes = {}
      for k,v in ort_outs.items():
          writeArrayToPB("/home/wang/wangxudong/RPP_iTest/netmodel/save_model_all_outs/inception-v1-9/prob_1.pb",v)
          ort_outshapes.update({k:v.shape})
      print(ort_outshapes)

Expected behavior
onnxruntime infer success

Screenshots
(ubuntu) wang@VM-1-159-ubuntu:~/wangxudong/RPP_iTest/netmodel$ python3 test.py
all_outs:[name: "loss3_classifier_1"
, name: "conv1_7x7_s2_1"
, name: "inception_4b_5x5_reduce_2"
, name: "inception_4b_5x5_1"
, name: "inception_4c_1x1_2"
, name: "inception_4c_3x3_reduce_2"
, name: "pool3_3x3_s2_1"
, name: "inception_5b_pool_proj_2"
, name: "inception_5a_5x5_2"
, name: "inception_4c_5x5_2"
, name: "inception_3a_pool_1"
, name: "pool1_norm1_1"
, name: "inception_4c_3x3_1"
, name: "inception_3a_3x3_reduce_2"
, name: "inception_4d_pool_proj_2"
, name: "inception_4e_pool_1"
, name: "_pool5/7x7_s1_mask_1"
, name: "inception_4b_3x3_reduce_2"
, name: "pool5_7x7_s1_1"
, name: "inception_4a_5x5_1"
, name: "inception_3a_5x5_1"
, name: "inception_4d_5x5_reduce_1"
, name: "inception_5b_5x5_2"
, name: "inception_4d_5x5_reduce_2"
, name: "inception_3b_5x5_reduce_2"
, name: "inception_4b_1x1_2"
, name: "inception_4a_1x1_1"
, name: "inception_4b_3x3_1"
, name: "inception_3a_1x1_1"
, name: "inception_4d_3x3_1"
, name: "pool1_3x3_s2_1"
, name: "inception_5b_output_1"
, name: "inception_5a_5x5_reduce_2"
, name: "inception_4d_1x1_1"
, name: "inception_4e_5x5_1"
, name: "conv2_3x3_1"
, name: "inception_4e_1x1_2"
, name: "inception_4d_3x3_reduce_1"
, name: "inception_3b_5x5_2"
, name: "inception_4d_3x3_reduce_2"
, name: "inception_4c_pool_1"
, name: "inception_5b_1x1_1"
, name: "inception_5a_3x3_reduce_2"
, name: "inception_5a_output_1"
, name: "inception_4a_3x3_2"
, name: "inception_5a_pool_proj_1"
, name: "inception_3a_5x5_reduce_2"
, name: "inception_3a_pool_proj_1"
, name: "inception_5a_pool_1"
, name: "inception_4e_pool_proj_1"
, name: "conv2_3x3_reduce_1"
, name: "inception_4c_pool_proj_1"
, name: "inception_4d_3x3_2"
, name: "inception_3b_3x3_reduce_2"
, name: "inception_4a_5x5_reduce_1"
, name: "inception_4a_3x3_1"
, name: "inception_4c_output_1"
, name: "pool2_3x3_s2_1"
, name: "inception_4e_3x3_1"
, name: "inception_4e_pool_proj_2"
, name: "conv2_3x3_2"
, name: "inception_3b_pool_1"
, name: "conv2_norm2_1"
, name: "inception_5b_3x3_reduce_2"
, name: "inception_4a_3x3_reduce_1"
, name: "inception_5a_pool_proj_2"
, name: "conv1_7x7_s2_2"
, name: "inception_3a_pool_proj_2"
, name: "inception_3a_3x3_1"
, name: "inception_5b_5x5_reduce_2"
, name: "inception_4b_5x5_2"
, name: "inception_4e_5x5_reduce_1"
, name: "inception_4b_pool_proj_1"
, name: "inception_4c_3x3_reduce_1"
, name: "inception_5a_5x5_1"
, name: "inception_4a_pool_proj_1"
, name: "inception_4a_5x5_reduce_2"
, name: "inception_4a_1x1_2"
, name: "inception_5a_3x3_reduce_1"
, name: "inception_5b_1x1_2"
, name: "inception_4c_5x5_reduce_2"
, name: "inception_4c_3x3_2"
, name: "inception_4e_3x3_reduce_2"
, name: "inception_5b_pool_proj_1"
, name: "inception_3a_5x5_reduce_1"
, name: "inception_3a_5x5_2"
, name: "inception_3b_pool_proj_1"
, name: "inception_3b_pool_proj_2"
, name: "OC2_DUMMY_0"
, name: "inception_4e_output_1"
, name: "inception_4b_pool_proj_2"
, name: "inception_3b_output_1"
, name: "inception_4b_3x3_2"
, name: "inception_4a_3x3_reduce_2"
, name: "inception_4a_5x5_2"
, name: "inception_4e_1x1_1"
, name: "inception_3b_5x5_reduce_1"
, name: "inception_4e_5x5_reduce_2"
, name: "inception_3b_5x5_1"
, name: "inception_5b_pool_1"
, name: "inception_3a_3x3_2"
, name: "inception_3a_3x3_reduce_1"
, name: "inception_5b_5x5_reduce_1"
, name: "inception_4d_5x5_1"
, name: "inception_5b_3x3_1"
, name: "inception_4d_pool_proj_1"
, name: "inception_4b_1x1_1"
, name: "inception_3a_output_1"
, name: "inception_4b_3x3_reduce_1"
, name: "inception_3b_3x3_2"
, name: "inception_5a_1x1_1"
, name: "inception_4d_1x1_2"
, name: "inception_3b_1x1_2"
, name: "inception_4c_5x5_1"
, name: "inception_5b_3x3_reduce_1"
, name: "inception_3b_3x3_reduce_1"
, name: "inception_4b_output_1"
, name: "inception_5a_3x3_2"
, name: "inception_4d_pool_1"
, name: "inception_4d_output_1"
, name: "inception_4e_3x3_reduce_1"
, name: "OC2_DUMMY_2"
, name: "inception_4a_pool_1"
, name: "inception_4c_5x5_reduce_1"
, name: "inception_4a_output_1"
, name: "inception_4c_1x1_1"
, name: "pool4_3x3_s2_1"
, name: "inception_3a_1x1_2"
, name: "inception_4b_5x5_reduce_1"
, name: "inception_4d_5x5_2"
, name: "inception_4a_pool_proj_2"
, name: "conv2_3x3_reduce_2"
, name: "inception_5a_1x1_2"
, name: "inception_5b_3x3_2"
, name: "inception_3b_1x1_1"
, name: "inception_5a_5x5_reduce_1"
, name: "pool5_7x7_s1_2"
, name: "inception_5a_3x3_1"
, name: "inception_4e_5x5_2"
, name: "inception_3b_3x3_1"
, name: "inception_5b_5x5_1"
, name: "inception_4c_pool_proj_2"
, name: "inception_4b_pool_1"
, name: "inception_4e_3x3_2"
]
ort_outnames:['prob_1', 'loss3_classifier_1', 'conv1_7x7_s2_1', 'inception_4b_5x5_reduce_2', 'inception_4b_5x5_1', 'inception_4c_1x1_2', 'inception_4c_3x3_reduce_2', 'pool3_3x3_s2_1', 'inception_5b_pool_proj_2', 'inception_5a_5x5_2', 'inception_4c_5x5_2', 'inception_3a_pool_1', 'pool1_norm1_1', 'inception_4c_3x3_1', 'inception_3a_3x3_reduce_2', 'inception_4d_pool_proj_2', 'inception_4e_pool_1', '_pool5/7x7_s1_mask_1', 'inception_4b_3x3_reduce_2', 'pool5_7x7_s1_1', 'inception_4a_5x5_1', 'inception_3a_5x5_1', 'inception_4d_5x5_reduce_1', 'inception_5b_5x5_2', 'inception_4d_5x5_reduce_2', 'inception_3b_5x5_reduce_2', 'inception_4b_1x1_2', 'inception_4a_1x1_1', 'inception_4b_3x3_1', 'inception_3a_1x1_1', 'inception_4d_3x3_1', 'pool1_3x3_s2_1', 'inception_5b_output_1', 'inception_5a_5x5_reduce_2', 'inception_4d_1x1_1', 'inception_4e_5x5_1', 'conv2_3x3_1', 'inception_4e_1x1_2', 'inception_4d_3x3_reduce_1', 'inception_3b_5x5_2', 'inception_4d_3x3_reduce_2', 'inception_4c_pool_1', 'inception_5b_1x1_1', 'inception_5a_3x3_reduce_2', 'inception_5a_output_1', 'inception_4a_3x3_2', 'inception_5a_pool_proj_1', 'inception_3a_5x5_reduce_2', 'inception_3a_pool_proj_1', 'inception_5a_pool_1', 'inception_4e_pool_proj_1', 'conv2_3x3_reduce_1', 'inception_4c_pool_proj_1', 'inception_4d_3x3_2', 'inception_3b_3x3_reduce_2', 'inception_4a_5x5_reduce_1', 'inception_4a_3x3_1', 'inception_4c_output_1', 'pool2_3x3_s2_1', 'inception_4e_3x3_1', 'inception_4e_pool_proj_2', 'conv2_3x3_2', 'inception_3b_pool_1', 'conv2_norm2_1', 'inception_5b_3x3_reduce_2', 'inception_4a_3x3_reduce_1', 'inception_5a_pool_proj_2', 'conv1_7x7_s2_2', 'inception_3a_pool_proj_2', 'inception_3a_3x3_1', 'inception_5b_5x5_reduce_2', 'inception_4b_5x5_2', 'inception_4e_5x5_reduce_1', 'inception_4b_pool_proj_1', 'inception_4c_3x3_reduce_1', 'inception_5a_5x5_1', 'inception_4a_pool_proj_1', 'inception_4a_5x5_reduce_2', 'inception_4a_1x1_2', 'inception_5a_3x3_reduce_1', 'inception_5b_1x1_2', 'inception_4c_5x5_reduce_2', 'inception_4c_3x3_2', 'inception_4e_3x3_reduce_2', 'inception_5b_pool_proj_1', 'inception_3a_5x5_reduce_1', 'inception_3a_5x5_2', 'inception_3b_pool_proj_1', 'inception_3b_pool_proj_2', 'OC2_DUMMY_0', 'inception_4e_output_1', 'inception_4b_pool_proj_2', 'inception_3b_output_1', 'inception_4b_3x3_2', 'inception_4a_3x3_reduce_2', 'inception_4a_5x5_2', 'inception_4e_1x1_1', 'inception_3b_5x5_reduce_1', 'inception_4e_5x5_reduce_2', 'inception_3b_5x5_1', 'inception_5b_pool_1', 'inception_3a_3x3_2', 'inception_3a_3x3_reduce_1', 'inception_5b_5x5_reduce_1', 'inception_4d_5x5_1', 'inception_5b_3x3_1', 'inception_4d_pool_proj_1', 'inception_4b_1x1_1', 'inception_3a_output_1', 'inception_4b_3x3_reduce_1', 'inception_3b_3x3_2', 'inception_5a_1x1_1', 'inception_4d_1x1_2', 'inception_3b_1x1_2', 'inception_4c_5x5_1', 'inception_5b_3x3_reduce_1', 'inception_3b_3x3_reduce_1', 'inception_4b_output_1', 'inception_5a_3x3_2', 'inception_4d_pool_1', 'inception_4d_output_1', 'inception_4e_3x3_reduce_1', 'OC2_DUMMY_2', 'inception_4a_pool_1', 'inception_4c_5x5_reduce_1', 'inception_4a_output_1', 'inception_4c_1x1_1', 'pool4_3x3_s2_1', 'inception_3a_1x1_2', 'inception_4b_5x5_reduce_1', 'inception_4d_5x5_2', 'inception_4a_pool_proj_2', 'conv2_3x3_reduce_2', 'inception_5a_1x1_2', 'inception_5b_3x3_2', 'inception_3b_1x1_1', 'inception_5a_5x5_reduce_1', 'pool5_7x7_s1_2', 'inception_5a_3x3_1', 'inception_4e_5x5_2', 'inception_3b_3x3_1', 'inception_5b_5x5_1', 'inception_4c_pool_proj_2', 'inception_4b_pool_1', 'inception_4e_3x3_2']
Segmentation fault (core dumped)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided test.py with the linked Inception v1 model and the reported ONNX Runtime 1.6.0 environment. Compare inference with the original outputs against the version that extends model.graph.output with every node output. Done means the Python API no longer segfaults and inference completes for the requested outputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.