TensorRT:Invalid axis in softmax layer

在尝试序列化RepVGG-A0模型到TensorRT时遇到错误,问题源于softmax层的无效轴。通过检查prototxt文件发现Reshape层缺少对NCHW维度的明确指定。为解决此问题,只需更新Reshape层,完整指定所有维度参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 尝试了一下 RepVGG-A0 的TensorRT序列化,遇到了下面这个问题:

Caffe Parser: Invalid axis in softmax layer - TensorRT expects NCHW input. Negative axis is not supported in TensorRT, please use positive axis indexing
error parsing layer type Softmax

看了一下prototxt: softmax前面,只有 Reshape layer里面是没有显示的指定NCHW【-1表示是自己推理处理】。

所以,稍微调整一下Reshape layer,将缺省维度参数补全即可:

 

layer {
  name: "view1"
  type: "Reshape"
  bottom: "ave_pool_blob1"
  top: "view_blob1"
  reshape_param {
    shape {
      dim: 0
      dim: -1
      dim: 1
      dim: 1
    }
  }
}

 

File ~\anaconda3\Lib\site-packages\tensorflow\python\util\traceback_utils.py:153, in filter_traceback.<locals>.error_handler(*args, **kwargs) 151 except Exception as e: 152 filtered_tb = _process_traceback_frames(e.__traceback__) --> 153 raise e.with_traceback(filtered_tb) from None 154 finally: 155 del filtered_tb File ~\anaconda3\Lib\site-packages\keras\src\backend\common\keras_tensor.py:91, in KerasTensor.__tf_tensor__(self, dtype, name) 90 def __tf_tensor__(self, dtype=None, name=None): ---> 91 raise ValueError( 92 "A KerasTensor cannot be used as input to a TensorFlow function. " 93 "A KerasTensor is a symbolic placeholder for a shape and dtype, " 94 "used when constructing Keras Functional models " 95 "or Keras Functions. You can only use it as input to a Keras layer " 96 "or a Keras operation (from the namespaces `keras.layers` " 97 "and `keras.operations`). " 98 "You are likely doing something like:\n\n" 99 "```\n" 100 "x = Input(...)\n" 101 "...\n" 102 "tf_fn(x) # Invalid.\n" 103 "```\n\n" 104 "What you should do instead is wrap `tf_fn` in a layer:\n\n" 105 "```\n" 106 "class MyLayer(Layer):\n" 107 " def call(self, x):\n" 108 " return tf_fn(x)\n\n" 109 "x = MyLayer()(x)\n" 110 "```\n" 111 ) ValueError: A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras.layers` and `keras.operations`). You are likely doing something like: ``` x = Input(...) ... tf_fn(x) # Invalid. ``` What you should do instead is wrap `tf_fn` in a layer: ``` class MyLayer(Layer): def call(self, x): return tf_fn(x) x = MyLayer()(x) ```
最新发布
07-17
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

微风❤水墨

你的鼓励是我最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值