I am using the dataset API and am getting unexpected None values in my dataset shape.
import tensorflow as tf
import os
def load_seti_dataset(path):
with open(path) as f:
dataset_file = f.read().splitlines()
data = tf.data.Dataset.from_tensor_slices(dataset_file)
data = data.repeat()
data = data.shuffle(buffer_size=1000)
data = data.map(parse_records, num_parallel_calls=4)
data = data.batch(batch_size=2)
data = data.prefetch(buffer_size=1)
return data
def load_image(path):
image = tf.io.read_file(path)
image = tf.io.decode_png(image, channels=3)
image = tf.image.resize(image, [512, 384])
image = 1. - image / 127.5
return image
def parse_records(line):
image_path, image_label = tf.io.decode_csv(line, ["", 0])
image = load_image(image_path)
return image, image_label
data = load_seti_dataset("test_data.csv")
print(data)
test_data.csv is just a csv with image path and label. Images I am reading are 512x384 with 3 channels. Each label is just a scalar value.
Printing data outputs these dimensions:
<PrefetchDataset shapes: ((None, 512, 384, 3), (None,)), types: (tf.float32, tf.int32)>
What I would expect:
<PrefetchDataset shapes: ((512, 384, 3), (1,)), types: (tf.float32, tf.int32)>
Why are there None values in each of the dimensions in the batch? Why isn't the second value in the batch a just scalar?