计算图结构
- MetaGraphDef(计算图)
- MetaInfoDef(运算方法)
- OpList(运算方法集合)
- OpDef(运算方法)
- ArgDef(输入,输出)
- AttrDef(属性)
- OpDef(运算方法)
- OpList(运算方法集合)
- GraphDef (连接结构)
- NodeDef(节点)
- SaverDef (模型持久化)
- CheckpointFormatVersion(模型定义使用的版本)
- map<string, CollectionDef> (集合)
- NodeList(节点value)
- BytesList(序列化value)
- map<string, SignatureDef>(签名)
- AssetFileDef (权重值)
- MetaInfoDef(运算方法)
MetaInfoDef
记录计算图中所有是使用到的运算方法
message MetaInfoDef {
// 用户指定的版本字符串 可以是模型和修订的名称,
// 此模型已经过训练的步骤等。
string meta_graph_version = 1;
// 此graph_def的生产者使用的(运算方法)OpDefs的副本。
// 一个运算方法在这里只能出项一次。
// 删除了graph_def中未使用的描述和操作。
OpList stripped_op_list = 2;
// 序列化的protobuf。 可以是创建或修改此元图的时间,也可以是模型的名称。
google.protobuf.Any any_info = 3;
// 用户在meta_graph上提供了标签,并包含了graph_def。
// MetaGraphDefs应标记其功能或用例。
// 例子:“train”,“serve”,“gpu”,“tpu”等。
// 这些标签使加载程序能够访问适合于特定用例或运行时环境的MetaGraph。
repeated string tags = 4;
// 由框架指定
string tensorflow_version = 5;
// 由框架指定
string tensorflow_git_version = 6;
// 一个标志,表示是否已从此graph_def中的节点中删除了默认值的attrs。
bool stripped_default_attrs = 7;
}
OpList
定义运算集合
一个OpDefs的集合,集合意味着没有重复的
message OpList {
repeated OpDef op = 1;
};
OpDef
定义运算结构的具体实现
message OpDef {
string name = 1;
// 可重复的ArgDef结构的输入
repeated ArgDef input_arg = 2;
// 可重复的ArgDef结构的输出
repeated ArgDef output_arg = 3;
// 记录上面输入,输出中tyep_attr属性的具体意义
repeated AttrDef attr = 4;
// 可以根据计算图的版本选择使用使用
OpDeprecation deprecation = 8;
// 对此运算方法OP做的一行可读的描述。
string summary = 5;
// 更加具体的op描述解释
string description = 6;
// 该操作可以参与哪些优化,以下都时标识是否可以进行某一种优化
// op是否可以互换进行,比如 ("op(a,b) == op(b,a)" for all inputs)
bool is_commutative = 18;
// 是否能进行赋值
bool is_aggregate = 16; // for things like add
// 是否有状态依赖
bool is_stateful = 17; // for things like variables, queue
// 是否允许不初始化进行
bool allows_uninitialized_input = 19; // for Assign, etc.
};
ArgDef
定义节点输入,输出的结构
message ArgDef {
string name = 1;
// 人类可读的描述。
string description = 2;
// 描述input/output的一个或多个张量的类型
DataType type = 3;
string type_attr = 4; // if specified, attr must have type "type"
string number_attr = 5; // if specified, attr must have type "int"
string type_list_attr = 6;
bool is_ref = 16;
};
AttrDef
定义属性结构的具体实现
message AttrDef {
string name = 1;
string type = 2;
AttrValue default_value = 3;
string description = 4;
bool has_minimum = 5;
int64 minimum = 6;
AttrValue allowed_values = 7;
}
OpDeprecation
定义弃用结构的具体实现
message OpDeprecation {
// 第一个GRODDEF版本,其中OP是不允许的。
int32 version = 1;
// 解释为什么它被弃用,而用什么来代替。
string explanation = 2;
};
案例
下面以Add运算为例子, 这个运算有2给输入和1给输出,输入和输出属性都指定了属性type_attr, 并且这个属性的值为T。在OpDef中,必须要出现name,为T的属性。
op{
name:"Add"
input_arg {
name:"x"
type_attr:"T"
}
input_arg {
name:"y"
type_attr:"T"
}
output_arg {
name:"z"
tpye_attr:"T"
}
attr {
name:"T"
type:"type"
allowed_values {
list {
type:DT_HALF
type:DT_FLOAF
}
}
}
}