Skip to content

Commit

Permalink
AC: update yolact adapter for model with embedded decoder (openvinoto…
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova authored Oct 20, 2020
1 parent 2f69416 commit d20e1b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
5 changes: 3 additions & 2 deletions tools/accuracy_checker/accuracy_checker/adapters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ AccuracyChecker supports following set of adapters:
* `texts_out` - name of output layer with texts.
* `confidence_threshold` - confidence threshold that is used to filter out detected instances.
* `yolact` - converting raw outputs of Yolact model to to combination of `DetectionPrediction` and `CoCocInstanceSegmentationPrediction`.
* `loc_out` - name of output layer which contains box locations.
* `prior_out` - name of output layer which contains prior boxes.
* `loc_out` - name of output layer which contains box locations, optional if boxes decoding embedded into model.
* `prior_out` - name of output layer which contains prior boxes, optional if boxes decoding embedded into model.
* `boxes_out` - name of output layer which contains decoded output boxes, optional if model has `prior` a `loc` outputs for boxes decoding.
* `conf_out` - name of output layer which contains confidence scores for all classes for each box.
* `mask_out` - name of output layer which contains instance masks.
* `proto_out` - name of output layer which contains proto for masks calculation.
Expand Down
30 changes: 22 additions & 8 deletions tools/accuracy_checker/accuracy_checker/adapters/yolact.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import cv2
import numpy as np

from ..config import StringField, NumberField
from ..config import StringField, NumberField, ConfigError
from ..postprocessor import NMS
from ..representation import DetectionPrediction, CoCocInstanceSegmentationPrediction, ContainerPrediction
from ..utils import UnsupportedPackage
Expand All @@ -35,9 +35,10 @@ class YolactAdapter(Adapter):
def parameters(cls):
params = super().parameters()
params.update({
'loc_out': StringField(description='name of output with box locations'),
'boxes_out': StringField(description='name of output with decoded boxes', optional=True),
'loc_out': StringField(description='name of output with box locations', optional=True),
'conf_out': StringField(description='name of output with confidence scores'),
'prior_out': StringField(description='name of output with prior boxes'),
'prior_out': StringField(description='name of output with prior boxes', optional=True),
'mask_out': StringField(description='name of output with masks'),
'proto_out': StringField(description='name of output with proto for masks calculation'),
'confidence_threshold': NumberField(
Expand All @@ -56,21 +57,25 @@ def configure(self):
self.loc_out = self.get_value_from_config('loc_out')
self.conf_out = self.get_value_from_config('conf_out')
self.prior_out = self.get_value_from_config('prior_out')
self.boxes_out = self.get_value_from_config('boxes_out')
self.mask_out = self.get_value_from_config('mask_out')
self.proto_out = self.get_value_from_config('proto_out')
self.conf_thresh = self.get_value_from_config('confidence_threshold')
self.max_num_detections = self.get_value_from_config('max_detections')
if not self.loc_out and not self.prior_out and not self.boxes_out:
raise ConfigError('loc_out and prior_out or boxes_out should be provided')
if not self.boxes_out and not (self.prior_out and self.loc_out):
raise ConfigError('both loc_out and prior_out should be provided')

def process(self, raw, identifiers, frame_meta):
raw_outputs = self._extract_predictions(raw, frame_meta)
prior_boxes = raw_outputs[self.prior_out]
result = []
for identifier, locs, conf, masks, proto, meta in zip(
identifiers, raw_outputs[self.loc_out], raw_outputs[self.conf_out],
for batch_id, (identifier, conf, masks, proto, meta) in enumerate(zip(
identifiers, raw_outputs[self.conf_out],
raw_outputs[self.mask_out], raw_outputs[self.proto_out], frame_meta
):
)):
h, w, _ = meta['image_size']
boxes = self.decode_boxes(locs, prior_boxes)
boxes = self.get_boxes(batch_id, raw_outputs)
conf = np.transpose(conf)
cur_scores = conf[1:, :]
conf_scores = np.max(cur_scores, axis=0)
Expand Down Expand Up @@ -179,6 +184,15 @@ def decode_boxes(loc, priors):

return boxes

def get_boxes(self, batch_id, raw_outputs):
if self.boxes_out:
boxes = raw_outputs[self.boxes_out][batch_id]
else:
prior_boxes = raw_outputs[self.prior_out]
locs = raw_outputs[self.loc_out][batch_id]
boxes = self.decode_boxes(locs, prior_boxes)
return boxes

@staticmethod
def mask_proto_mask_activation(masks):
return 1 / (1 + np.exp(-masks))
Expand Down

0 comments on commit d20e1b4

Please sign in to comment.