CANN/ge TensorDesc张量描述API文档

📅 2026/7/4 21:29:35
CANN/ge TensorDesc张量描述API文档
TensorDesc【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/geProduct SupportProductSupportAtlas A3 Training Products/Atlas A3 Inference Products√Atlas A2 Training Products/Atlas A2 Inference Products√Module Importfrom ge.graph import TensorDescFunctionality DescriptionTensorDesc class describes tensor metadata, including Shape, Format and DataType. Supports distinguishing between original shape/format and current shape/format, suitable for complete description of tensor attributes during graph building. Allset_*methods returnself, supporting chained calls. Does not support copy and deepcopy.Class Definitionclass TensorDesc: def __init__( self, shape: Optional[List[int]] None, format: Optional[Format] Format.FORMAT_ND, data_type: Optional[DataType] DataType.DT_FLOAT, ) - NoneFunction ListFunctionDescription__init__(shapeNone, formatFormat.FORMAT_ND, data_typeDataType.DT_FLOAT)Constructor, creates TensorDesc object. shape is dimension list, None indicates scalar; format is data format, default FORMAT_ND; data_type is data type, default DT_FLOATshape (property)Get current shape as property, returns Shape objectorigin_shape (property)Get original shape as property, returns Shape objectformat (property)Get current data format as property, returns Format enum valueorigin_format (property)Get original data format as property, returns Format enum valuedata_type (property)Get data type as property, returns DataType enum valueget_shape()Get current shapeset_shape(shape)Set current shape, supports chained callsget_origin_shape()Get original shapeset_origin_shape(shape)Set original shape, supports chained callsget_format()Get current data formatset_format(format)Set current data format, supports chained callsget_origin_format()Get original data formatset_origin_format(format)Set original data format, supports chained callsget_data_type()Get data typeset_data_type(data_type)Set data type, supports chained callsParameter Description__init__ ParametersParameterTypeRequiredDescriptionshapeList[int]NoTensors dimension list, e.g. [1, 3, 224, 224]. None indicates scalar (empty list). Default is NoneformatFormatNoTensors data format, takes Format enum value. Default is Format.FORMAT_NDdata_typeDataTypeNoTensors element data type, takes DataType enum value. Default is DataType.DT_FLOATset_shape / set_origin_shape ParametersParameterTypeRequiredDescriptionshapeList[int]YesTarget dimension list, must be integer listset_format / set_origin_format ParametersParameterTypeRequiredDescriptionformatFormatYesTarget data format, must be Format enum valueset_data_type ParametersParameterTypeRequiredDescriptiondata_typeDataTypeYesTarget data type, must be DataType enum valueReturn Value DescriptionFunctionReturn TypeDescriptionshape (property)ShapeCurrent shape objectorigin_shape (property)ShapeOriginal shape objectformat (property)FormatCurrent data format enum valueorigin_format (property)FormatOriginal data format enum valuedata_type (property)DataTypeData type enum valueget_shape()ShapeCurrent shape objectset_shape(shape)TensorDescReturns self, supports chained callsget_origin_shape()ShapeOriginal shape objectset_origin_shape(shape)TensorDescReturns self, supports chained callsget_format()FormatCurrent data format enum valueset_format(format)TensorDescReturns self, supports chained callsget_origin_format()FormatOriginal data format enum valueset_origin_format(format)TensorDescReturns self, supports chained callsget_data_type()DataTypeData type enum valueset_data_type(data_type)TensorDescReturns self, supports chained callsConstraintsDoes not support copy: callingcopy.copy()will throw RuntimeError.Does not support deepcopy: callingcopy.deepcopy()will throw RuntimeError.In constructor, format parameter must be Format enum type, otherwise throws TypeError.In constructor, data_type parameter must be DataType enum type, otherwise throws TypeError.For set_shape, set_origin_shape, shape parameter must be integer list (list of int), otherwise throws TypeError.For set_format, set_origin_format, format parameter must be Format enum type, otherwise throws TypeError.For set_data_type, data_type parameter must be DataType enum type, otherwise throws TypeError.If underlying C API call fails, methods will throw RuntimeError.Usage Examplefrom ge.graph import TensorDesc, Shape, Format, DataType # Create TensorDesc object desc TensorDesc(shape[1, 3, 224, 224], formatFormat.FORMAT_NCHW, data_typeDataType.DT_FLOAT) # Get tensor info via properties print(desc.shape) # [1, 3, 224, 224] print(desc.format) # Format.FORMAT_NCHW print(desc.data_type) # DataType.DT_FLOAT # Get tensor info via methods shape desc.get_shape() fmt desc.get_format() dtype desc.get_data_type() # Chain call to set properties desc.set_shape([2, 3]).set_data_type(DataType.DT_INT32).set_format(Format.FORMAT_ND)【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考