恢复预训练模型的Tensorflow检查点文件

时间:2017-09-08 00:52:49

标签: python tensorflow tensorboard

我已从MobileNet检查点文件下载了预训练的TF-Slim模型,我正在尝试查看与图层关联的权重。

举个例子,我有三个文件:

67903136 Jun 14 00:15 mobilenet_v1_1.0_224.ckpt.data-00000-of-00001
19954 Jun 14 00:15 mobilenet_v1_1.0_224.ckpt.index
4319476 Jun 14 00:15 mobilenet_v1_1.0_224.ckpt.meta

第一种方法:

我直接使用tensorboard

tensorboard --logdir=${CHKPNT_DIR}

它在本地运行(http://127.0.0.1:6006/),但没有显示任何内容:

No dashboards are active for the current data set.
Probable causes:

You haven’t written any data to your event files.
TensorBoard can’t find your event files.

第二种方法:

我使用后端方法Event_Accumulator

import tensorflow as tf
from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
event_acc = EventAccumulator('${CHKPNT_DIR}')
event_acc.Reload()

# Show all tags in the log file
print(event_acc.Tags())

有趣的是,所有标签都是空的:

{'scalars': [], 'histograms': [], 'meta_graph': False, 'images': [], 'graph': False, 'audio': [], 'distributions': [], 'tensors': [], 'run_metadata': []}

所以这是dir

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

然后,我们如何看待已预先训练好的网络?这些检查点文件必须包含某种Google Protobuf数据。

在Mac OS 10.12.4上运行TF 1.3.0。

1 个答案:

答案 0 :(得分:0)

saver = tf.train.import_meta_graph("path/your/meta/file")
saver.restore("path/to/data/file")

graph = tf.get_default_graph()
writer = tf.summary.FileWriter("path/to/write/graph")
writer.add_graph(graph)

然后

tensorboard --logdir="path/to/write/graph"