Negative dimension size caused by subtracting 8 from 7 for op: 'AvgPool' with input shapes: [32,7,7,2048]

I have modified the script (which implements integrated TensorFlow-TensorRT) to accelerate the inference of my model (trained with TensorFlow and exported the inference graph as a SavedModel). The script runs fine for the inference mode FP32, but throws errors for native mode> Some tips or suggestions about the root cause?

Source code / logs
Inference mode: native

INFO:tensorflow:Restoring parameters from b'/home/saved_model/1538691479/variables/variables'
INFO:tensorflow:Froze 251 variables.
Converted 251 variables to const ops.
graph_name frozen_graph.pb:
Running native graph
INFO:tensorflow:Starting execution
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/", line 489, in import_graph_def
    graph._c_graph, serialized, options)  # pylint: disable=protected-access
Negative dimension size caused by subtracting 8 from 7 for 'import/resnet_model/average_pooling2d/AvgPool' (op: 'AvgPool') with input shapes: [32,7,7,2048].

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "", line 635, in <module>
  File "", line 480, in main
    g_name, frozen_graph_def, data, log_buffer, flags)
  File "", line 376, in time_and_log_graph
    graph_def, data, flags.input_node, flags.output_node, flags.num_loops)
  File "", line 314, in time_graph
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/util/", line 432, in new_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/", line 493, in import_graph_def
    raise ValueError(str(e))

Hello, can you provide details on the platforms you are using?

Linux distro and version
GPU type
nvidia driver version
CUDA version
CUDNN version
Python version [if using python]
Tensorflow version
TensorRT version

It’d help us debug if you can provide a small reproduction package including source, model, and dataset. You can DM me if you can’t share publically.

hi, I resolved the issue by changing padding=‘same’ to the average_pooling2d layer in my model

inputs = tf.layers.average_pooling2d(
          inputs=inputs, pool_size=pool_size, strides=1, padding='SAME',

before it was padding=‘VALID’, which was generating the error “Negative dimension size caused by subtracting 8 from 7 for op: ‘AvgPool’”

If someone has the same issue and want more information see this link: