Tensorflow:访问python对象的实例方法

2024-05-16 22:53:59 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Tensorflow 1.3我可以访问Event_acumulator,它将重新加载保存的事件:

>>> dir(event_acc)
['Audio', 'CompressedHistograms', 'FirstEventTimestamp', 'Graph', 'Histograms', 'Images', 'MetaGraph', 'PluginAssets', 'PluginTagToContent', 'Reload', 'RetrievePluginAsset', 'RunMetadata', 'Scalars', 'SummaryMetadata', 'Tags', 'Tensors', '_CheckForOutOfOrderStepAndMaybePurge', '_CheckForRestartAndMaybePurge', '_CompressHistogram', '_ConvertHistogramProtoToTuple', '_MaybePurgeOrphanedData', '_ProcessAudio', '_ProcessEvent', '_ProcessHistogram', '_ProcessImage', '_ProcessScalar', '_ProcessTensor', '_Purge', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_compression_bps', '_first_event_timestamp', '_generator', '_generator_mutex', '_graph', '_graph_from_metagraph', '_meta_graph', '_plugin_to_tag_to_content', '_tagged_metadata', '_tensor_summaries', 'accumulated_attrs', 'audios', 'compressed_histograms', 'file_version', 'histograms', 'images', 'most_recent_step', 'most_recent_wall_time', 'path', 'purge_orphaned_data', 'scalars', 'summary_metadata', 'tensors']

对于冻结模型示例,它具有以下标记:

>>> type(event_acc.Tags)
<type 'instancemethod'>

>>>type(event_acc.Tags())
<type 'dict'>

>>> dir(event_acc.Tags())
['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values', 'viewitems', 'viewkeys', 'viewvalues']

打印它将带来:

>>> pprint(event_acc.Tags())
{'audio': [],
 'distributions': [u'MobilenetV1/Conv2d_5_depthwise/BatchNorm/moving_variance_1',
                   u'activations/Conv2d_4_depthwise',
                   u'MobilenetV1/Conv2d_4_depthwise/BatchNorm/moving_mean_1',
                   u'activations/Conv2d_8_depthwise',
...
 'graph': True,
 'histograms': [u'MobilenetV1/Conv2d_5_depthwise/BatchNorm/moving_variance_1',
                u'activations/Conv2d_4_depthwise',
                u'MobilenetV1/Conv2d_4_depthwise/BatchNorm/moving_mean_1',
                u'activations/Conv2d_8_depthwise',
                u'MobilenetV1/Conv2d_2_depthwise/BatchNorm/moving_mean_1',
...
 'images': [u'distort_image/cropped_resized_image/image/0',
            u'distort_image/images_with_distorted_bounding_box/image/0',
            u'distort_image/final_distorted_image/image/0',
            u'distort_image/image_with_bounding_boxes/image/0'],
 'meta_graph': True,
 'run_metadata': [],
 'scalars': [u'sparsity/Conv2d_13_pointwise',
             u'sparsity/Conv2d_6_depthwise',
...
            u'sparsity/Conv2d_11_depthwise',
             u'global_step/sec'],
 'tensors': []}

我似乎没有找到一种方法来打印标签中'distributions'数组中特定变量的值。例如:像这样的Tags.Distribution('X')不起作用,因为它不存在于它的dir中。然而,打印标签表示有与“分布”相对应的数组。你知道吗?你知道吗


Tags: imageeventreducetypedirtagsgraphacc
1条回答
网友
1楼 · 发布于 2024-05-16 22:53:59

您没有在event_acc.Tags()上调用type,这会很有用。不过,考虑到打印输出和方法列表,它可能只是返回一个普通的字典。所以你可以简单地做event_acc.Tags()['distributions']。你知道吗

相关问题 更多 >