from keras_frcnn import metrics as metrics_fn ImportError: cannot import name 'metrics' from 'keras_frcnn' (D:\程序\Keras-Faster-RCNN-master-master\keras_frcnn\__init__.py)
时间: 2024-03-10 12:51:21 浏览: 116
这个错误可能是由于`keras_frcnn`包中没有`metrics`模块导致的。为此,你可以尝试使用`keras_frcnn.metrics`代替`from keras_frcnn import metrics as metrics_fn`,并修改`class_acc`和`mean_overlapping_bboxes`为`keras_frcnn.metrics.class_acc`和`keras_frcnn.metrics.mean_overlapping_bboxes`。修改后的代码如下:
```
from keras.models import Model
from keras_frcnn import config, data_generators
from keras_frcnn import losses as losses_fn
from keras_frcnn import metrics
from keras.models import load_model
# 加载模型配置
config_output_filename = "config.pickle"
with open(config_output_filename, "rb") as f_in:
C = pickle.load(f_in)
# 创建数据生成器
test_imgs, _, _ = data_generators.get_data(
C,
C.test_path,
mode='test'
)
test_gen = data_generators.get_anchor_gt(
test_imgs,
C,
mode='test'
)
# 加载模型
model_path = "model_frcnn.hdf5"
model = load_model(model_path, custom_objects={
"rpn_loss_cls": losses_fn.rpn_loss_cls,
"rpn_loss_regr": losses_fn.rpn_loss_regr,
"class_loss_cls": losses_fn.class_loss_cls,
"class_loss_regr": losses_fn.class_loss_regr,
"class_acc": metrics.class_acc,
"mean_overlapping_bboxes": metrics.mean_overlapping_bboxes
})
# 评估模型性能
X, Y, image_data, debug_img, debug_num_pos = next(test_gen)
result = model.evaluate(X, Y)
# 打印性能指标
print("Losses: ", result)
print("Classification accuracy: ", result[1])
print("Classification loss: ", result[2])
print("Regression loss: ", result[3])
```
如果还有其他问题,请告诉我。
阅读全文