Closed kuroko1t closed 3 years ago
model = torch.nn.Transformer() src = np.random.rand(10, 32, 512).astype(np.float32) tgt = np.random.rand(20, 32, 512).astype(np.float32) src_shape = (10, 32, 512) tgt_shape = (20, 32, 512) tflite_file = "resnet.tflite" bm = nne.Benchmark(name='tflite') nne.cv2tflite(model, (src_shape, tgt_shape), tflite_file) tflite_model = nne.load_tflite(tflite_file) nne.infer_tflite(tflite_model, (src, tgt), bm=bm)
Even though the model's input shape is set to (10, 32, 512) , (20, 32, 512) , but when I checked interpreter.get_input_details(), it was as follows.
[{'name': 'serving_default_query.7:0', 'index': 0, 'shape': array([ 20, 32, 512], dtype=int32), 'shape_signature': array([ 20, 32, 512], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}, {'name': 'serving_default_input:0', 'index': 1, 'shape': array([ 10, 32, 512], dtype=int32), 'shape_signature': array([ 10, 32, 512], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]
So, this caused dimension mismatch error
ValueError: Cannot set tensor: Dimension mismatch. Got 10 but expected 20 for dimension 0 of input 0.
maybe.. using onnx-tf 1.8.0, this bug was resolved.
Even though the model's input shape is set to (10, 32, 512) , (20, 32, 512) , but when I checked interpreter.get_input_details(), it was as follows.
So, this caused dimension mismatch error