Tensorflow TypeError: `generator` yielded an element of shape (32,) where an element of shape (None, None) was expected

Viewed 225

I am training a dataset with both numerical and categorical data. I split the columns and fed the categorical data in an embedding layer first. When I try to train my model, this error occurs.

TypeError: `generator` yielded an element of shape (32,) where an element of shape (None, None) was expected.

This is my code:

numeric_inputs = tf.keras.layers.Input((22,), name='numeric_inputs')
cat_inputs = tf.keras.layers.Input((1,), name='cat_inputs')

def emb_sz_rule(n_cat):
    return min(600, round(1.6 * n_cat ** 0.56))

embedding_layer = tf.keras.layers.Embedding(
    num_categories,
    emb_sz_rule(num_categories),
    input_length=1)
cats = embedding_layer(cat_inputs)
cats = tf.keras.layers.Flatten()(cats)


def bootstrap_sample_generator(batch_size):
    while True:
        batch_idx = np.random.choice(
            X_train_scaled.shape[0], batch_size)
        yield({'numeric_inputs': X_train_scaled[batch_idx],
               'cat_inputs': X_cat_train[batch_idx]},
              {'output': y[batch_idx]})

BATCH_SIZE = 32

history = model.fit(
    bootstrap_sample_generator(BATCH_SIZE),
    steps_per_epoch= len(X_train_scaled) / BATCH_SIZE,
    epochs=5,
    max_queue_size=10,
)
0 Answers
Related