MindInsight张量可视设计介绍
MindInsight張量可視設計介紹
特性背景
張量可視,能夠幫助用戶直觀查看訓練過程中的Tensor值,既支持以直方圖的形式呈現Tensor的變化趨勢,也支持查看某次step的具體Tensor值。Tensor包括權重值、梯度值、激活值等。
總體設計
Tensor可視主要是解析由MindSpore的TensorSummary算子記錄的Tensor數據生成的Summary文件,并把結果返回給前端展示。
MindInsight解析時,會遵循proto文件(Google Protocol Buffer,是一種高效便捷的結構化數據存儲方式)來解析Tensor數據,然后把數據緩存起來,在前端查詢特定數據時將其返回供前端展示。
Tensor可視支持1-N維的Tensor以表格或直方圖的形式展示,對于0維的Tensor,需要通過ScalarSummary來記錄并在標量可視中展示。
在表格視圖中,可以查詢當前緩存中特定step的Tensor數據,后臺通過切片操作,使得用戶單次可以查詢任意0-2維的Tensor數據。
在直方圖視圖中,可以查詢當前緩存中所有step的直方圖數據。
后端設計
張量可視相關的類主要有TensorContainer、Histogram以及TensorProcessor類,其中TensorContainer用于保存Tensor的具體值、維度、數據類型、最大值、最小值、直方圖等信息,這里的直方圖引用了Histogram的數據。Histogram用于處理直方圖相關的信息,包括保存桶個數,歸一化緩存中所有step的直方圖數據等。TensorProcessor用于處理與Tensor相關的HTTP請求,包括獲取當前緩存中特定訓練作業,特定tag有多少個step,每個step的Tensor統計信息,特定step的特定維度的Tensor數據(單次支持查詢最多某兩維的數據)以及特定tag的直方圖數據。
前端設計
圖1:表格展示
圖1將用戶所記錄的張量以表格的形式展示,包含以下功能:
? 表格中白色方框顯示當前展示的是哪個維度下的張量數據,其中冒號:表示當前維度索引范圍,和Python索引含義基本一致,不指定具體索引表示當前維度所有值,2:5表示索引2到5(不包括5)的值,可以在方框輸入對應的索引或者含有:的索引范圍來查詢特定維度的張量數據。
? 拖拽表格下方的空心圓圈可以查詢特定步驟的張量數據。
圖2:直方圖展示
圖2將用戶所記錄的張量以直方圖的形式進行展示。
接口設計
在張量可視中,主要有文件接口和RESTful API接口,其中文件接口為summary.proto文件,是MindInsight和MindSpore進行數據對接的接口。 RESTful API接口是MindInsight前后端進行數據交互的接口,是內部接口。
文件接口設計
summary.proto文件為總入口,其中張量的數據(TensorProto)存放在Summary的Value中,如下所示:
{
message Summary {
message Image {
// Dimensions of the image.
required int32 height = 1;
required int32 width = 2;
…
}
message Histogram {message bucket{// Counting number of values fallen in [left, left + width).// For the rightmost bucket, the range is [left, left + width].required double left = 1;required double width = 2;required int64 count = 3;}repeated bucket buckets = 1;...}message Value {// Tag name for the data.required string tag = 1;// Value associated with the tag.oneof value {float scalar_value = 3;Image image = 4;TensorProto tensor = 8;Histogram histogram = 9;}}// Set of values for the summary.
repeated Value value = 1;
}
而TensorProto的定義在anf_ir.proto文件中。
總結
以上是生活随笔為你收集整理的MindInsight张量可视设计介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MindInsight计算图可视设计
- 下一篇: MindSpore静态图语法支持