尝试使用最近发布的Tensorflow Object Detection API,并想知道如何评估他们在模型动物园中提供的预训练模型之一?恩。如何获得该预训练模型的mAP值?
由于他们提供的script似乎使用了检查点(根据他们的documentation),我尝试制作一个指向提供的model.ckpt.data-00000-of-00001
模型的检查点的哑副本在他们的模型动物园,但eval.py不喜欢这样。
checkpoint
model_checkpoint_path: "model.ckpt.data-00000-of-00001"
我已经考虑过对训练前的训练,然后评估......但我不确定这是否会给我正确的指标。
对不起,如果这是一个基本问题 - 我刚开始使用Tensorflow,并想验证我得到了正确的东西。非常感谢任何指针!
修改
我根据Jonathan的回答制作了一个检查点文件:
model_checkpoint_path: "model.ckpt"
all_model_checkpoint_paths: "model.ckpt"
评估脚本采用的,并使用COCO数据集进行评估。然而,评估停止并说有一个形状不匹配:
...
[[Node: save/Assign_19 = Assign[T=DT_FLOAT, _class=["loc:@BoxPredictor_4/ClassPredictor/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/gpu:0"](BoxPredictor_4/ClassPredictor/weights, save/RestoreV2_19/_15)]]
2017-07-05 18:40:11.969641: W tensorflow/core/framework/op_kernel.cc:1158] Invalid argument: Assign requires shapes of both tensors to match. lhs shape= [1,1,256,486] rhs shape= [1,1,256,546]
[[Node: save/Assign_19 = Assign[T=DT_FLOAT, _class=["loc:@BoxPredictor_4/ClassPredictor/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/gpu:0"](BoxPredictor_4/ClassPredictor/weights, save/RestoreV2_19/_15)]]
2017-07-05 18:40:11.969725: W tensorflow/core/framework/op_kernel.cc:1158]
...
Invalid argument: Assign requires shapes of both tensors to match. lhs shape= [1,1,256,486] rhs shape= [1,1,256,546]
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [1,1,256,486] rhs shape= [1,1,256,546]
可能导致这种形状不匹配的原因是什么?我该如何解决?
答案 0 :(得分:4)
您可以通过运行eval.py脚本来评估预训练模型。它会要求您指向一个配置文件(位于samples/configs
目录中)和一个检查点,为此您将提供.../.../model.ckpt
形式的路径(删除任何扩展名,如{ {1}}或.meta
)。
您还必须在包含您要评估的检查点的目录中创建名为“checkpoint”的文件。然后在该文件中写下以下两行:
model_checkpoint_path:“path / to / model.ckpt”
all_model_checkpoint_paths:“path / to / model.ckpt”
(在哪里修改路径/到/适当)
最后得到的数字是使用50%IOU作为真阳性的截止阈值的平均精确度。这与模型动物园中报告的度量略有不同,后者使用COCO mAP度量标准并对多个IOU值进行平均。
答案 1 :(得分:1)
您还可以使用 model_main.py 评估模型。
如果要根据验证数据评估模型,则应使用:
python models/research/object_detection/model_main.py --pipeline_config_path=/path/to/pipeline_file --model_dir=/path/to/output_results --checkpoint_dir=/path/to/directory_holding_checkpoint --run_once=True
如果要根据训练数据评估模型,则应将“ eval_training_data”设置为True,即:
python models/research/object_detection/model_main.py --pipeline_config_path=/path/to/pipeline_file --model_dir=/path/to/output_results --eval_training_data=True --checkpoint_dir=/path/to/directory_holding_checkpoint --run_once=True
我还添加了注释以阐明一些先前的选项:
-pipeline_config_path:用于训练检测模型的“ pipeline.config”文件的路径。此文件应包含您要评估的TFRecords文件(训练和测试文件)的路径,即:
...
train_input_reader: {
tf_record_input_reader {
#path to the training TFRecord
input_path: "/path/to/train.record"
}
#path to the label map
label_map_path: "/path/to/label_map.pbtxt"
}
...
eval_input_reader: {
tf_record_input_reader {
#path to the testing TFRecord
input_path: "/path/to/test.record"
}
#path to the label map
label_map_path: "/path/to/label_map.pbtxt"
}
...
-model_dir :将在其中写入生成的度量标准的输出目录,尤其是可由tensorboard读取的“ events。*”文件。
-checkpoint_dir :具有检查点的目录。这是模型目录,在训练过程中或使用“ export_inference_graph.py”将其导出后,已在其中写入检查点文件(“ model.ckpt。*”)。对于您的情况,您应该指向从https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md下载的预训练模型文件夹。
-run_once :真,仅运行一次评估。
答案 2 :(得分:0)
尝试:
python eval.py --logtostderr --checkpoint_dir=training --eval_dir=path/to/eval_dir --pipeline_config_path=path/to/pretrained_model.config
例如:
python eval.py --logtostderr --checkpoint_dir=training --eval_dir=images/val \
--pipelineline_config_path=training/faster_rcnn_inception_v2.config
注意:
培训目录包含您所有的培训检查点。在训练期间,Tensorflow会在该目录内生成一个检查点文件,其中包含所有检查点元数据,因此您无需创建另一个文件。如果要在生成推理图后评估训练有素的自定义模型,请确保将用于训练的.config中的原始pretrained_model / model.chpt更改为new_trained_model / model.ckpt。您应该得到类似的输出:
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.457
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.729
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.502
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.122
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.297
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.659
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.398
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.559
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.590
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.236
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.486
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.746
INFO:tensorflow:Writing metrics to tf summary.
INFO:tensorflow:DetectionBoxes_Precision/mAP: 0.456758
INFO:tensorflow:DetectionBoxes_Precision/mAP (large): 0.659280
INFO:tensorflow:DetectionBoxes_Precision/mAP (medium): 0.296693
INFO:tensorflow:DetectionBoxes_Precision/mAP (small): 0.122108
INFO:tensorflow:DetectionBoxes_Precision/mAP@.50IOU: 0.728587
INFO:tensorflow:DetectionBoxes_Precision/mAP@.75IOU: 0.502194
INFO:tensorflow:DetectionBoxes_Recall/AR@1: 0.397509
INFO:tensorflow:DetectionBoxes_Recall/AR@10: 0.558966
INFO:tensorflow:DetectionBoxes_Recall/AR@100: 0.590182
INFO:tensorflow:DetectionBoxes_Recall/AR@100 (large): 0.745691
INFO:tensorflow:DetectionBoxes_Recall/AR@100 (medium): 0.485964
INFO:tensorflow:DetectionBoxes_Recall/AR@100 (small): 0.236275
INFO:tensorflow:Losses/Loss/BoxClassifierLoss/classification_loss: 0.234645
INFO:tensorflow:Losses/Loss/BoxClassifierLoss/localization_loss: 0.139109
INFO:tensorflow:Losses/Loss/RPNLoss/localization_loss: 0.603733
INFO:tensorflow:Losses/Loss/RPNLoss/objectness_loss: 0.206419