NVIDIA / TensorRT

NVIDIA® TensorRT™ is an SDK for high-performance deep learning inference on NVIDIA GPUs. This repository contains the open source components of TensorRT.
https://developer.nvidia.com/tensorrt
Apache License 2.0
10.67k stars 2.12k forks source link

Report Bug for Select Operation of Python API #731

Closed roborocklsm closed 4 years ago

roborocklsm commented 4 years ago

Description

When I am trying to create SELECT layer by Python API, it gives me the following error message. It seems failed to create select layer.

(200, 100, 3) (200, 100, 3) (200, 100, 3)
[TensorRT] ERROR: Parameter check failed at: ../builder/Network.cpp::addSelect::917, condition: !hasImplicitBatchDimension()
Traceback (most recent call last):
  File "trt_convertor/test_nms.py", line 71, in <module>
    network.mark_output(select_tensor.get_output(0))
AttributeError: 'NoneType' object has no attribute 'get_output'

Environment

TensorRT Version: 7 GPU Type: RTX 2070 Nvidia Driver Version: 440 CUDA Version: 10.2 CUDNN Version: 8.0 Operating System + Version: Ubuntu 18.04 Python Version (if applicable): 3.7 TensorFlow Version (if applicable): PyTorch Version (if applicable): Baremetal or Container (if container which image + tag):

Relevant Files

Steps To Reproduce

import tensorrt as trt
import numpy as np

if __name__ == "__main__":
    logger = trt.Logger(trt.Logger.WARNING)
    with trt.Builder(logger) as builder, builder.create_network() as network:

        builder.max_batch_size = 1
        builder.max_workspace_size = 1 << 30

        bag = []
        np_ones = np.ones([200, 100, 3], dtype=np.float32)# .reshape(-1)
        np_zeros = np.zeros([200, 100, 3], dtype=np.float32)# .reshape(-1)
        bag += [np_bool, np_ones, np_zeros]

        then_tensor = network.add_constant(trt.Dims([200, 100, 3]), 
            trt.Weights(np_ones))
        then_tensor.name = 'then_tensor'

        else_tensor = network.add_constant(trt.Dims([200, 100, 3]), 
            trt.Weights(np_zeros))
        else_tensor.name = 'else_tensor'

        condition_tensor = network.add_elementwise(then_tensor.get_output(0), 
            else_tensor.get_output(0), trt.ElementWiseOperation.GREATER)
        condition_tensor.name = 'condition_tensor'

        print(condition_tensor.get_output(0).shape,
            then_tensor.get_output(0).shape, else_tensor.get_output(0).shape)

        select_tensor = network.add_select(condition_tensor.get_output(0),
            then_tensor.get_output(0), else_tensor.get_output(0))

        network.mark_output(select_tensor.get_output(0))
        engine_path = 'select_test.engine'
        with builder.build_cuda_engine(network) as engine:
            with open(engine_path, "wb") as f:
                f.write(engine.serialize())
            logging.info('Finish writing trt engine!')
georgeliu95 commented 4 years ago

np_bool and logging not defined though. Use builder.create_network(1) instead. Builder - tensorrt

mk-nvidia commented 4 years ago

@roborocklsm As the error suggests, you need to be using explicit batch.