最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - tensorflow dataset loop endless will model.predict - Stack Overflow

programmeradmin6浏览0评论

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 imagine it was due to ".repeat()" so I try:

model.predict(test_dataset_sim )

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:404] Local rendezvous is aborting with status: OUT_OF_RANGE: End of sequence

What is the good way to make it work properly?

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 imagine it was due to ".repeat()" so I try:

model.predict(test_dataset_sim )

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:404] Local rendezvous is aborting with status: OUT_OF_RANGE: End of sequence

What is the good way to make it work properly?

Share Improve this question edited Mar 11 at 13:00 Jonathan Roy asked Mar 10 at 21:38 Jonathan RoyJonathan Roy 4411 gold badge7 silver badges23 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

try to set steps in predict function

model.predict(test_dataset_sim, steps=steps)

and the steps is the length of your test_dataset_sim / test_batch_sz

thanks.

发布评论

评论列表(0)

  1. 暂无评论