Tensorflow Invalid Argument Error: "Input is empty" when creating dataset for Siamese CNN

52 Views Asked by At

I am creating a Siamese CNN that does facial recognition. To process the data, I am using the tf.data.Dataset libraries. However, when I try to use my dataset as a numpy iterator, I get this error:

InvalidArgumentError: {{function_node __wrapped__IteratorGetNext_output_types_3_device_/job:localhost/replica:0/task:0/device:CPU:0}} Input is empty.
     [[{{node DecodeJpeg_1}}]] [Op:IteratorGetNext] name:

The line of code where this error specifically happens is this:

samples = data.as_numpy_iterator()
for s in samples:
  print(s)

Here is the rest of my code, from joining the files to where the error occurs.

anchor = tf.data.Dataset.list_files(ANC_DATA_PATH+'/*', shuffle=True).take(300)
positive = tf.data.Dataset.list_files(POS_DATA_PATH+'/*', shuffle=True).take(300)
negative = tf.data.Dataset.list_files(NEG_DATA_PATH+'/*', shuffle=True).take(300)

positives = tf.data.Dataset.zip((anchor, positive, tf.data.Dataset.from_tensor_slices(tf.ones(len(anchor)))))
negatives = tf.data.Dataset.zip((anchor, negative, tf.data.Dataset.from_tensor_slices(tf.zeros(len(anchor)))))
data = positives.concatenate(negatives)

def preprocess(file_path):
  byte_img = tf.io.read_file(file_path)
  img = tf.io.decode_jpeg(byte_img)
  img = tf.image.resize(img, (100, 100)) # Test this out
  img = img / 255.0
  return img

def preprocess_twin(input_img, validation_img, label):
  return (preprocess(input_img), preprocess(validation_img), label)

data = data.map(preprocess_twin)
data = data.cache()
data = data.shuffle(buffer_size=1024)
samples = data.as_numpy_iterator()
for s in samples:
  print(s)

Anyone know why this error occurs and how to rectify it? Thank you so much!

I tried swapping the datatype of the data variable, like taking shuffle=False and not using the .take(300). I also checked that all of my photos are .jpg and that there are no unconventional filenames on the photos. However, I still get this error.

0

There are 0 best solutions below