@@ -289,6 +289,7 @@ std::unique_ptr<ResultBase> ClassificationModel::postprocess(InferenceResult& in
289
289
auto saliency_map_iter = infResult.outputsData .find (saliency_map_name);
290
290
if (saliency_map_iter != infResult.outputsData .end ()) {
291
291
cls_res->saliency_map = std::move (saliency_map_iter->second );
292
+ cls_res->saliency_map = reorder_saliency_maps (cls_res->saliency_map );
292
293
}
293
294
auto feature_vector_iter = infResult.outputsData .find (feature_vector_name);
294
295
if (feature_vector_iter != infResult.outputsData .end ()) {
@@ -384,6 +385,27 @@ std::unique_ptr<ResultBase> ClassificationModel::get_hierarchical_predictions(In
384
385
return retVal;
385
386
}
386
387
388
+ ov::Tensor ClassificationModel::reorder_saliency_maps (const ov::Tensor& source_maps) {
389
+ if (!hierarchical || source_maps.get_shape ().size () == 1 ) {
390
+ return source_maps;
391
+ }
392
+
393
+ auto reordered_maps = ov::Tensor (source_maps.get_element_type (), source_maps.get_shape ());
394
+ const std::uint8_t * source_maps_ptr = static_cast <std::uint8_t *>(source_maps.data ());
395
+ std::uint8_t * reordered_maps_ptr = static_cast <std::uint8_t *>(reordered_maps.data ());
396
+
397
+ size_t shape_offset = (source_maps.get_shape ().size () == 4 ) ? 1 : 0 ;
398
+ size_t map_byte_size = source_maps.get_element_type ().size () *
399
+ source_maps.get_shape ()[shape_offset + 1 ] * source_maps.get_shape ()[shape_offset + 2 ];
400
+
401
+ for (size_t i = 0 ; i < source_maps.get_shape ()[shape_offset]; ++i) {
402
+ size_t new_index = hierarchical_info.label_to_idx [hierarchical_info.logit_idx_to_label [i]];
403
+ std::copy_n (source_maps_ptr + i*map_byte_size, map_byte_size, reordered_maps_ptr + new_index * map_byte_size);
404
+ }
405
+
406
+ return reordered_maps;
407
+ }
408
+
387
409
std::unique_ptr<ResultBase> ClassificationModel::get_multiclass_predictions (InferenceResult& infResult, bool add_raw_scores) {
388
410
const ov::Tensor& indicesTensor = infResult.outputsData .find (indices_name)->second ;
389
411
const int * indicesPtr = indicesTensor.data <int >();
@@ -516,6 +538,17 @@ HierarchicalConfig::HierarchicalConfig(const std::string& json_repr) {
516
538
for (const auto & range_descr : tmp_head_idx_to_logits_range) {
517
539
head_idx_to_logits_range[stoi (range_descr.first )] = range_descr.second ;
518
540
}
541
+
542
+ size_t logits_processed = 0 ;
543
+ for (size_t i = 0 ; i < num_multiclass_heads; ++i) {
544
+ const auto & logits_range = head_idx_to_logits_range[i];
545
+ for (size_t k = logits_range.first ; k < logits_range.second ; ++k) {
546
+ logit_idx_to_label[logits_processed++] = all_groups[i][k - logits_range.first ];
547
+ }
548
+ }
549
+ for (size_t i = 0 ; i < num_multilabel_heads; ++i) {
550
+ logit_idx_to_label[logits_processed++] = all_groups[num_multiclass_heads + i][0 ];
551
+ }
519
552
}
520
553
521
554
GreedyLabelsResolver::GreedyLabelsResolver (const HierarchicalConfig& config) :
0 commit comments