5

I am working through a Tensorflow blog to create a CNN.

Its a great article but it does use the following code to save and restore the vocab file to the file system:

vocab_processor.save(vocab)
vocab_processor = learn.preprocessing.VocabularyProcessor.restore(vocab))

I have been extending the example to use the SaveModel approach to produce a saved_model.pd and this is working OK. As the next step I would like to save and restore the vocab file as an asset.

The save action is working well and I can see the vocab file in my /assets directory, same size and content as using the original approach.

My question is, how do I restore the content of the file from the assets directory to pass to the VocabularyProcessor.restore method?

I found a comprehensive example of a loader class to process each asset and add it to an asset tensor dictionary, but this gives me the file path and name, not the data.

for asset_any_proto in assets_any_proto:
    asset_proto = meta_graph_pb2.AssetFileDef()
    asset_any_proto.Unpack(asset_proto)
    tensor_name = asset_proto.tensor_info.name
if import_scope:
    tensor_name = "%s/%s" % (import_scope, tensor_name)
asset_tensor_dict[tensor_name] = os.path.join(
    compat.as_bytes(assets_directory),
    compat.as_bytes(asset_proto.filename))

How do i achieve the following:

vocab_processor = learn.preprocessing.VocabularyProcessor.restore(RESTORED_ASSET))

is this possible with Tensorflow?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
j_1234
  • 51
  • 3

0 Answers0