std1.0.0-beta-7 SafeC docs

std :: ml::cnn

Struct std::FeatureMap

#include <std/ml/cnn.h> source

struct FeatureMap {
    &heap float data;
    unsigned long channels;
    unsigned long height;
    unsigned long width;
    int fromArena;
}

Fields

§&heap float datasource

flat, channelsheightwidth, CHW order (data[cHW + h*W + w])

§unsigned long channelssource
§unsigned long heightsource
§unsigned long widthsource
§int fromArenasource

1 if data came from a TensorArena (FeatureMap::free leaves it)

Methods

§void drop()source · definition
§void free() consumesource · definition

= drop()

§static struct FeatureMap new( unsigned long channels, unsigned long height, unsigned long width, )source · definition

Between TensorArena::begin and tensor_arena_end (std/ml/tensor.h), new feature maps -- the ones these functions return, and every layer's intermediate inside UNet::forward and the like -- come from the thread's TensorArena, as tensors do: no malloc (or page faults, for fresh memory) per layer. FeatureMap::free does nothing for them; TensorArena::reset releases them all, so don't use one after its arena is reset.

§struct FeatureMap maxpool2d(unsigned long kernel, unsigned long stride) constsource · definition

Max/avg pooling: kernel x kernel window, given stride, no padding. Channel count is preserved; caller must choose dimensions divisible by the kernel/stride combination.

§struct FeatureMap avgpool2d(unsigned long kernel, unsigned long stride) constsource · definition
§struct FeatureMap maxpool2d_ex( unsigned long kernel, unsigned long stride, unsigned long padding, ) constsource · definition

The same with 'padding' on every side; output side (dim + 2*padding - kernel)/stride + 1. Max pooling ignores the padded positions (as PyTorch's MaxPool2d does); avg pooling counts them as zeros in the divisor when 'countIncludePad' (PyTorch's AvgPool2d default) and divides by the positions inside the plane otherwise.

§struct FeatureMap avgpool2d_ex( unsigned long kernel, unsigned long stride, unsigned long padding, int countIncludePad, ) constsource · definition
§struct FeatureMap global_avgpool2d() constsource · definition

Global pooling over each channel's whole plane: channels x 1 x 1 (the classifier head of ResNet-style networks).

§struct FeatureMap global_maxpool2d() constsource · definition
§struct FeatureMap upsample2x_nearest() constsource · definition

Nearest-neighbor 2x spatial upsample: out[c][2h+dh][2w+dw] = in[c][h][w] for dh,dw in {0,1}. Used by U-Net's decoder path (see unet.h) in place of a learned transposed convolution.