
class AdviceProtoclass GraphNodeProtoclass MultiGraphNodeProtoclass OpLogProtoclass ProfileOptionBuilder: 用于分析API的选项生成器。class Profiler: TensorFlow多步骤的分析器。advise(...): 自动配置和建议。profile(...): 概要文件的模型。write_op_log(...): Log提供了'op_log',并在下面添加了额外的模型信息。__init____init__(**kwargs)checkers
repeated CheckersEntry checkers
ByteSizeByteSize()4、ClearClear()5、ClearFieldClearField(field_name)6、DiscardUnknownFieldsDiscardUnknownFields()7、FindInitializationErrorsFindInitializationErrors()查找未初始化的必需字段。
返回值:
8、FromString@staticmethod
FromString(s)9、HasFieldHasField(field_name)10、IsInitializedIsInitialized(errors=None)检查是否设置了消息的所有必需字段。
参数:
errors:如果提供了一个列表,它将填充所有缺少的必需字段的字段路径。返回值:
11、ListFieldsListFields()12、MergeFromMergeFrom(msg)13、MergeFromStringMergeFromString(serialized)14、RegisterExtension@staticmethod
RegisterExtension(extension_handle)15、SerializePartialToStringSerializePartialToString(**kwargs)16、SerializeToStringSerializeToString(**kwargs)17、SetInParentSetInParent()将_cached_byte_size_dirty位设置为true,并将其传播给侦听器(如果这是状态更改)。
18、UnknownFieldsUnknownFields()19、WhichOneofWhichOneof(oneof_name)返回其中一个或None中当前设置字段的名称。
20、__eq____eq__(other)1、__init____init__(**kwargs)2、ByteSizeByteSize()3、ClearClear()4、ClearFieldClearField(field_name)5、DiscardUnknownFieldsDiscardUnknownFields()6、FindInitializationErrorsFindInitializationErrors()查找未初始化的必需字段。
返回值:
7、FromString@staticmethod
FromString(s)8、HasFieldHasField(field_name)9、IsInitializedIsInitialized(errors=None)检查是否设置了消息的所有必需字段。
参数:
errors:如果提供了一个列表,它将填充所有缺少的必需字段的字段路径。返回值:
10、ListFieldsListFields()11、MergeFromMergeFrom(msg)12、MergeFromStringMergeFromString(serialized)13、RegisterExtension@staticmethod
RegisterExtension(extension_handle)14、SerializePartialToStringSerializePartialToString(**kwargs)15、SerializeToStringSerializeToString(**kwargs)16、SetInParentSetInParent()将_cached_byte_size_dirty位设置为true,并将其传播给侦听器(如果这是状态更改)。
17、UnknownFieldsUnknownFields()18、WhichOneofWhichOneof(oneof_name)返回其中一个或None中当前设置字段的名称。
19、__eq____eq__(other)1、__init____init__(**kwargs)2、ByteSizeByteSize()3、ClearClear()4、ClearFieldClearField(field_name)5、DiscardUnknownFieldsDiscardUnknownFields()6、FindInitializationErrorsFindInitializationErrors()查找未初始化的必需字段。
返回值:
7、FromString@staticmethod
FromString(s)8、HasFieldHasField(field_name)9、IsInitializedIsInitialized(errors=None)检查是否设置了消息的所有必需字段。
参数:
errors:如果提供了一个列表,它将填充所有缺少的必需字段的字段路径。返回值:
10、ListFieldsListFields()11、MergeFromMergeFrom(msg)12、MergeFromStringMergeFromString(serialized)13、RegisterExtension@staticmethod
RegisterExtension(extension_handle)14、SerializePartialToStringSerializePartialToString(**kwargs)15、SerializeToStringSerializeToString(**kwargs)16、SetInParentSetInParent()将_cached_byte_size_dirty位设置为true,并将其传播给侦听器(如果这是状态更改)。
17、UnknownFieldsUnknownFields()18、WhichOneofWhichOneof(oneof_name)返回其中一个或None中当前设置字段的名称。
19、__eq____eq__(other)自动配置和建议。
tf.profiler.advise(
graph=None,
run_meta=None,
options=_DEFAULT_ADVISE_OPTIONS
)构建概要文件并自动检查各个方面的异常。更多信息:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/README.md
参数:
graph:tf.Graph。如果没有启用None和eager执行,则使用默认图。options:参见上面的ALL_ADVICE示例。默认检查一切。返回值:
__init____init__(**kwargs)2、ByteSizeByteSize()3、ClearClear()4、ClearFieldClearField(field_name)5、DiscardUnknownFieldsDiscardUnknownFields()6、FindInitializationErrorsFindInitializationErrors()查找未初始化的必需字段。
返回值:
7、FromString@staticmethod
FromString(s)8、HasFieldHasField(field_name)9、IsInitializedIsInitialized(errors=None)检查是否设置了消息的所有必需字段。
参数:
返回值:
10、ListFieldsListFields()11、MergeFromMergeFrom(msg)12、MergeFromStringMergeFromString(serialized)13、RegisterExtension@staticmethod
RegisterExtension(extension_handle)14、SerializePartialToStringSerializePartialToString(**kwargs)15、SerializeToStringSerializeToString(**kwargs)16、SetInParentSetInParent()将_cached_byte_size_dirty位设置为true,并将其传播给侦听器(如果这是状态更改)。
17、UnknownFieldsUnknownFields()18、WhichOneofWhichOneof(oneof_name)返回其中一个或None中当前设置字段的名称。
19、__eq____eq__(other)1、__init____init__(**kwargs)2、ByteSizeByteSize()3、ClearClear()4、ClearFieldClearField(field_name)5、DiscardUnknownFieldsDiscardUnknownFields()6、FindInitializationErrorsFindInitializationErrors()查找未初始化的必需字段。
返回值:
7、FromString@staticmethod
FromString(s)8、HasFieldHasField(field_name)9、IsInitializedIsInitialized(errors=None)检查是否设置了消息的所有必需字段。
参数:
返回:
10、ListFieldsListFields()11、MergeFromMergeFrom(msg)12、MergeFromStringMergeFromString(serialized)13、RegisterExtension@staticmethod
RegisterExtension(extension_handle)14、SerializePartialToStringSerializePartialToString(**kwargs)15、SerializeToStringSerializeToString(**kwargs)16、SetInParentSetInParent()将_cached_byte_size_dirty位设置为true,并将其传播给侦听器(如果这是状态更改)。
17、UnknownFieldsUnknownFields()18、WhichOneofWhichOneof(oneof_name)返回其中一个或None中当前设置字段的名称。
19、__eq____eq__(other)1、__init____init__(**kwargs)2、ByteSizeByteSize()3、ClearClear()4、ClearFieldClearField(field_name)5、DiscardUnknownFieldsDiscardUnknownFields()6、FindInitializationErrorsFindInitializationErrors()查找未初始化的必需字段。
返回值:
7、FromString@staticmethod
FromString(s)8、HasFieldHasField(field_name)9、IsInitializedIsInitialized(errors=None)检查是否设置了消息的所有必需字段。
参数:
返回值:
10、ListFieldsListFields()11、MergeFromMergeFrom(msg)12、MergeFromStringMergeFromString(serialized)13、RegisterExtension@staticmethod
RegisterExtension(extension_handle)14、SerializePartialToStringSerializePartialToString(**kwargs)15、SerializeToStringSerializeToString(**kwargs)16、SetInParentSetInParent()将_cached_byte_size_dirty位设置为true,并将其传播给侦听器(如果这是状态更改)。
17、UnknownFieldsUnknownFields()18、WhichOneofWhichOneof(oneof_name)返回其中一个或None中当前设置字段的名称。
19、__eq____eq__(other)1、__init____init__(**kwargs)2、ByteSizeByteSize()3、ClearClear()4、ClearFieldClearField(field_name)5、DiscardUnknownFieldsDiscardUnknownFields()6、FindInitializationErrorsFindInitializationErrors()查找未初始化的必需字段。
返回值:
7、FromString@staticmethod
FromString(s)8、HasFieldHasField(field_name)9、IsInitializedIsInitialized(errors=None)检查是否设置了消息的所有必需字段。
参数:
返回值:
10、ListFieldsListFields()11、MergeFromMergeFrom(msg)12、MergeFromStringMergeFromString(serialized)13、RegisterExtension@staticmethod
RegisterExtension(extension_handle)14、SerializePartialToStringSerializePartialToString(**kwargs)15、SerializeToStringSerializeToString(**kwargs)16、SetInParentSetInParent()将_cached_byte_size_dirty位设置为true,并将其传播给侦听器(如果这是状态更改)。
17、UnknownFieldsUnknownFields()18、WhichOneofWhichOneof(oneof_name)返回其中一个或None中当前设置字段的名称。
19、__eq____eq__(other)1、__init____init__(**kwargs)ByteSizeByteSize()3、ClearClear()4、ClearFieldClearField(field_name)5、DiscardUnknownFieldsDiscardUnknownFields()6、FindInitializationErrorsFindInitializationErrors()查找未初始化的必需字段。
返回值:
7、FromString@staticmethod
FromString(s)8、HasFieldHasField(field_name)9、IsInitializedIsInitialized(errors=None)检查是否设置了消息的所有必需字段。
参数:
返回值:
10、ListFieldsListFields()11、MergeFromMergeFrom(msg)12、MergeFromStringMergeFromString(serialized)13、RegisterExtension@staticmethod
RegisterExtension(extension_handle)14、SerializePartialToStringSerializePartialToString(**kwargs)15、SerializeToStringSerializeToString(**kwargs)16、SetInParentSetInParent()将_cached_byte_size_dirty位设置为true,并将其传播给侦听器(如果这是状态更改)。
17、UnknownFieldsUnknownFields()18、WhichOneofWhichOneof(oneof_name)返回其中一个或None中当前设置字段的名称。
19、__eq____eq__(other)概要文件的模型。
tf.profiler.profile(
graph=None,
run_meta=None,
op_log=None,
cmd='scope',
options=_DEFAULT_PROFILE_OPTIONS
)教程和示例可以在https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/README.md找到
参数:
graph:tf.Graph。如果没有启用None和eager执行,则使用默认图。options:选项的dict。看到核心/分析器/ g3doc / options.md。返回值:
用于分析API的选项生成器。有关这些选项的教程,请参见https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/g3doc/options.md
# Users can use pre-built options:
opts = (
tf.profiler.ProfileOptionBuilder.trainable_variables_parameter())
# Or, build your own options:
opts = (tf.compat.v1.profiler.ProfileOptionBuilder()
.with_max_depth(10)
.with_min_micros(1000)
.select(['accelerator_micros'])
.with_stdout_output()
.build()
# Or customize the pre-built options:
opts = (tf.compat.v1.profiler.ProfileOptionBuilder(
tf.profiler.ProfileOptionBuilder.time_and_memory())
.with_displaying_options(show_name_regexes=['.*rnn.*'])
.build())
# Finally, profiling with the options:
_ = tf.compat.v1.profiler.profile(tf.compat.v1.get_default_graph(),
run_meta=run_meta,
cmd='scope',
options=opts)1、__init____init__(options=None)构造函数。
参数:
2、account_displayed_op_onlyaccount_displayed_op_only(is_true)是否只计算显示的分析器节点的统计信息。
参数:
返回:
3、buildbuild()构建分析选项。
返回:
4、float_operation@staticmethod
float_operation()用于分析浮动操作的选项。有关浮点运算的注意事项,请参阅https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/g3doc/profile_model_architecture.md。
返回值:
5、order_byorder_by(attribute)根据属性对显示的分析器节点进行排序。支持的属性包括micros、bytes、occurrence、params等https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/g3doc/options.md
参数:
attribute:分析器节点拥有的属性。返回值:
6、selectselect(attributes)选择要显示的属性。有关支持的属性,请参见https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/g3doc/options.md。
参数:
返回值:
、time_and_memory@staticmethod
time_and_memory(
min_micros=1,
min_bytes=1,
min_accelerator_micros=0,
min_cpu_micros=0,
min_peak_bytes=0,
min_residual_bytes=0,
min_output_bytes=0
)显示操作时间和内存消耗。
参数:
返回值:
8、trainable_variables_parameter@staticmethod
trainable_variables_parameter()用于分析可训练变量参数的选项。通常与“范围”视图一起使用。
返回值:
9、with_accounted_typeswith_accounted_types(account_type_regexes)根据节点类型有选择地计算统计信息。这里,“types”表示分析器节点的属性。默认情况下,将设备名称(例如/job:xx/…/device:GPU:0)和操作类型(例如MatMul)作为概要节点的属性。用户还可以通过OpLogProto proto将定制的“类型”关联到分析器节点。例如,用户可以使用:account_type_regexes=['.*gpu:0]选择位于gpu:0上的分析器节点。*']如果节点的属性都不匹配指定的regexes,则不显示或计算该节点。
参数:
返回值:
10、with_empty_outputwith_empty_output()不要产生副作用输出。
11、with_file_outputwith_file_output(outfile)将结果打印到文件中。
12、with_max_depthwith_max_depth(max_depth)设置显示的最大深度。深度取决于分析视图。对于“scope”视图,它是名称范围层次结构的深度(树),对于“op”视图,它是操作类型的数量(列表),等等。
参数:
返回值:
13、with_min_execution_timewith_min_execution_time(
min_micros=0,
min_accelerator_micros=0,
min_cpu_micros=0
)只显示使用不少于'min_micros'的分析器节点。
参数:
返回值:
14、with_min_float_operationswith_min_float_operations(min_float_ops)只显示使用不少于“min_float_ops”的分析器节点。有关浮点运算的注意事项,请参阅https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/profiler/g3doc/profile_model_architecture.md。
参数:
返回值:
15、with_min_memorywith_min_memory(
min_bytes=0,
min_peak_bytes=0,
min_residual_bytes=0,
min_output_bytes=0
)只显示使用不少于“min_bytes”的分析器节点。
参数:
返回:
16、with_min_occurrencewith_min_occurrence(min_occurrence)只显示包含不少于“min_occurrence”图形节点的分析器节点。“节点”表示分析器输出节点,它可以是python行(代码视图)、操作类型(op视图)或图节点(图/范围视图)。python行包含由该行创建的所有图形节点,而操作类型包含该类型的所有图形节点。
参数:
返回值:
17、with_min_parameterswith_min_parameters(min_params)只显示包含不少于“min_params”参数的分析器节点。参数通常是指张量流变量的权重。它反映了模型的“能力”。
参数:
返回:
18、with_node_nameswith_node_names(
start_name_regexes=None,
show_name_regexes=None,
hide_name_regexes=None,
trim_name_regexes=None
)用于选择要显示的分析器节点的正则表达式。在'with_accounted_types'被求值后,'with_node_names'被求值如下:对于概要文件数据结构,profiler首先找到匹配'start_name_regexes'的概要文件节点,然后从那里开始显示概要文件节点。然后,如果节点匹配“show_name_regexes”而不匹配“hide_name_regexes”,则显示该节点。如果一个节点匹配“trim_name_regexes”,分析器将停止进一步搜索该分支。
参数:
返回值:
19、with_pprof_outputwith_pprof_output(pprof_file)生成一个pprof概要文件gzip文件。要使用pprof文件:pprof -png——nodecount=100——sample_index=1
参数:
返回值:
20、with_stdout_outputwith_stdout_output()将结果打印到stdout。
21、with_stepwith_step(step)要使用哪个概要文件步骤进行概要分析。这里的“步骤”指的是profile .add_step() API定义的步骤。
参数:
step:当配置文件的多个步骤可用时,选择要使用哪个步骤的配置文件。如果-1,使用所有可用步骤的平均值。返回:
22、with_timeline_outputwith_timeline_output(timeline_file)生成一个时间轴json文件。
TensorFlow多步骤的分析器。
Typical use case:
# Currently we are only allowed to create 1 profiler per process.
profiler = Profiler(sess.graph)
for i in xrange(total_steps):
if i % 10000 == 0:
run_meta = tf.compat.v1.RunMetadata()
_ = sess.run(...,
options=tf.compat.v1.RunOptions(
trace_level=tf.RunOptions.FULL_TRACE),
run_metadata=run_meta)
profiler.add_step(i, run_meta)
# Profile the parameters of your model.
profiler.profile_name_scope(options=(option_builder.ProfileOptionBuilder
.trainable_variables_parameter()))
# Or profile the timing of your model operations.
opts = option_builder.ProfileOptionBuilder.time_and_memory()
profiler.profile_operations(options=opts)
# Or you can generate a timeline:
opts = (option_builder.ProfileOptionBuilder(
option_builder.ProfileOptionBuilder.time_and_memory())
.with_step(i)
.with_timeline_output(filename).build())
profiler.profile_graph(options=opts)
else:
_ = sess.run(...)
# Auto detect problems and generate advice.
profiler.advise()1、__init____init__(
graph=None,
op_log=None
)构造函数。
参数:
graph:tf.Graph。如果没有启用None和eager执行,则使用默认图。2、add_stepadd_step(
step,
run_meta
)添加步骤的统计信息。
参数:
step:int,用于将一个或多个不同的run_meta组合在一起的id。当使用profile_xxx api进行概要分析时,用户可以使用选项中的步骤id对这些run_meta进行概要分析。3、adviseadvise(options)自动检测问题并生成报告。
参数:
options:选项的dict。参见上面的ALL_ADVICE示例。返回值:
4、profile_graphprofile_graph(options)描述由数据流图组织的图节点统计信息。
参数:
options:选项的dict。看到核心/分析器/ g3doc / options.md。返回值:
5、profile_name_scopeprofile_name_scope(options)概述按名称范围组织的图节点的统计信息。
参数:
返回值:
6、profile_operationsprofile_operations(options)分析操作类型的统计信息(例如MatMul、Conv2D)。
参数:
options:选项的dict。看到核心/分析器/ g3doc / options.md。返回值:
7、profile_pythonprofile_python(options)分析Python代码的统计数据。默认情况下,它显示根目录下的调用堆栈。为了避免冗余输出,可以使用以下选项过滤['show_name_regexes'] = ['.my_code.py ']。
参数:
options:选项的dict。看到核心/分析器/ g3doc / options.md。返回值:
8、serialize_to_stringserialize_to_string()将ProfileProto序列化为二进制字符串。用户可以通过tfprof命令行或图形界面将其写入文件进行离线分析。
返回值:
Log提供了'op_log',并在下面添加了额外的模型信息。
tf.profiler.write_op_log(
graph,
log_dir,
op_log=None,
run_meta=None,
add_trace=True
)API还为tf.compat.v1.trainable_variables()中的ops分配了一个名为“_trainable_variables”的op类型。该API还为定义了op.RegisterStatistics()的ops记录“flops”统计信息。flops计算依赖于“graph”中定义的张量形状,这可能不完整。如果提供了'run_meta',则尽最大努力完成形状信息。
参数:
graph:tf.Graph。如果没有启用None和eager执行,则使用默认图。