Overview
The Shape class is used to represent tensor shapes.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | from ge.graph import Shape # Create a shape object. shape = Shape([1, 3, 224, 224]) # Obtain the total number of elements. print(shape.get_shape_size()) # 150528 # Check whether the shape is unknown. print(shape.is_unknown_shape()) # False # Create a shape that contains unknown dimensions. unknown_shape = Shape([-1, 3, 224, 224]) print(unknown_shape.is_unknown_shape()) # True print(unknown_shape.get_shape_size()) # -1 # Scalar shape (empty list) scalar = Shape() print(len(scalar)) # 0 print(scalar.get_shape_size()) # 0 # Support list operations. print(shape[0]) # 1 print(len(shape)) # 4 print(list(shape)) # [1, 3, 224, 224] |
Parent topic: Shape