我正在尝试使用 Tensorflow 模型进行转换然后运行推理。
我用 tf.keras 生成了一个 Tensorflow 模型:
model = Sequential()
model.add(Conv2D(64, kernel_size=3, activation='relu', input_shape=(224,224,3), name='image'))
model.add(Conv2D(32, kernel_size=3, activation='relu'))
model.add(Flatten())
model.add(Dense(num_classes, activation='softmax', name='output'))
我训练模型然后我转换文件保存一个.pb tensorflow冻结图形文件,转换为UFF:
uff_model = uff.from_tensorflow_frozen_model(
frozen_file="model/tensorflow/simplemodel.pb",
output_nodes=["output/Softmax"],
output_filename="model/tensorrt/simplemodel.uff")
当我解析模型时:
TRT_LOGGER = trt.Logger(trt.Logger.INFO)
builder = trt.Builder(TRT_LOGGER)
network = builder.create_network()
parser = trt.UffParser()
parser.register_input("image_input", (1, 224, 224, 3))
parser.register_output("output/SoftMax")
parser.parse("model/tensorrt/simplemodel.uff", network)
我收到了这个错误:
[TensorRT] INFO: UFFParser: parsing image_input
[TensorRT] INFO: UFFParser: parsing image/kernel
[TensorRT] INFO: UFFParser: parsing image/Conv2D
[TensorRT] INFO: UFFParser: parsing image/bias
[TensorRT] INFO: UFFParser: parsing image/BiasAdd
[TensorRT] ERROR: image/Conv2D: kernel weights has count 1728 but 129024 was expected
[TensorRT] ERROR: UFFParser: Parser error: image/BiasAdd: The input to the Scale Layer is required to have a minimum of 3 dimensions.
为什么关于内核权重的错误计数?我将输入形状设置为正确的大小(224,244,3...),这是我的模型:
Layer (type) Output Shape Param #
=================================================================
image (Conv2D) (None, 222, 222, 64) 1792
_________________________________________________________________
conv2d (Conv2D) (None, 220, 220, 32) 18464
_________________________________________________________________
flatten (Flatten) (None, 1548800) 0
_________________________________________________________________
output (Dense) (None, 6) 9292806
=================================================================
Total params: 9,313,062
Trainable params: 9,313,062
Non-trainable params: 0
谢谢,
伊戈尔