[Python] tensorflow dataset loop endless will model.predict

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    I use this code to setup my dataset for trainning and predict:

    train_dataset = train_dataset.batch(train_batch_sz)
    train_dataset = train_dataset.repeat().prefetch(5)

    test_dataset_sim = test_dataset
    test_dataset = test_dataset.batch(test_batch_sz)
    test_dataset = test_dataset.repeat().prefetch(5)


    Trainning work perfectly but when it is time to model.predict(test_dataset) the predict loop endless. I imagin it was due to ".repeat()" so I try:

    model.predict(test_dataset)


    and got this error:


    ValueError: Exception encountered when calling Sequential.call().

    Invalid input shape for input Tensor("data:0", shape=(24,), dtype=float32). Expected shape (None, 24), but input has incompatible shape (24,)

    Arguments received by Sequential.call():
    • inputs=tf.Tensor(shape=(24,), dtype=float32)
    • training=False
    • mask=None
    File <command-8335341383601104>, line 35

    ---> 35 y_pred = model.predict(test_dataset_sim)
    36 y_pred_classes = np.argmax(y_pred, axis=1)
    37 y_pred_prob = np.max(y_pred, axis=1)
    File /databricks/python/lib/python3.11/site-packages/keras/src/models/functional.py:285, in Functional._adjust_input_rank(self, flat_inputs)
    283 adjusted.append(ops.expand_dims(x, axis=-1))
    284 continue
    --> 285 raise ValueError(
    286 f"Invalid input shape for input {x}. Expected shape "
    287 f"{ref_shape}, but input has incompatible shape {x.shape}"
    288 )
    289 # Add back metadata.
    290 for i in range(len(flat_inputs)):


    I change my dataset to:

    test_dataset_sim = test_dataset.batch(test_batch_sz)


    I got this warning and don't get all my predict step as required

    2025-03-10 21:05:32.085357: W tensorflow/core/framework/local_rendezvous.cc:404] Local rendezvous is aborting with status: OUT_OF_RANGE: End of sequence


    What is the good way to make it work properly?

    Continue reading...

Compartilhe esta Página