Last active
December 9, 2018 20:45
-
-
Save yoel-zeldes/8fd471fe290496afe711e41451a541e8 to your computer and use it in GitHub Desktop.
Used in https://towardsdatascience.com/tensorflow-filesystem-access-tensors-differently-888bce1d68e7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
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