【发布时间】:2021-06-27 05:36:56
【问题描述】:
settings:
Tensorflow = 2.4.1, Keras = 2.4.3, Python = 3.7.9, OpenCV = 4.5.1
我使用 VGG16 的 Keras 基础模型进行迁移学习。 我自己的模型架构开始于:
inputs = tf.keras.layers.Input(shape=(img_height, img_width, 3), name="input_layer")
x = tf.keras.applications.vgg16.preprocess_input(inputs)
x = tf.keras.applications.VGG16(weights=weights, include_top=include_top, input_shape=(img_height, img_width, 3))(x)
等等
然后我冻结我的模型并使用 freeze_optimize_inference.py。 因此我的冻结层看起来像:
x
VGG16/tf.__operators__.getitem/strided_slice/stack
VGG16/tf.__operators__.getitem/strided_slice/stack_1
VGG16/tf.__operators__.getitem/strided_slice/stack_2
VGG16/tf.__operators__.getitem/strided_slice
VGG16/tf.nn.bias_add/BiasAdd/bias
VGG16/tf.nn.bias_add/BiasAdd
VGG16/vgg16/block1_conv1/Conv2D/ReadVariableOp/resource
VGG16/vgg16/block1_conv1/Conv2D/ReadVariableOp
等等
在 C++ 中,我使用 OpenCV 并通过以下方式读取我的模型:
tensorflowNet = cv::dnn::readNetFromTensorflow("freeze_model_inference.pb");
这给了我错误:
OpenCV(4.5.1) C:\build\master_winpack-build-win64-
vc14\opencv\modules\dnn\src\tensorflow\tf_importer.cpp:1527: error: (-213:The
function/feature is not implemented) StridedSlice with stride -1 in function
'cv::dnn::dnn4_v20201117::`anonymous-namespace'::TFImporter::populateNet'
empty model
对我来说,问题来自 vgg16.preprocess_input-layers。我可以创建一个没有这些层的模型,但是我遇到了一个问题“我怎样才能在 C++ 中准确地实现 VGG16 预处理?”
【问题讨论】:
标签: python c++ tensorflow opencv keras