Categories
Misc

What is the correct way to zip multiple inputs into a tf.data.Dataset?

Hi,

I have a multi input model with a single target variable

After a lot of trial and error (and countless hours on SO) I’ve come this far

#reads in filepaths to images from dataframe train

images = tf.data.Dataset.from_tensor_slices(train.image.to_numpy())

#converts labels to one hot encoding vector

target = tf.keras.utils.to_categorical(

train.Label.to_numpy(), num_classes=n_class, dtype=’float32′

)

#reads in the image and resizes it

images= images.map(transform_img)

#zips the former according to

#https://stackoverflow.com/questions/65295459/how-to-use-tensorflow-dataset-correctly-for-multiple-input-layers-with-keras

input_1 = tf.data.Dataset.zip((anchors, target))

dataset = tf.data.Dataset.zip((input_1, target))

and I think this is almost the solution, but the second input shape get’s distorted.

Because I get a warning that input expected is (None, n_class)

But it received an input of (n_class, 1)

And an error:

ValueError: Shapes (n_class, 1) and (n_class, n_class) are incompatible

I checked though, the shapes from to_categorical is correct, it’s num_examples, n_class

Could someone help an utterly confused me out?

Thanks a lot!

submitted by /u/obolli
[visit reddit] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *