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_letterbox([0.0, 0.0, 1.0, 0.75]);
decode_semantic(&logits, &config, &mut class_map, None, &options)?;Structs§
- Semantic
Config - Static description of a semantic output, usually built from the model’s
edgefirst.jsonbySemanticConfig::from_logical. - Semantic
Layout - Axis positions of a semantic output in its tensor shape.
- Semantic
Options - Runtime options of one semantic decode.
Enums§
- Semantic
Input - What a semantic output holds.
Functions§
- decode_
semantic - Decodes a semantic output into
dst, an[H, W]class map of dtypeu8(up to 256 classes) oru16(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.