Onnxruntime: InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Unexpected input data type. Actual: (N11onnxruntime17PrimitiveDataTypeINS_9MLFloat16EEE) , expected: (N11onnxruntime17PrimitiveDataTypeIfEE)

Created on 10 May 2020  路  6Comments  路  Source: microsoft/onnxruntime

Describe the bug
Dear Helper,

I have a tensorflow model

Model: "model"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
em_barrel_Lr1 (InputLayer)      [(None, 56, 11)]     0                                            
__________________________________________________________________________________________________
em_barrel_Lr0 (InputLayer)      [(None, 7, 11)]      0                                            
__________________________________________________________________________________________________
em_barrel_Lr2 (InputLayer)      [(None, 7, 11)]      0                                            
__________________________________________________________________________________________________
em_barrel_Lr3 (InputLayer)      [(None, 7, 11)]      0                                            
__________________________________________________________________________________________________
tile_barrel_Lr1 (InputLayer)    [(None, 7, 11)]      0                                            
__________________________________________________________________________________________________
tile_barrel_Lr2 (InputLayer)    [(None, 7, 11)]      0                                            
__________________________________________________________________________________________________
tile_barrel_Lr3 (InputLayer)    [(None, 7, 11)]      0                                            
__________________________________________________________________________________________________
reshape_7 (Reshape)             (None, 56, 11, 1)    0           em_barrel_Lr1[0][0]              
__________________________________________________________________________________________________
tracks_image (InputLayer)       [(None, 4, 13)]      0                                            
__________________________________________________________________________________________________
reshape_1 (Reshape)             (None, 7, 11, 1)     0           em_barrel_Lr0[0][0]              
__________________________________________________________________________________________________
reshape_2 (Reshape)             (None, 7, 11, 1)     0           em_barrel_Lr2[0][0]              
__________________________________________________________________________________________________
reshape_3 (Reshape)             (None, 7, 11, 1)     0           em_barrel_Lr3[0][0]              
__________________________________________________________________________________________________
reshape_4 (Reshape)             (None, 7, 11, 1)     0           tile_barrel_Lr1[0][0]            
__________________________________________________________________________________________________
reshape_5 (Reshape)             (None, 7, 11, 1)     0           tile_barrel_Lr2[0][0]            
__________________________________________________________________________________________________
reshape_6 (Reshape)             (None, 7, 11, 1)     0           tile_barrel_Lr3[0][0]            
__________________________________________________________________________________________________
conv2d_4 (Conv2D)               (None, 54, 9, 200)   2000        reshape_7[0][0]                  
__________________________________________________________________________________________________
reshape (Reshape)               (None, 4, 13, 1)     0           tracks_image[0][0]               
__________________________________________________________________________________________________
concatenate (Concatenate)       (None, 7, 11, 6)     0           reshape_1[0][0]                  
                                                                 reshape_2[0][0]                  
                                                                 reshape_3[0][0]                  
                                                                 reshape_4[0][0]                  
                                                                 reshape_5[0][0]                  
                                                                 reshape_6[0][0]                  
__________________________________________________________________________________________________
leaky_re_lu_4 (LeakyReLU)       (None, 54, 9, 200)   0           conv2d_4[0][0]                   
__________________________________________________________________________________________________
conv2d (Conv2D)                 (None, 4, 13, 200)   400         reshape[0][0]                    
__________________________________________________________________________________________________
conv2d_2 (Conv2D)               (None, 6, 9, 200)    7400        concatenate[0][0]                
__________________________________________________________________________________________________
max_pooling2d (MaxPooling2D)    (None, 27, 4, 200)   0           leaky_re_lu_4[0][0]              
__________________________________________________________________________________________________
leaky_re_lu (LeakyReLU)         (None, 4, 13, 200)   0           conv2d[0][0]                     
__________________________________________________________________________________________________
leaky_re_lu_2 (LeakyReLU)       (None, 6, 9, 200)    0           conv2d_2[0][0]                   
__________________________________________________________________________________________________
dropout_4 (Dropout)             (None, 27, 4, 200)   0           max_pooling2d[0][0]              
__________________________________________________________________________________________________
dropout (Dropout)               (None, 4, 13, 200)   0           leaky_re_lu[0][0]                
__________________________________________________________________________________________________
dropout_2 (Dropout)             (None, 6, 9, 200)    0           leaky_re_lu_2[0][0]              
__________________________________________________________________________________________________
conv2d_5 (Conv2D)               (None, 25, 2, 200)   360200      dropout_4[0][0]                  
__________________________________________________________________________________________________
conv2d_1 (Conv2D)               (None, 4, 13, 200)   40200       dropout[0][0]                    
__________________________________________________________________________________________________
conv2d_3 (Conv2D)               (None, 5, 7, 200)    240200      dropout_2[0][0]                  
__________________________________________________________________________________________________
leaky_re_lu_5 (LeakyReLU)       (None, 25, 2, 200)   0           conv2d_5[0][0]                   
__________________________________________________________________________________________________
leaky_re_lu_1 (LeakyReLU)       (None, 4, 13, 200)   0           conv2d_1[0][0]                   
__________________________________________________________________________________________________
leaky_re_lu_3 (LeakyReLU)       (None, 5, 7, 200)    0           conv2d_3[0][0]                   
__________________________________________________________________________________________________
max_pooling2d_1 (MaxPooling2D)  (None, 12, 1, 200)   0           leaky_re_lu_5[0][0]              
__________________________________________________________________________________________________
dropout_1 (Dropout)             (None, 4, 13, 200)   0           leaky_re_lu_1[0][0]              
__________________________________________________________________________________________________
dropout_3 (Dropout)             (None, 5, 7, 200)    0           leaky_re_lu_3[0][0]              
__________________________________________________________________________________________________
dropout_5 (Dropout)             (None, 12, 1, 200)   0           max_pooling2d_1[0][0]            
__________________________________________________________________________________________________
p_Eratio (InputLayer)           [(None,)]            0                                            
__________________________________________________________________________________________________
p_Reta (InputLayer)             [(None,)]            0                                            
__________________________________________________________________________________________________
p_Rhad (InputLayer)             [(None,)]            0                                            
__________________________________________________________________________________________________
p_Rphi (InputLayer)             [(None,)]            0                                            
__________________________________________________________________________________________________
p_TRTPID (InputLayer)           [(None,)]            0                                            
__________________________________________________________________________________________________
p_numberOfSCTHits (InputLayer)  [(None,)]            0                                            
__________________________________________________________________________________________________
p_ndof (InputLayer)             [(None,)]            0                                            
__________________________________________________________________________________________________
p_dPOverP (InputLayer)          [(None,)]            0                                            
__________________________________________________________________________________________________
p_deltaEta1 (InputLayer)        [(None,)]            0                                            
__________________________________________________________________________________________________
p_f1 (InputLayer)               [(None,)]            0                                            
__________________________________________________________________________________________________
p_f3 (InputLayer)               [(None,)]            0                                            
__________________________________________________________________________________________________
p_deltaPhiRescaled2 (InputLayer [(None,)]            0                                            
__________________________________________________________________________________________________
p_weta2 (InputLayer)            [(None,)]            0                                            
__________________________________________________________________________________________________
p_d0 (InputLayer)               [(None,)]            0                                            
__________________________________________________________________________________________________
p_d0Sig (InputLayer)            [(None,)]            0                                            
__________________________________________________________________________________________________
p_qd0Sig (InputLayer)           [(None,)]            0                                            
__________________________________________________________________________________________________
p_nTracks (InputLayer)          [(None,)]            0                                            
__________________________________________________________________________________________________
p_sct_weight_charge (InputLayer [(None,)]            0                                            
__________________________________________________________________________________________________
flatten (Flatten)               (None, 10400)        0           dropout_1[0][0]                  
__________________________________________________________________________________________________
flatten_1 (Flatten)             (None, 7000)         0           dropout_3[0][0]                  
__________________________________________________________________________________________________
flatten_2 (Flatten)             (None, 2400)         0           dropout_5[0][0]                  
__________________________________________________________________________________________________
flatten_3 (Flatten)             (None, 1)            0           p_Eratio[0][0]                   
__________________________________________________________________________________________________
flatten_4 (Flatten)             (None, 1)            0           p_Reta[0][0]                     
__________________________________________________________________________________________________
flatten_5 (Flatten)             (None, 1)            0           p_Rhad[0][0]                     
__________________________________________________________________________________________________
flatten_6 (Flatten)             (None, 1)            0           p_Rphi[0][0]                     
__________________________________________________________________________________________________
flatten_7 (Flatten)             (None, 1)            0           p_TRTPID[0][0]                   
__________________________________________________________________________________________________
flatten_8 (Flatten)             (None, 1)            0           p_numberOfSCTHits[0][0]          
__________________________________________________________________________________________________
flatten_9 (Flatten)             (None, 1)            0           p_ndof[0][0]                     
__________________________________________________________________________________________________
flatten_10 (Flatten)            (None, 1)            0           p_dPOverP[0][0]                  
__________________________________________________________________________________________________
flatten_11 (Flatten)            (None, 1)            0           p_deltaEta1[0][0]                
__________________________________________________________________________________________________
flatten_12 (Flatten)            (None, 1)            0           p_f1[0][0]                       
__________________________________________________________________________________________________
flatten_13 (Flatten)            (None, 1)            0           p_f3[0][0]                       
__________________________________________________________________________________________________
flatten_14 (Flatten)            (None, 1)            0           p_deltaPhiRescaled2[0][0]        
__________________________________________________________________________________________________
flatten_15 (Flatten)            (None, 1)            0           p_weta2[0][0]                    
__________________________________________________________________________________________________
flatten_16 (Flatten)            (None, 1)            0           p_d0[0][0]                       
__________________________________________________________________________________________________
flatten_17 (Flatten)            (None, 1)            0           p_d0Sig[0][0]                    
__________________________________________________________________________________________________
flatten_18 (Flatten)            (None, 1)            0           p_qd0Sig[0][0]                   
__________________________________________________________________________________________________
flatten_19 (Flatten)            (None, 1)            0           p_nTracks[0][0]                  
__________________________________________________________________________________________________
flatten_20 (Flatten)            (None, 1)            0           p_sct_weight_charge[0][0]        
__________________________________________________________________________________________________
concatenate_1 (Concatenate)     (None, 19818)        0           flatten[0][0]                    
                                                                 flatten_1[0][0]                  
                                                                 flatten_2[0][0]                  
                                                                 flatten_3[0][0]                  
                                                                 flatten_4[0][0]                  
                                                                 flatten_5[0][0]                  
                                                                 flatten_6[0][0]                  
                                                                 flatten_7[0][0]                  
                                                                 flatten_8[0][0]                  
                                                                 flatten_9[0][0]                  
                                                                 flatten_10[0][0]                 
                                                                 flatten_11[0][0]                 
                                                                 flatten_12[0][0]                 
                                                                 flatten_13[0][0]                 
                                                                 flatten_14[0][0]                 
                                                                 flatten_15[0][0]                 
                                                                 flatten_16[0][0]                 
                                                                 flatten_17[0][0]                 
                                                                 flatten_18[0][0]                 
                                                                 flatten_19[0][0]                 
                                                                 flatten_20[0][0]                 
__________________________________________________________________________________________________
dense (Dense)                   (None, 200)          3963800     concatenate_1[0][0]              
__________________________________________________________________________________________________
leaky_re_lu_6 (LeakyReLU)       (None, 200)          0           dense[0][0]                      
__________________________________________________________________________________________________
dropout_6 (Dropout)             (None, 200)          0           leaky_re_lu_6[0][0]              
__________________________________________________________________________________________________
dense_1 (Dense)                 (None, 200)          40200       dropout_6[0][0]                  
__________________________________________________________________________________________________
leaky_re_lu_7 (LeakyReLU)       (None, 200)          0           dense_1[0][0]                    
__________________________________________________________________________________________________
dropout_7 (Dropout)             (None, 200)          0           leaky_re_lu_7[0][0]              
__________________________________________________________________________________________________
dense_2 (Dense)                 (None, 2)            402         dropout_7[0][0]                  
==================================================================================================
Total params: 4,654,802
Trainable params: 4,654,802
Non-trainable params: 0
__________________________________________________________________________________________________

which converts to .onnx model, and I have a sample to input in the model as dictionary with following keys.

'em_barrel_Lr0', 'em_barrel_Lr1', 'em_barrel_Lr2', 'em_barrel_Lr3', 'tile_barrel_Lr1', 
'tile_barrel_Lr2', 'tile_barrel_Lr3', 'tracks_image','p_Eratio', 'p_Reta', 'p_Rhad', 
'p_Rphi', 'p_TRTPID', 'p_numberOfSCTHits', 'p_ndof', 'p_dPOverP', 
'p_deltaEta1', 'p_f1', 'p_f3', 'p_deltaPhiRescaled2', 'p_weta2', 
'p_d0', 'p_d0Sig', 'p_qd0Sig', 'p_nTracks', 'p_sct_weight_charge'

I tried to feed the sample to the .onnx model by

input_feeds = {}
key = ['em_barrel_Lr0', 'em_barrel_Lr1', 'em_barrel_Lr2', 'em_barrel_Lr3', 'tile_barrel_Lr1', 
'tile_barrel_Lr2', 'tile_barrel_Lr3', 'tracks_image','p_Eratio', 'p_Reta', 'p_Rhad', 
'p_Rphi', 'p_TRTPID', 'p_numberOfSCTHits', 'p_ndof', 'p_dPOverP', 
'p_deltaEta1', 'p_f1', 'p_f3', 'p_deltaPhiRescaled2', 'p_weta2', 
'p_d0', 'p_d0Sig', 'p_qd0Sig', 'p_nTracks', 'p_sct_weight_charge']
for i in range(26):
    input_feeds[sess_ort.get_inputs()[i].name] = final_sample1[key[i]]

and then

output_name = sess_ort.get_outputs()[0].name
res = sess_ort.run([output_name], input_feeds)

and I get following error

InvalidArgument                           Traceback (most recent call last)
<ipython-input-27-830965c44719> in <module>
----> 1 res = sess_ort.run([output_name], input_feeds)

/export/home/zp/gupta/envTf2/lib/python3.7/site-packages/onnxruntime/capi/session.py in run(self, output_names, input_feed, run_options)
    140             output_names = [output.name for output in self._outputs_meta]
    141         try:
--> 142             return self._sess.run(output_names, input_feed, run_options)
    143         except C.EPFail as err:
    144             if self._enable_fallback:

InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Unexpected input data type. Actual: (N11onnxruntime17PrimitiveDataTypeINS_9MLFloat16EEE) , expected: (N11onnxruntime17PrimitiveDataTypeIfEE)

need help,

Thanks,
Debo.

Urgency
none
System information

  • OS Platform and Distribution (linux centos7):
  • ONNX Runtime installed from binary:
  • ONNX Runtime version:Latest
  • Python version: 3.7

Most helpful comment

Hi @pranavsharma ,
I figured out, your example really helped; especially the part you did

 d = create_random_data(shape_arr, np.float32, 0, 1, None)

The dataset I was feeding was of type np.float16, e.g.

'p_Eratio': array([0.40392396], dtype=float16),
 'p_Reta': array([-0.64157045], dtype=float16),

I just change them to float32 by final_sample1[key].astype(np.float32) and it works with my code.
Thanks a lot,
Debo.

All 6 comments

Is it possible to attach the onnx model here? Or you can just email me?

Hi @pranavsharma ,
Couldn't attach it here I emailed you the .onnx model.

Thanks,
Debo

I couldn't repro it with onnxruntime 1.2. Which version are you using? Here's the script I used https://gist.github.com/pranavsharma/f3f9b14a1ccc1e5567995a39568db9b7.

Hi @pranavsharma,

Thanks a lot for investigating. I am using onnxruntime 1.1.1 since our c++ api is still 1.1.1 please see the following

ort.__version__
'1.1.1'

and the sample I am using quite big maybe try to put everything in github but for now please see the following, the sample I am using has the following dimention

em_barrel_Lr0 : (1, 7, 11)
em_barrel_Lr1 : (1, 56, 11)
em_barrel_Lr2 : (1, 7, 11)
em_barrel_Lr3 : (1, 7, 11)
tile_barrel_Lr1 : (1, 7, 11)
tile_barrel_Lr2 : (1, 7, 11)
tile_barrel_Lr3 : (1, 7, 11)
tracks_image : (1, 4, 13)
p_Eratio : (1,)
p_Reta : (1,)
p_Rhad : (1,)
p_Rphi : (1,)
p_TRTPID : (1,)
p_numberOfSCTHits : (1,)
p_ndof : (1,)
p_dPOverP : (1,)
p_deltaEta1 : (1,)
p_f1 : (1,)
p_f3 : (1,)
p_deltaPhiRescaled2 : (1,)
p_weta2 : (1,)
p_d0 : (1,)
p_d0Sig : (1,)
p_qd0Sig : (1,)
p_nTracks : (1,)
p_sct_weight_charge : (1,)

and the model I have

em_barrel_Lr0 : ['N', 7, 11]
em_barrel_Lr1 : ['N', 56, 11]
em_barrel_Lr2 : ['N', 7, 11]
em_barrel_Lr3 : ['N', 7, 11]
tile_barrel_Lr1 : ['N', 7, 11]
tile_barrel_Lr2 : ['N', 7, 11]
tile_barrel_Lr3 : ['N', 7, 11]
tracks_image : ['N', 4, 13]
p_Eratio : ['N']
p_Reta : ['N']
p_Rhad : ['N']
p_Rphi : ['N']
p_TRTPID : ['N']
p_numberOfSCTHits : ['N']
p_ndof : ['N']
p_dPOverP : ['N']
p_deltaEta1 : ['N']
p_f1 : ['N']
p_f3 : ['N']
p_deltaPhiRescaled2 : ['N']
p_weta2 : ['N']
p_d0 : ['N']
p_d0Sig : ['N']
p_qd0Sig : ['N']
p_nTracks : ['N']
p_sct_weight_charge : ['N']

The same sample works for the tensorflow model from which the .onnx model developed.
Thanks,
Debo.

Hi @pranavsharma ,
I figured out, your example really helped; especially the part you did

 d = create_random_data(shape_arr, np.float32, 0, 1, None)

The dataset I was feeding was of type np.float16, e.g.

'p_Eratio': array([0.40392396], dtype=float16),
 'p_Reta': array([-0.64157045], dtype=float16),

I just change them to float32 by final_sample1[key].astype(np.float32) and it works with my code.
Thanks a lot,
Debo.

Glad it worked. Thanks!

Was this page helpful?
0 / 5 - 0 ratings