尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

CANN/ge Shape类API文档

CANN/ge Shape类API文档
📅 发布时间:2026/7/4 7:17:26

Shape

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

Product 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 Import

from ge.graph import Shape

Functionality Description

Shape 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 Definition

class Shape(list): def __init__(self, dims: Optional[List[int]] = None) -> None

Function List

| Function | Functionality Description | | | :--- | :--- | | __init__(dims=None) | 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 Description

  • dims 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 Example

from 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]

【免费下载链接】geGE(Graph Engine)是面向昇腾的图编译器和执行器,提供了计算图优化、多流并行、内存复用和模型下沉等技术手段,加速模型执行效率,减少模型内存占用。 GE 提供对 PyTorch、TensorFlow 前端的友好接入能力,并同时支持 onnx、pb 等主流模型格式的解析与编译。项目地址: https://gitcode.com/cann/ge

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

相关新闻

  • Elm-platform安全指南:确保Elm应用安全性的最佳实践
  • Gradle Docker插件与微服务架构:多模块项目的最佳实践指南
  • jinjava高级技巧:自定义标签、过滤器和函数的终极指南

最新新闻

  • CANN/asc-devkit Conv3DBackpropInput GetTiling函数
  • CANN/GE DFlow API MetaContext类
  • Leaps API开发入门:将实时协作功能集成到你自己的应用中的实用指南
  • 升势动能主图之红钻选股指标公式
  • 深入理解tools.cli的核心功能:parse-opts函数全方位解析
  • RestFB性能优化技巧:如何高效管理Facebook API调用

日新闻

  • STM32F745VG与MC6470 IMU的高性能姿态控制系统设计
  • 机器不消费,人何以生存
  • AI项目操作手册编写规范与最佳实践

周新闻

  • Windows字体自定义终极方案:No!! MeiryoUI完全指南
  • Deepin Boot Maker:告别命令行,3分钟制作Linux启动盘的智能解决方案
  • Plain Craft Launcher 2:重新定义你的Minecraft游戏体验

月新闻

  • 2026年6月公司网站搭建最新热门渠道测评:四大低成本/零代码平台对比+避坑
  • 【Linux】Linux arm 编译QT程序,出现expected “}“报错
  • 【MATLAB例程】四基站二维AOA定位与距离辅助增强对比仿真。基于角度观测和测距修正的固定目标平面定位精度分析

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号