MindInsight张量可视设计介绍
MindInsight張量可視設(shè)計(jì)介紹
特性背景
張量可視,能夠幫助用戶直觀查看訓(xùn)練過程中的Tensor值,既支持以直方圖的形式呈現(xiàn)Tensor的變化趨勢,也支持查看某次step的具體Tensor值。Tensor包括權(quán)重值、梯度值、激活值等。
總體設(shè)計(jì)
Tensor可視主要是解析由MindSpore的TensorSummary算子記錄的Tensor數(shù)據(jù)生成的Summary文件,并把結(jié)果返回給前端展示。
MindInsight解析時(shí),會(huì)遵循proto文件(Google Protocol Buffer,是一種高效便捷的結(jié)構(gòu)化數(shù)據(jù)存儲(chǔ)方式)來解析Tensor數(shù)據(jù),然后把數(shù)據(jù)緩存起來,在前端查詢特定數(shù)據(jù)時(shí)將其返回供前端展示。
Tensor可視支持1-N維的Tensor以表格或直方圖的形式展示,對(duì)于0維的Tensor,需要通過ScalarSummary來記錄并在標(biāo)量可視中展示。
在表格視圖中,可以查詢當(dāng)前緩存中特定step的Tensor數(shù)據(jù),后臺(tái)通過切片操作,使得用戶單次可以查詢?nèi)我?-2維的Tensor數(shù)據(jù)。
在直方圖視圖中,可以查詢當(dāng)前緩存中所有step的直方圖數(shù)據(jù)。
后端設(shè)計(jì)
張量可視相關(guān)的類主要有TensorContainer、Histogram以及TensorProcessor類,其中TensorContainer用于保存Tensor的具體值、維度、數(shù)據(jù)類型、最大值、最小值、直方圖等信息,這里的直方圖引用了Histogram的數(shù)據(jù)。Histogram用于處理直方圖相關(guān)的信息,包括保存桶個(gè)數(shù),歸一化緩存中所有step的直方圖數(shù)據(jù)等。TensorProcessor用于處理與Tensor相關(guān)的HTTP請(qǐng)求,包括獲取當(dāng)前緩存中特定訓(xùn)練作業(yè),特定tag有多少個(gè)step,每個(gè)step的Tensor統(tǒng)計(jì)信息,特定step的特定維度的Tensor數(shù)據(jù)(單次支持查詢最多某兩維的數(shù)據(jù))以及特定tag的直方圖數(shù)據(jù)。
前端設(shè)計(jì)
圖1:表格展示
圖1將用戶所記錄的張量以表格的形式展示,包含以下功能:
? 表格中白色方框顯示當(dāng)前展示的是哪個(gè)維度下的張量數(shù)據(jù),其中冒號(hào):表示當(dāng)前維度索引范圍,和Python索引含義基本一致,不指定具體索引表示當(dāng)前維度所有值,2:5表示索引2到5(不包括5)的值,可以在方框輸入對(duì)應(yīng)的索引或者含有:的索引范圍來查詢特定維度的張量數(shù)據(jù)。
? 拖拽表格下方的空心圓圈可以查詢特定步驟的張量數(shù)據(jù)。
圖2:直方圖展示
圖2將用戶所記錄的張量以直方圖的形式進(jìn)行展示。
接口設(shè)計(jì)
在張量可視中,主要有文件接口和RESTful API接口,其中文件接口為summary.proto文件,是MindInsight和MindSpore進(jìn)行數(shù)據(jù)對(duì)接的接口。 RESTful API接口是MindInsight前后端進(jìn)行數(shù)據(jù)交互的接口,是內(nèi)部接口。
文件接口設(shè)計(jì)
summary.proto文件為總?cè)肟?#xff0c;其中張量的數(shù)據(jù)(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文件中。
總結(jié)
以上是生活随笔為你收集整理的MindInsight张量可视设计介绍的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MindInsight计算图可视设计
- 下一篇: MindSpore静态图语法支持