I'm trying to use a generator- based data set:
def gen():
return zip(samples,feature)
ds = tf.data.Dataset.from_generator(gen,output_types=tf.dtypes.float32)
model.fit(ds,
epochs=150,
#callbacks=[tensorboard_callback]
)
model.save("/sda/anyone/imagenet-in-np/transformer")
whereas feature is numpy.ndarray (2D array) whereas feature is numpy.ndarray (4D array) And I get the following error:
TypeError: Target data is missing. Your model has `loss`: BinaryCrossentropy, and therefore expects target data to be passed in `fit()`.
which is strange, as the target data is actually present. Whenever I separate the dataset to two
def gen():
return samples
ds = tf.data.Dataset.from_generator(gen,output_types=tf.dtypes.float32)
def gen2():
return feature
ds2= tf.data.Dataset.from_generator(gen2,output_types=tf.dtypes.float32)
model.fit(ds,ds2,
epochs=150,
#callbacks=[tensorboard_callback]
)
model.save("/sda/anyone/imagenet-in-np/transformer")
I get:
raise ValueError("`y` argument is not supported when using "
ValueError: `y` argument is not supported when using dataset as input.
Which means that TF doesn't accept this split.
So how should I use the generator API?
Edit #1: I tried as mentioned:
def gen():
for element in zip(samples,feature):
yield element
ds = tf.data.Dataset.from_generator(gen(),output_types=tf.dtypes.float32)
I get
TypeError: generator must be a Python callable.
So I tried to swap it to :
def gen():
for element in zip(samples,feature):
yield element
ds = tf.data.Dataset.from_generator(gen,output_types=tf.dtypes.float32)
I get again:
TypeError: Target data is missing. Your model has `loss`: BinaryCrossentropy, and therefore expects target data to be passed in `fit()`.
python-BaseException
Edit #2:
I've tried the following:
def gen():
for element in zip(samples,feature):
sample=tf.convert_to_tensor(element[0], dtype=tf.float32)
f=tf.convert_to_tensor(element[1], dtype=tf.float32)
print(sample.shape)
yield (sample,f)
ds = tf.data.Dataset.from_generator(gen,output_types=(tf.float32, tf.float32))
model.fit(ds,
epochs=150
#callbacks=[tensorboard_callback]
)
I get
2022-01-22 16:50:07.417109: W tensorflow/core/framework/op_kernel.cc:1745] OP_REQUIRES failed at conv_ops.cc:675 : INVALID_ARGUMENT: input must be 4-dimensional[16,17,10]