// Protocol buffer for configuring DELF feature extraction.

syntax = "proto2";

package delf.protos;

message DelfPcaParameters {
  // Path to PCA mean file.
  optional string mean_path = 1; // Required.

  // Path to PCA matrix file.
  optional string projection_matrix_path = 2; // Required.

  // Dimensionality of feature after PCA.
  optional int32 pca_dim = 3; // Required.

  // If whitening is to be used, this must be set to true.
  optional bool use_whitening = 4 [default = false];

  // Path to PCA variances file, used for whitening. This is used only if
  // use_whitening is set to true.
  optional string pca_variances_path = 5;
}

message DelfLocalFeatureConfig {
  // If PCA is to be used, this must be set to true.
  optional bool use_pca = 1 [default = true];

  // Target layer name for DELF model. This is used to obtain receptive field
  // parameters used for localizing features with respect to the input image.
  optional string layer_name = 2 [default = ""];

  // Intersection over union threshold for the non-max suppression (NMS)
  // operation. If two features overlap by at most this amount, both are kept.
  // Otherwise, the one with largest attention score is kept. This should be a
  // number between 0.0 (no region is selected) and 1.0 (all regions are
  // selected and NMS is not performed).
  optional float iou_threshold = 3 [default = 1.0];

  // Maximum number of features that will be selected. The features with largest
  // scores (eg, largest attention score if score_type is "Att") are the
  // selected ones.
  optional int32 max_feature_num = 4 [default = 1000];

  // Threshold to be used for feature selection: no feature with score lower
  // than this number will be selected).
  optional float score_threshold = 5 [default = 100.0];

  // PCA parameters for DELF local feature. This is used only if use_pca is
  // true.
  optional DelfPcaParameters pca_parameters = 6;
}

message DelfConfig {
  // Path to DELF model.
  optional string model_path = 1; // Required.

  // Image scales to be used.
  repeated float image_scales = 2;

  // Configuration used for DELF local features.
  optional DelfLocalFeatureConfig delf_local_config = 3;

  // The maximum/minimum image size (in terms of height or width) to be used
  // when extracting DELF features. If the height *OR* width is larger than
  // max_image_size, it will be resized to max_image_size, and the other
  // dimension will be resized by preserving the aspect ratio. Similar logic
  // applies to min_image_size, if both height *AND* width are smaller than
  // min_image_size, the larger side is set to min_image_size. If set to -1
  // (default), no image resizing is performed on the corresponding criteria.
  // When using local features, note that the feature locations and scales will
  // be consistent with the original image input size.
  // Note that when both options are specified (which is a valid and legit use
  // case), as long as max_image_size >= min_image_size, there's no conflicting
  // scenario (i.e. never triggers both enlarging / shrinking).
  // Bilinear interpolation is used.
  optional int32 max_image_size = 4 [default = -1];
  optional int32 min_image_size = 5 [default = -1];
}
