You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TensorFlow1.15加载ssd_mobilenet_v2_fpn_keras报ValueError问题

TensorFlow 1.15下目标检测特征提取器版本兼容问题解决

问题复现

运行环境信息:

  • 运行载体:Jupyter Notebook
  • 依赖版本:Python 3.7.13、TensorFlow 1.15.5
  • 实现逻辑:加载pipeline配置、构建检测模型、恢复检查点、定义推理函数,核心代码如下:
# Load pipeline config and build a detection model
configs = config_util.get_configs_from_pipeline_file(CONFIG_PATH)
detection_model = model_builder.build(model_config=configs['model'], is_training=False)

# Restore checkpoint
ckpt = tf.compat.v2.train.Checkpoint(model=detection_model)
ckpt.restore(os.path.join(CHECKPOINT_PATH, 'ckpt-7')).expect_partial()

@tf.function
def detect_fn(image):
    image, shapes = detection_model.preprocess(image)
    prediction_dict = detection_model.predict(image, shapes)
    detections = detection_model.postprocess(prediction_dict, shapes)
    return detections

执行模型构建语句时触发ValueError,核心报错信息如下:

ValueError: ssd_mobilenet_v2_fpn_keras is not supported for tf version 1. See model_builder.py for features extractors compatible with different versions of Tensorflow
报错根因:pipeline配置中指定的ssd_mobilenet_v2_fpn_keras特征提取器为TensorFlow 2.x专属Keras实现,不兼容当前TensorFlow 1.15.5版本。

排查解决流程

  • 第一步:确认TF1.x适配的特征提取器名称
    找到本地Python环境安装路径下object_detection/builders/model_builder.py文件,定位到特征提取器版本校验的分支代码,查看TF1版本支持的特征提取器列表:所有带_keras后缀的特征提取器均为TF2专属,当前使用的MobileNetV2+FPN结构在TF1下的对应实现名为ssd_mobilenet_v2_fpn,无_keras后缀。
  • 第二步:修改pipeline配置文件
    打开CONFIG_PATH指向的pipeline.config文件,定位到model.ssd.feature_extractor配置块,将type字段的取值从ssd_mobilenet_v2_fpn_keras修改为ssd_mobilenet_v2_fpn,其余配置(包括特征提取层通道数、锚框参数、预处理配置等)保持不变,避免和已训练的检查点权重结构不匹配。
  • 第三步:根据检查点训练环境选择后续方案
    修改配置后如果加载检查点出现权重维度不匹配的报错,说明持有的ckpt-7检查点是基于TF2.x+Keras特征提取器训练得到,此时二选一即可:
    • 保留原有配置和检查点,将当前环境TensorFlow升级到2.4~2.6区间和Python3.7兼容的版本,同时匹配安装对应版本的Object Detection API,代码无需修改即可正常运行
    • 保留当前TF1.15.5环境,使用修改后的TF1兼容特征提取器配置重新训练模型,生成适配TF1版本的检查点后再执行推理
  • 避坑说明:TF1.x环境下所有带_keras后缀的特征提取器均无法使用,这类实现完全基于TF2的Keras接口开发,未做TF1版本兼容。

内容的提问来源于stack exchange,提问作者Abrar El Aoua

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.27 09:33:28