Useful tool for functions, neural networks, or callable objects outputs dimensions checking. It allows fast testing and relies on pattern string for easy use.
DimChecker().test_dims(nn, "bcl->bn(2*c+1)l", n=16)A pattern is defined as two formulas separated by an arrow:
pattern = "bcl -> b(2*c)l"
DimChecker().test_dims(nn, pattern)On the left side of the arrow we have the inputs formula and the outputs formula on the right.
in_formula = "bcl"
out_formula = "b(2*c)l"
pattern = in_formula + "->" + out_formula
DimChecker().test_dims(nn, pattern)Dimensions are defined by a single letter. Here a common machine learning input tensor of shape
formula = "bcl"For 2D images of shape
formula = "bchw"To use several inputs or outputs we only need to separate them by commas:
# several inputs
pattern = "bcl, bl -> bcl"
# several outputs
pattern = "bcl -> bcl, bl"
# several inputs or outputs
pattern = "bcl, bc ->bcl, bl"
DimChecker().test_dims(nn, pattern)