diff --git a/tools/accuracy_checker/accuracy_checker/adapters/README.md b/tools/accuracy_checker/accuracy_checker/adapters/README.md index 26b40d1df9..d7eae48755 100644 --- a/tools/accuracy_checker/accuracy_checker/adapters/README.md +++ b/tools/accuracy_checker/accuracy_checker/adapters/README.md @@ -43,6 +43,7 @@ AccuracyChecker supports following set of adapters: * `joining_method` - method used to join embeddings (optional, supported methods are `sum` and `concatenation`, default - `sum`). * `target_out` - target output layer name (Optional, if not provided first in the model will be used). * `keep_shape` - allow keeping initial shape for predicted embedding (Optional, default `False`, it means that model output will be flattenized). + * `mean_pooling` - average the embeddings of all tokens from last_hidden_state (Optional, default `False`) * `yolo_v2` - converting output of YOLO v2 family models to `DetectionPrediction` representation. * `classes` - number of detection classes (default 20). * `anchors` - anchor values provided as comma-separated list or one of precomputed: diff --git a/tools/accuracy_checker/accuracy_checker/adapters/reidentification.py b/tools/accuracy_checker/accuracy_checker/adapters/reidentification.py index e2c4618c45..dea6a59799 100644 --- a/tools/accuracy_checker/accuracy_checker/adapters/reidentification.py +++ b/tools/accuracy_checker/accuracy_checker/adapters/reidentification.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2018-2024 Intel Corporation +Copyright (c) 2018-2025 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -41,7 +41,9 @@ def parameters(cls): choices=['sum', 'concatenation'] ), 'target_out': StringField(optional=True, description='Target output layer name'), - 'keep_shape': BoolField(optional=True, default=False, description='keep output embedding shape') + 'keep_shape': BoolField(optional=True, default=False, description='keep output embedding shape'), + 'mean_pooling': BoolField(optional=True, default=False, + description='Average the embeddings of all tokens for last_hidden_state') }) return parameters @@ -54,6 +56,7 @@ def configure(self): self.joining_method = self.get_value_from_config('joining_method') self.target_out = self.get_value_from_config('target_out') self.keep_shape = self.get_value_from_config('keep_shape') + self.mean_pooling = self.get_value_from_config('mean_pooling') def process(self, raw, identifiers, frame_meta): """ @@ -67,6 +70,10 @@ def process(self, raw, identifiers, frame_meta): raw_prediction = self._extract_predictions(raw, frame_meta) prediction = raw_prediction[self.output_blob] + if self.mean_pooling: + # Shape: (1, 128, 768) -> (1, 768) + prediction = np.mean(prediction, axis=1) + if self.grn_workaround: # workaround: GRN layer prediction = self._grn_layer(prediction)