# UFF parser int8 problem

**URL:** <https://forums.developer.nvidia.com/t/uff-parser-int8-problem/70145>\
**Category:** TensorRT\
**Created:** [February 4, 2019, 10:56pm UTC](https://forums.developer.nvidia.com/t/uff-parser-int8-problem/70145 "2019-02-04T22:56:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danxpy](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@danxpy](https://forums.developer.nvidia.com/u/danxpy)\
**Post date:** [February 4, 2019, 10:56pm UTC](https://forums.developer.nvidia.com/t/uff-parser-int8-problem/70145/1 "2019-02-04T22:56:24Z")

</div>

Does the latest versions of TensorRT support loading FP32-trained tensorflow model for INT8 inference ?

When trying to load the UFF model with

```auto
parser->parse(uff_file_name.c_str(), *network, nvinfer1::DataType::kINT8)

```

I get an error like this:

```auto
UFFParser: Parser error: dense_7/kernel: Invalid weights types when converted. Trying to convert from FP32 To INT8

```

I thought this maybe a problem with my model but I have tried many tensorflow frozen graphs (\*.pb) and converted them with convert-to-uff and encountered the same issue in all. However, FLOAT and HALF precision inference work without a problem though.

My TensorRT version is 5.0.0.10.

---

<div class="post-metadata">

**Author:** ![NVES](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nves/32/14043_2.png) [@NVES](https://forums.developer.nvidia.com/u/NVES)\
**Post date:** [February 4, 2019, 11:26pm UTC](https://forums.developer.nvidia.com/t/uff-parser-int8-problem/70145/2 "2019-02-04T23:26:08Z")

</div>

hello,

You’ll need to calibrate the int8 input first. INT8 engines are built from 32-bit network definitions and require significantly more investment than building a 32-bit or 16-bit engine. In particular, the TensorRT builder must perform a process called calibration to determine how best to represent the weights and activations as 8-bit integers.

Please see this example: [https://docs.nvidia.com/deeplearning/sdk/tensorrt-developer-guide/index.html#int8\_sample](https://docs.nvidia.com/deeplearning/sdk/tensorrt-developer-guide/index.html#int8_sample)

---

<div class="post-metadata">

**Author:** ![danxpy](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@danxpy](https://forums.developer.nvidia.com/u/danxpy)\
**Post date:** [February 4, 2019, 11:44pm UTC](https://forums.developer.nvidia.com/t/uff-parser-int8-problem/70145/3 "2019-02-04T23:44:54Z")

</div>

> [@NVES](#):
>
> hello,
> 
> You’ll need to calibrate the int8 input first. INT8 engines are built from 32-bit network definitions and require significantly more investment than building a 32-bit or 16-bit engine. In particular, the TensorRT builder must perform a process called calibration to determine how best to represent the weights and activations as 8-bit integers.
> 
> Please see this example: [Developer Guide :: NVIDIA Deep Learning TensorRT Documentation](https://docs.nvidia.com/deeplearning/sdk/tensorrt-developer-guide/index.html#int8_sample)

Yes, I understand that but the problem does not occur during inference but loading of the UFF model.  
I am actually following the sampleInt8API example which avoids uses of the calibration step.  
Parsing the UFF model fails before the code setting layer precision etcs… I also tried moving that part of the code before the network is parsed to no avail.

```auto
IBuilder* builder = createInferBuilder(logger);
    INetworkDefinition* network = builder->createNetwork();  
    if(!parser->parse(uff_file_name.c_str(), *network, floatMode)) { //problem occurs here
        std::cout << "Fail to parse network " << uff_file_name << std::endl;;
        return;
    }     
    if (floatMode == nvinfer1::DataType::kHALF) {
        builder->setHalf2Mode(true);
    } else if (floatMode == nvinfer1::DataType::kINT8) {
        builder->setInt8Mode(true);
        builder->setInt8Calibrator(nullptr);
        builder->setStrictTypeConstraints(true);

        setLayerPrecision(network);
        setDynamicRange(network);
    }
    builder->setMaxBatchSize(BATCH_SIZE);
    builder->setMaxWorkspaceSize((1 << 30));
    engine = builder->buildCudaEngine(*network);
    if (!engine) {
        std::cout << "Unable to create engine" << std::endl;
        return;
    }

```

A similar issue mentioned here [TensorRT Python interface UFF int8 calibration issue - TensorRT - NVIDIA Developer Forums](https://devtalk.nvidia.com/default/topic/1029476/tensorrt/tensorrt-python-interface-uff-int8-calibration-issue/)  
concluded the problem is with tensorflow-int8 path that is not tested well. I was wondering if that has changed with the newer version of tensorrt.

**Edit**

It looks like I have to parse with the precision that the network is trained with.  
Please confirm this.

I did this before:

```auto
parser->parse(uff_file_name.c_str(), *network, nvinfer1::DataType::kINT8)

```

but I should use FLOAT to load the mode even when I am going to infer wiht int8

```auto
parser->parse(uff_file_name.c_str(), *network, nvinfer1::DataType::kFLOAT)

```

---

<div class="post-metadata">

**Author:** ![jerry\_mazeyu](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@jerry\_mazeyu](https://forums.developer.nvidia.com/u/jerry_mazeyu)\
**Post date:** [September 25, 2019, 9:34am UTC](https://forums.developer.nvidia.com/t/uff-parser-int8-problem/70145/4 "2019-09-25T09:34:32Z")

</div>

hi, I met the same problem, however, I use python api, I would like to know if tensorrt 6 support to transform uff to int8 mode?

---

<div class="post-metadata">

**Author:** ![TomNVIDIA](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/tomnvidia/32/14181_2.png) [@TomNVIDIA](https://forums.developer.nvidia.com/u/TomNVIDIA)\
**Post date:** [October 12, 2021, 7:47pm UTC](https://forums.developer.nvidia.com/t/uff-parser-int8-problem/70145/5 "2021-10-12T19:47:57Z")

</div>

Closed on October 12, 2021, 7:47pm UTC


