如何查看TensorFlow会话的默认配置选项?

时间:2017-02-21 23:15:23

标签: python tensorflow

如何查看TensorFlow session的默认配置选项?

我知道在初始化会话时我可以通过config参数传递配置选项,例如:

# Launch the graph in a session that allows soft device placement and
# logs the placement decisions.
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True,
                                        log_device_placement=True))

但我不知道如何查看默认配置选项。 tensorflow/core/protobuf/config.proto看起来不像默认选项。

2 个答案:

答案 0 :(得分:0)

来自

的Tensorflow 1.0.0
pip install tensorflow-gpu

我跑了:

import tensorflow as tf
import pprint
p = tf.ConfigProto()
pprint.pprint({ k:str(getattr(p,k)) for k in sorted(dir(p)) if not k.startswith('_')})

产生

{'ALLOW_SOFT_PLACEMENT_FIELD_NUMBER': '7',
 'ByteSize': '<bound method ConfigProto.ByteSize of >',
 'Clear': '<bound method ConfigProto._Clear of >',
 'ClearExtension': '<bound method ConfigProto.ClearExtension of >',
 'ClearField': '<bound method ConfigProto.ClearField of >',
 'CopyFrom': '<bound method ConfigProto.CopyFrom of >',
 'DESCRIPTOR': '<google.protobuf.descriptor.Descriptor object at 0x113dbf4d0>',
 'DEVICE_COUNT_FIELD_NUMBER': '1',
 'DEVICE_FILTERS_FIELD_NUMBER': '4',
 'DeviceCountEntry': "<class 'tensorflow.core.protobuf.config_pb2.DeviceCountEntry'>",
 'DiscardUnknownFields': '<bound method ConfigProto._DiscardUnknownFields of >',
 'FindInitializationErrors': '<bound method ConfigProto.FindInitializationErrors of >',
 'FromString': '<function FromString at 0x113de2578>',
 'GPU_OPTIONS_FIELD_NUMBER': '6',
 'GRAPH_OPTIONS_FIELD_NUMBER': '10',
 'HasExtension': '<bound method ConfigProto.HasExtension of >',
 'HasField': '<bound method ConfigProto.HasField of >',
 'INTER_OP_PARALLELISM_THREADS_FIELD_NUMBER': '5',
 'INTRA_OP_PARALLELISM_THREADS_FIELD_NUMBER': '2',
 'IsInitialized': '<bound method ConfigProto.IsInitialized of >',
 'LOG_DEVICE_PLACEMENT_FIELD_NUMBER': '8',
 'ListFields': '<bound method ConfigProto.ListFields of >',
 'MergeFrom': '<bound method ConfigProto.MergeFrom of >',
 'MergeFromString': '<bound method ConfigProto.MergeFromString of >',
 'OPERATION_TIMEOUT_IN_MS_FIELD_NUMBER': '11',
 'PLACEMENT_PERIOD_FIELD_NUMBER': '3',
 'ParseFromString': '<bound method ConfigProto.ParseFromString of >',
 'RPC_OPTIONS_FIELD_NUMBER': '13',
 'RegisterExtension': '<function RegisterExtension at 0x113de2500>',
 'SESSION_INTER_OP_THREAD_POOL_FIELD_NUMBER': '12',
 'SerializePartialToString': '<bound method ConfigProto.SerializePartialToString of >',
 'SerializeToString': '<bound method ConfigProto.SerializeToString of >',
 'SetInParent': '<bound method ConfigProto.Modified of >',
 'USE_PER_SESSION_THREADS_FIELD_NUMBER': '9',
 'WhichOneof': '<bound method ConfigProto.WhichOneof of >',
 'allow_soft_placement': 'False',
 'device_count': '{}',
 'device_filters': '[]',
 'gpu_options': '',
 'graph_options': '',
 'inter_op_parallelism_threads': '0',
 'intra_op_parallelism_threads': '0',
 'log_device_placement': 'False',
 'operation_timeout_in_ms': '0',
 'placement_period': '0',
 'rpc_options': '',
 'session_inter_op_thread_pool': '[]',
 'use_per_session_threads': 'False'}

答案 1 :(得分:-1)

这相当于protobufs的默认值问题:https://developers.google.com/protocol-buffers/docs/proto#optional

默认值是特定于类型的。通常0表示数字字段,False表示布尔值,空表示重复字段等。