Error: strided_slice_1: cannot use precision Int32 with weights of type Float with op tf.reshape

Description

import tensorflow as tf
import tf2onnx
import numpy as np
import onnxruntime as rt

def build_graph_reshape():
    onnx_path = '../models/onnx/tf_reshape.onnx'
    inputs = tf.placeholder(tf.float32, shape=([3, 2, 4, 2]), name='inputs')
    S = tf.shape(inputs)
    outputs = tf.reshape(inputs, [S[0], S[1], -1])
    outputs = tf.identity(outputs, name='outputs')
    config=tf.ConfigProto(allow_soft_placement=True, gpu_options=tf.GPUOptions(allow_growth=True))
    sess = tf.Session(config=config)
    onnx_graph = tf2onnx.tfonnx.process_tf_graph(sess.graph,
        input_names=["inputs:0"], output_names=["outputs:0"])
    onnx_graph = tf2onnx.optimizer.optimize_graph(onnx_graph)
    model_proto = onnx_graph.make_model("test")
    with open(onnx_path, "wb") as f:
        f.write(model_proto.SerializeToString())
    sess.close()

def onnx_infer_reshape():
    onnx_path = '../models/onnx/tf_reshape.onnx'
    sess = rt.InferenceSession(onnx_path)
    inputs_name = sess.get_inputs()[0].name
    outputs_name = sess.get_outputs()[0].name
    print(inputs_name, outputs_name)
    [outputs_data] = sess.run([outputs_name], {inputs_name: np.ones([3, 2, 4, 2], dtype=np.float32)})
    print('onnx_infer', outputs_data, outputs_data.shape)

def test_reshape():
    build_graph_reshape()
    onnx_infer_reshape()
./trtexec --explicitBatch --onnx=/mnt/disk0/liuqingjie/TensorRT/tests/models/onnx/tf_reshape.onnx
[04/09/2020-07:22:05] [I] === Model Options ===
[04/09/2020-07:22:05] [I] Format: ONNX
[04/09/2020-07:22:05] [I] Model: /mnt/disk0/liuqingjie/TensorRT/tests/models/onnx/tf_reshape.onnx
[04/09/2020-07:22:05] [I] Output:
[04/09/2020-07:22:05] [I] === Build Options ===
[04/09/2020-07:22:05] [I] Max batch: explicit
[04/09/2020-07:22:05] [I] Workspace: 16 MB
[04/09/2020-07:22:05] [I] minTiming: 1
[04/09/2020-07:22:05] [I] avgTiming: 8
[04/09/2020-07:22:05] [I] Precision: FP32
[04/09/2020-07:22:05] [I] Calibration:
[04/09/2020-07:22:05] [I] Safe mode: Disabled
[04/09/2020-07:22:05] [I] Save engine:
[04/09/2020-07:22:05] [I] Load engine:
[04/09/2020-07:22:05] [I] Inputs format: fp32:CHW
[04/09/2020-07:22:05] [I] Outputs format: fp32:CHW
[04/09/2020-07:22:05] [I] Input build shapes: model
[04/09/2020-07:22:05] [I] === System Options ===
[04/09/2020-07:22:05] [I] Device: 0
[04/09/2020-07:22:05] [I] DLACore:
[04/09/2020-07:22:05] [I] Plugins:
[04/09/2020-07:22:05] [I] === Inference Options ===
[04/09/2020-07:22:05] [I] Batch: Explicit
[04/09/2020-07:22:05] [I] Iterations: 10
[04/09/2020-07:22:05] [I] Duration: 3s (+ 200ms warm up)
[04/09/2020-07:22:05] [I] Sleep time: 0ms
[04/09/2020-07:22:05] [I] Streams: 1
[04/09/2020-07:22:05] [I] ExposeDMA: Disabled
[04/09/2020-07:22:05] [I] Spin-wait: Disabled
[04/09/2020-07:22:05] [I] Multithreading: Disabled
[04/09/2020-07:22:05] [I] CUDA Graph: Disabled
[04/09/2020-07:22:05] [I] Skip inference: Disabled
[04/09/2020-07:22:05] [I] Inputs:
[04/09/2020-07:22:05] [I] === Reporting Options ===
[04/09/2020-07:22:05] [I] Verbose: Disabled
[04/09/2020-07:22:05] [I] Averages: 10 inferences
[04/09/2020-07:22:05] [I] Percentile: 99
[04/09/2020-07:22:05] [I] Dump output: Disabled
[04/09/2020-07:22:05] [I] Profile: Disabled
[04/09/2020-07:22:05] [I] Export timing to JSON file:
[04/09/2020-07:22:05] [I] Export output to JSON file:
[04/09/2020-07:22:05] [I] Export profile to JSON file:
[04/09/2020-07:22:05] [I]
----------------------------------------------------------------
Input filename:   /mnt/disk0/liuqingjie/TensorRT/tests/models/onnx/tf_reshape.onnx
ONNX IR version:  0.0.6
Opset version:    8
Producer name:    tf2onnx
Producer version: 1.5.5
Domain:
Model version:    0
Doc string:
----------------------------------------------------------------
[04/09/2020-07:22:06] [W] [TRT] Tensor DataType is determined at build time for tensors not marked as input or output.
[04/09/2020-07:22:06] [W] [TRT] Tensor DataType is determined at build time for tensors not marked as input or output.
[04/09/2020-07:22:06] [W] [TRT] Tensor DataType is determined at build time for tensors not marked as input or output.
[04/09/2020-07:22:06] [W] [TRT] Tensor DataType is determined at build time for tensors not marked as input or output.
[04/09/2020-07:22:06] [W] [TRT] Tensor DataType is determined at build time for tensors not marked as input or output.
[04/09/2020-07:22:06] [W] [TRT] Tensor DataType is determined at build time for tensors not marked as input or output.
[04/09/2020-07:22:06] [E] [TRT] strided_slice_1: cannot use precision Int32 with weights of type Float
[04/09/2020-07:22:06] [E] [TRT] Layer strided_slice_1 failed validation
[04/09/2020-07:22:06] [E] [TRT] Network validation failed.
[04/09/2020-07:22:06] [E] Engine creation failed
[04/09/2020-07:22:06] [E] Engine set up failed
&&&& FAILED TensorRT.trtexec # ./trtexec --explicitBatch --onnx=/mnt/disk0/liuqingjie/TensorRT/tests/models/onnx/tf_reshape.onnx

If I changed

inputs = tf.placeholder(tf.float32, shape=([3, 2, 4, 2]), name='inputs')

to

inputs = tf.placeholder(tf.float32, shape=([None, None, None, None]), name='inputs')

TensorRT would run the op successfully. How can I fix this problem?

A clear and concise description of the bug or issue.

Environment

TensorRT Version: 7.0.0.11
GPU Type: 1080Ti
Nvidia Driver Version: 418.56
CUDA Version: 10.0
CUDNN Version: 7.6.5.32
Operating System + Version: ubuntu 16.04
Python Version (if applicable): 3.6.4
TensorFlow Version (if applicable): 1.13.2

Relevant Files

Please attach or include links to any models, data, files, or scripts necessary to reproduce your issue. (Github repo, Google Drive, Dropbox, etc.)

Steps To Reproduce

Please include:

  • Exact steps/commands to build your repro
  • Exact steps/commands to run your repro
  • Full traceback of errors encountered

Hi @tsingjie,

This seems like an issue with the graph produced by tf2onnx using default opset of 8.

If you explicitly specify opset 11 (the latest opset supported by TRT currently), this model can be parsed fine.

onnx_graph = tf2onnx.tfonnx.process_tf_graph(sess.graph,
        input_names=["inputs:0"], output_names=["outputs:0"],
        opset=11) 
1 Like

Thank you very much. This problem is solved by using upset of 11.