【问题标题】:Tensorflow: Accessing instance method of a python objectTensorflow:访问python对象的实例方法
【发布时间】:2018-02-24 22:44:51
【问题描述】:

使用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') 这样的东西不起作用,因为它不存在于其目录中。但是,打印标签说有对应于“分布”的数组。有什么想法吗?

【问题讨论】:

    标签: python tensorflow python-object


    【解决方案1】:

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

    【讨论】:

    • 谢谢,@丹尼尔。是的,这是一本字典,我更新了我的问题。现在,我可以将其中的名称作为列表获取。但是,我希望看到它们的值将它们的名称传递给“分布”,例如:&gt;&gt;&gt; pprint(event_acc.Tags()['distributions'][2]) u'MobilenetV1/Conv2d_4_depthwise/BatchNorm/moving_mean_1',我现在如何查看'MobilenetV1/Conv2d_4_depthwise/BatchNorm/moving_mean_1' 的权重?
    猜你喜欢
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-23
    相关资源
    最近更新 更多