执行deepmac_colab.ipynb遇TypeError:意外关键字参数'box_ind'求助
解决
reframe_box_masks_to_image_masks的box_ind参数错误 这个错误是因为TensorFlow Object Detection API中reframe_box_masks_to_image_masks函数的参数定义在不同版本中发生了变化,导致prediction_function的调用不兼容当前API版本。以下是两种可行的解决方法:
方法一:修改参数调用适配当前API版本
- 在笔记本中找到定义
prediction_function的代码块(通常是加载模型后构建预测逻辑的部分),定位到内部调用reframe_box_masks_to_image_masks的位置。 - 根据当前使用的Object Detection API版本调整参数:
- 如果API版本没有
box_ind参数(较新版本常见),删除调用中的box_ind参数。例如,将:
修改为:reframe_box_masks_to_image_masks(box_masks, box_ind, boxes, image_height, image_width)reframe_box_masks_to_image_masks(box_masks, boxes, image_height, image_width) - 如果API版本需要
box_ind参数(旧版本),补充该参数。例如,添加与box数量匹配的索引数组:box_ind = tf.range(tf.shape(boxes)[0]) reframe_box_masks_to_image_masks(box_masks, box_ind, boxes, image_height, image_width)
- 如果API版本没有
方法二:锁定兼容的版本组合
确保TensorFlow与Object Detection API版本严格匹配:
- 若使用TensorFlow 2.8.0,安装对应版本的Object Detection API:
pip install tensorflow-object-detection-api==2.8.0 - 若使用TensorFlow 2.14.0,安装最新兼容版本的API:
pip install tensorflow-object-detection-api==2.14.0
额外验证
确认你的预标注框格式正确:
- 框坐标需为**归一化的[y_min, x_min, y_max, x_max]**格式
- 确保
boxes变量是二维numpy数组或TensorFlow张量,维度为(N, 4),N是框的数量
内容的提问来源于stack exchange,提问作者AnonX
相关产品推荐
相关产品推荐

