Skip to content

Method to add original competition metrics

Atsushi Fukuda edited this page Mar 18, 2020 · 5 revisions

Method to add original competition metrics

Still WIP

Class diagram

Class diagram related to the definition of competition metrics is as follows.

image

How to add original metrics

Define metrics_type at Competition model

Define the value of original metrics_type at Competition model You can define arbitrary name which exhibits the meaning of your metrics.

Define service class

In order to add original competition metrics, developer should define service class called by MetricServiceFactoryClass

Naming rule of service class

The name of service class should be <metrics_type> + Service.
First Character of <metrics_type> should be uppercase and the second and subsequent characters should be lowercase.

For example, in case metric type is auc, Service class name become AucService.
In case of mAP, Service class name become MapService.

Implement interface of service class

Each service class should own common interface methods because it is called from various controllers or models via MetricServiceFactoryClass

To implement the actual content of these interface, it is recommended for developer to create original service class by copying he default service class (such as AUC or mAP).

Interface definition of service class

Common methods which should be defined at each service class is as follows

  • request_data(answer_json, prediction_json)
    • method to create the request data sent to API server for metrics calculation.
    • This method is called at here
  • metric_keys()
    • Method to define keys to retrieve metric values from returned JSON from Flask API server.
    • The keys defined at this method should be also defined at JSON data returned from API server.
    • For example, in case of mAP metrics type, metric_keys()returns %w[mAP allAP allAR](code). And the corresponding JSON values at Flask API is defined like this. There are the same keys as metric_keys() in return value dictionary.
  • metric_for_sota()
    • Method to define a key of metrics to determine ranking of prediction result.
    • This method is called at here.
    • If a new record can achieve highest score according to metrics defined by this key, slack notification is sent to the arbitrary channel specified at SLACK_WEBHOOK_URL environment variable.
  • unique_key
    • Define the unique key to judge whether the records between submitted predictions and answer data are matched.
    • This method is called at here
  • prediction_json_schema
    • Define the JSON shema of prediction result submitted by user.
    • According to this definition, JSON format of submitted result is validated.
  • answer_json_schema
    • Define the JSON schema of answer data of each competition.
    • According to this definition, JSON format of answer data is validated.

API endpoint definition

  • Endpoint(URI) to calculate in API Server should be defined at Flask API Server
  • The endpoint of default metrics is defined at here

Naming rule of API endpoint

  • Name of API endpoint should be /metrics/<metrics_type>
  • For example, in case metrics_type is mAP, the name of API endpoint become /metrics/mAP