Neural network

This submodule provides function for neural network.

biom3d.utils.neural_network.convert_num_pools(num_pools: list[int], roll_strides: bool = True) list[list[int]][source]

Generate adaptive pooling stride configurations based on the number of pools per axis.

This utility transforms a list indicating the number of pooling operations along each axis into a stride pattern usable for downsampling layers in convolutional architectures.

Parameters:
  • num_pools (list of int) – List indicating how many pooling steps to apply per axis. For example, [3, 5, 5] means: - axis 0 will be pooled 3 times, - axis 1 and 2 will be pooled 5 times each.

  • roll_strides (bool, default=True) – If True, zero-padding is symmetrically centered (rolled), otherwise zeros are left-aligned.

Returns:

strides – A 2D list of shape (max(num_pools), len(num_pools)) representing stride values. Each inner list corresponds to the stride per axis at a given depth. Strides are either 1 (no pooling) or 2 (pooling).

Return type:

list of list of int

Examples

>>> convert_num_pools([3, 5, 5])
[[1, 2, 2],
 [2, 2, 2],
 [2, 2, 2],
 [2, 2, 2],
 [1, 2, 2]]