Skip to content
Advertisement

Reading in file names from a tensor in Tensorflow

Context: I am trying to make a GAN to generate images from a large dataset, and have been running into OOM issues when loading in the training data. In an effort to solve this, I am trying to pass in a list of file directories and read them in as images only when needed.

Issue: I do not know how to parse out the file name from the tensor itself. If anyone has any insight on how to convert the tensor back to a list or somehow iterate through the tensor. Or, if this is a bad way to solve this problem, please let me know

Relevant code snippets:

Generating the data: NOTE: make_file_list() returns a list of file names for all the images I want to read in

JavaScript

training function:

JavaScript

train step:

JavaScript

Error:

JavaScript

Advertisement

Answer

Remove @tf.function decorator on your train_step. If you decorate your train_step with @tf.function, Tensorflow will try to convert the Python code inside train_step into an execution graph instead of operating in eager mode. Execution graphs offer speedup, but also put some constraints on which operators can be performed (as the error stated).

To keep @tf.function on train_step, you can do the iterating and loading step in your train function first, then pass the already loaded image as an argument to train_step instead of trying to load image directly within train_step

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement