Skip to content

Instantly share code, notes, and snippets.

@yoel-zeldes
Last active December 9, 2018 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoel-zeldes/8fd471fe290496afe711e41451a541e8 to your computer and use it in GitHub Desktop.
Save yoel-zeldes/8fd471fe290496afe711e41451a541e8 to your computer and use it in GitHub Desktop.
# ...
def _eval_tensor_if_needed(self, path):
"""
Given a path to a tensor file, evaluate the tensor and cache the result in self._tensor_values.
"""
if self._session is None:
return None
if path not in self._tensor_values:
self._tensor_values[path] = self._session.run(self._graph.get_tensor_by_name(path[1:]))
return self._tensor_values[path]
def read(self, path, size, offset, fh):
if path.startswith('/bin/'):
return self._bin_scripts[path][offset:offset + size]
val = self._eval_tensor_if_needed(path)
with printoptions(suppress=True,
formatter={'all': _fixed_val_length},
threshold=sys.maxint,
linewidth=sys.maxint):
return str(val)[offset:offset + size]
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment