Tensorflow: Accessing instance method of a python object

76 views Asked by At

Using Tensorflow 1.3 I can access Event_acumulator which reloads the saved events:

>>> 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']

It has the following tags for a sample frozen model:

>>> 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']

Printing it will bring this:

>>> 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': []}

I don't seem to find a way to print the value of a specific variable in 'distributions' arrays inside the tags. E.g.: something like this Tags.Distribution('X') doesn't work as it does not exist in its dir. However, printing Tags says that there are arrays corresponding to `'distributions'. Any idea?

1

There are 1 answers

1
Daniel Roseman On

You didn't call type on event_acc.Tags(), which would have been useful. Presumably, though, given that print output and the list of methods it seems to be just returning a normal dictionary. So you can simply do event_acc.Tags()['distributions'].