当前位置: 首页 > news >正文

CANN/ge Shape类API文档

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),仅供参考

http://www.jsqmd.com/news/1120229/

相关文章:

  • Elm-platform安全指南:确保Elm应用安全性的最佳实践
  • Statsig Status Page故障排查:常见问题与解决方案
  • Selenium Web自动化入门到实战:从环境搭建到框架设计
  • Instatic数据获取实战:从TypeBox验证到useAsyncResource的完整指南
  • 终极指南:如何使用Gradle Docker插件实现与Kubernetes的无缝集成
  • jinjava高级技巧:自定义标签、过滤器和函数的终极指南
  • Trae使用详细教程—从入门到精通(附带图文)
  • Spirit Web Player高级技巧:掌握timeline控制的10个实用方法
  • Genome在Linux环境下的部署与使用:跨平台Swift开发的秘诀
  • CANN/mat-chem-sim-pred IPDT批量闭环评分
  • PoseDiffusion实战应用:如何使用自定义数据集进行姿态估计的完整指南
  • CANN/asc-devkit Conv3DBackpropFilter Tiling使用说明
  • Laravel Vonage Notification Channel源码解析:短信发送的实现原理与流程
  • CANN/mat-chem-sim-pred FOPDT批量闭环评分API
  • 如何免费下载E-Hentai漫画档案:E-Hentai-Downloader完整使用指南 [特殊字符]
  • Gradle Docker插件版本管理:如何处理镜像标签和版本冲突的完整指南
  • ANSI转义序列实战:从终端色彩到动态界面
  • 如何用VisProg解决四大视觉任务?GQA/NLVR/图像编辑/目标标记实战教程
  • SENet-Tensorflow数据预处理详解:CIFAR-10数据集加载与增强技巧
  • jqjq REPL使用指南:交互式JSON查询与处理的终极技巧
  • 文本嵌入实战指南:TF-IDF、word2vec与BERT选型避坑手册
  • 昇腾AI处理器GlobalTensor形状获取
  • CANN/GE自定义算子开发指南
  • CANN/cannbot-skills:环境快照
  • Obsidian-zola社区指南:如何贡献代码和参与开发
  • AI 图标生成入库:漂亮图标还要过语义和网格检查
  • Packtpub-crawler通知系统详解:邮件、IFTTT、Pushover多平台提醒设置指南
  • CANN/asc-devkit SIMD数据加载API
  • CANN/Ascend C Conv3D Tiling构造函数
  • MCPJungle与Context7集成教程:获取开源库文档从未如此简单