API接口提供了一个强大的工具来获取模型推理的统计数据。通过简单的GET请求,可以获取包括推理次数、错误次数、平均置信度和平均响应时间等关键指标。这些数据对于监控模型性能和优化资源分配至关重要。
要使用这个API接口,需要传递三个可选的查询参数:startTime、endTime和modelNames。startTime和endTime参数接受格式为"YYYY-MM-DD HH:mm:ss"的日期时间字符串,分别表示统计数据的开始和结束时间。如果这两个参数为空,startTime将默认为请求时间之前的24小时,endTime将默认为请求的当前时间。modelNames参数接受一个由逗号分隔的模型名称字符串,允许指定想要获取统计数据的模型。
下面是一个使用curl命令行工具发起GET请求的示例。需要将<your_api_key>替换为实际API密钥。
                    curl --location --request GET 'https://api.roboflow.com/${WORKSPACE}/inference-stats?api_key=&startTime=&endTime='
                 
如果请求成功,将收到一个包含统计数据的JSON响应。这个响应包含了总体统计数据和每个模型的详细统计数据。总体统计数据包括推理次数、错误次数、平均置信度和平均响应时间等。每个模型的详细统计数据包括模型名称、预测类别、推理次数、错误次数、平均置信度、平均响应时间等。
例如,以下是一个示例响应:
                    {
                        "num_inferences": 120,
                        "prev_num_inferences": 290,
                        "num_errors": 0,
                        "prev_num_errors": 0,
                        "avg_confidence": 0.92541713388321,
                        "prev_avg_confidence": 0.8610920182589827,
                        "avg_response_time": 0.16464362986438943,
                        "prev_avg_response_time": 0.043521592255159045,
                        "inference_stats": [
                            {
                                "model_name": "cards-3z9gn",
                                "predicted_class": "Playingcards",
                                "num_inferences": 106,
                                "prev_num_inferences": 190,
                                "num_errors": null,
                                "prev_num_errors": null,
                                "avg_confidence": 0.931105958703923,
                                "prev_avg_confidence": 0.935741652940449,
                                "avg_response_time": 0.176652773857811,
                                "prev_avg_response_time": 0.05487422056841488,
                                "median_confidence": 0.9268901944160461,
                                "class_count": 211,
                                "deployment_types": "hosted",
                                "inference_server_versions": "0.15.3,0.16.0",
                                "model_num_inferences": 107,
                                "prev_model_num_inferences": 190
                            },
                            // 其他模型的统计数据...
                        ]
                    }