Using torch and numpy a lot I find myself perplexed about the shape of some torch.Tensors, particularly if they have a non-obvious set of dimensions (e.g a batch dimension or something). I reach for this one-liner pretty regularly so perhaps it can be of use to others:)
print(f"\nArray Shapes:\n{'':=>50}"); [print(f"{k:<20}: {str(type(v).__name__):<7}:", tuple(v.shape)) for k, v in locals().items() if hasattr(v, "shape") and not hasattr(getattr(v, "shape", None), "__call__")] # Exclude the 'numpy' import, the `shape` func. isn't relevant
(semi-golfed to be able to easily run in a `breakpoint()`)
1 comment
[ 3.3 ms ] story [ 8.1 ms ] threadHere's an example output:
And the code: (semi-golfed to be able to easily run in a `breakpoint()`)