CANN/ge Shape类API文档

发布时间:2026/10/24 14:38:40
CANN/ge Shape类API文档 Shape【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/geProduct Support Status| Product | Support Status | | | :----------- | :------: | | Atlas A3 Training Series Products/Atlas A3 Inference Series Products | √ | | Atlas A2 Training Series Products/Atlas A2 Inference Series Products | √ |Module Importfrom ge.graph import ShapeFunctionality DescriptionShape class inherits from Python built-inlist, used to represent tensor shape dimension information. Besides having all operation capabilities of standard lists, it also provides convenient methods for calculating total element count of shape and judging if it is unknown shape. When dims is None, represents scalar (empty list).Shape module also defines the following constants:| Constant Name | Value | Description | | | :----- | :--- | :--- | | UNKNOWN_DIM | -1 | Represents unknown dimension | | UNKNOWN_DIM_NUM | -2 | Represents unknown dimension count | | UNKNOWN_DIM_SIZE | -1 | Return value of get_shape_size() when shape is unknown |Class Definitionclass Shape(list): def __init__(self, dims: Optional[List[int]] None) - NoneFunction List| Function | Functionality Description | | | :--- | :--- | | __init__(dimsNone) | Constructor, creates Shape object. dims is integer list, None represents scalar (empty list) | | get_shape_size() | Calculates product of all dimensions in shape, i.e., total element count of tensor | | is_unknown_shape() | Judges if shape contains unknown dimensions |Parameter Description__init__ Parameter| Parameter | Type | Required | Description | | | :----- | :--- | :------: | :--- | | dims | List[int] | No | Dimension value list, e.g., [1, 3, 224, 224]. None represents scalar (empty list). Default value is None |Return Value Description| Function | Return Type | Description | | | :--- | :--- | :--- | | get_shape_size() | int | Product of all dimensions. Returns 0 when shape is empty (scalar); returns -1 when shape contains unknown dimension (UNKNOWN_DIM or UNKNOWN_DIM_NUM) | | is_unknown_shape() | bool | Returns True if shape contains UNKNOWN_DIM (-1) or UNKNOWN_DIM_NUM (-2); otherwise returns False |Constraint Descriptiondims parameter must be integer list (list of int) or None, otherwise throws TypeError.Shape inherits from list, therefore supports all standard list operations (indexing, slicing, iteration, len etc.).When shape contains unknown dimension, get_shape_size() returns -1, rather than throwing exception.Usage Examplefrom ge.graph import Shape # Create Shape object shape Shape([1, 3, 224, 224]) # Get total element count print(shape.get_shape_size()) # 150528 # Judge if it is unknown shape print(shape.is_unknown_shape()) # False # Create Shape containing unknown dimension 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 # Supports list operations print(shape[0]) # 1 print(len(shape)) # 4 print(list(shape)) # [1, 3, 224, 224]【免费下载链接】geGEGraph Engine是面向昇腾的图编译器和执行器提供了计算图优化、多流并行、内存复用和模型下沉等技术手段加速模型执行效率减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询