简体   繁体   中英

How to use keras model.predict with placeholders input?

I'm trying to feed keras predict method with tf placeholders while providing real data later.

I do z = model.predict(x*y, steps=1) where x and y are tf placeholders.

Then I do sess.run(tf.variables_initializer([z], feed_dict = {x: <x>, y: <y>})) where <x> and <y> are numpy arrays.

But I get error: Invalid argument: You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [1,1024,1024,3] [[{{node Placeholder}}]]

I don't really understand - where do I need to feed placeholders with values?

model.predict() executes the actual prediction. You can't predict on placeholders, you need to feed that function real data. If you explicitly feed it None for input data, then the model must have been created with existing data tensor(s) , and it still is what executes the actual prediction .

Normally, when a model is created, it has placeholder tensors for the input and output. However, you have the option of giving it real tensors, instead of placeholders. See an example of this here . In this case, and only this case, you can use fit, predict, or evaluate without feeding it data. The only reason you can do that is because the data already exists .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM