Skip to main content

Module semantic

Module semantic 

Source
Expand description

Semantic segmentation decoding.

Turns a per-pixel score map ([C, h, w] in any axis order) or a class map the model already computed into an [H, W] class map at any resolution, written into a caller-supplied tensor. Each output pixel is mapped through the letterbox geometry of the model input, so the padding is cropped and the class map covers the original image.

Two decode modes are available (DecodeMode):

  • Accurate upsamples the scores of every class, then takes the argmax. Pixels whose low-resolution neighbours agree on the winner skip the per-class interpolation, which is exact because bilinear interpolation is a convex combination.
  • Fast takes the argmax at the score map’s resolution, then upsamples the class map with nearest-neighbour sampling.

Single-channel outputs are thresholded instead of argmaxed: foreground is class 1 and background class 0.

§Examples

use edgefirst_decoder::semantic::{decode_semantic, SemanticConfig, SemanticLayout, SemanticOptions};
use edgefirst_decoder::schema::DecodeMode;
use edgefirst_tensor::{DType, TensorDyn, TensorMemory};

let config = SemanticConfig::scores(&[1, 150, 128, 168], 1, 2, 3)?;
let mut class_map = TensorDyn::new(&[480, 640], DType::U8, Some(TensorMemory::Mem), None)?;
let options = SemanticOptions::new()
    .with_mode(DecodeMode::Fast)
    .with_content_region([0.0, 0.0, 1.0, 0.75]);
decode_semantic(&logits, &config, &mut class_map, None, &options)?;

Structs§

SemanticConfig
Static description of a semantic output, usually built from the model’s edgefirst.json by SemanticConfig::from_logical.
SemanticLayout
Axis positions of a semantic output in its tensor shape.
SemanticOptions
Runtime options of one semantic decode.

Enums§

SemanticInput
What a semantic output holds.

Functions§

decode_semantic
Decodes a semantic output into dst, an [H, W] class map of dtype u8 (up to 256 classes) or u16 (up to 65 536).
select_output
Picks the tensor of a semantic output from a model’s outputs: the one named like the output, else the only one with its shape, else the one at the output’s position when every model output was passed.