0

So I have the following code snipped which works till the last line where i enter the interpreter.invoke()

input_data10 = np.expand_dims(input_text[1:1001], axis=1)
interpreter.resize_tensor_input(input_details[0]['index'], [1000, 1, 100])
interpreter.allocate_tensors()
interpreter.set_tensor(input_details[0]['index'], input_data10)
interpreter.allocate_tensors()
interpreter.invoke()

The error I am getting is this one:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-51-7d35ed1dfe14> in <module>
----> 1 interpreter.invoke()

/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/interpreter.py in invoke(self)
    538     """
    539     self._ensure_safe()
--> 540     self._interpreter.Invoke()
    541 
    542   def reset_all_variables(self):

RuntimeError: tensorflow/lite/kernels/pad.cc:79 SizeOfDimension(op_context->paddings, 0) != op_context->dims (3 != 4)Node number 21 (PAD) failed to prepare.
Asim S
  • 1
  • 1
  • Please make sure that the given model is capable of handling the above input shape, [1000, 1, 100]. – Jae sung Chung Jun 02 '21 at 14:08
  • Hey @JaesungChung, how to know if the above model handles it? Any luck? – Asim S Jun 02 '21 at 14:13
  • It is possible to see the input tensor specs by printing the input tensor details. E.g., interpreter.get_input_details(). Or you can use the Netron app to visualize the given model. – Jae sung Chung Jun 02 '21 at 21:14
  • I actually did see the input tensor specs and it has the shape [1000,1,100] – Asim S Jun 02 '21 at 21:53
  • Please check out that the shape signature field. The shape signature field should be referred for the input tensor shape restriction as I posted the answer at the TensorFlow GitHub. – Jae sung Chung Jun 02 '21 at 22:20

1 Answers1

0

Please check out that the shape signature field. The shape signature field should be referred for the input tensor shape restriction.

Looks like the above model requires the following shape restrictions:

'shape_signature': array([ -1, 100], dtype=int32),

Probably, the right input shape is [1000, 100] for the batch case.


The following snippet shows the above model's input tensor details.

[{'name': 'input_ids',
'index': 0,
'shape': array([1000, 1, 100], dtype=int32),
'shape_signature': array([ -1, 100], dtype=int32),
'dtype': numpy.int32,
'quantization': (0.0, 0),
'quantization_parameters': {'scales': array([], dtype=float32),
'zero_points': array([], dtype=int32),
'quantized_dimension': 0},
'sparsity_parameters': {}}]
Jae sung Chung
  • 835
  • 1
  • 6
  • 7