What is the difference between using model(x)
and model.predict(x)
for predicting the outcome of a model in Keras?
Keras with tensorflow backend was using underlying tensorflow objects, but mostly was providing high level outputs which could be understood outside the tensorflow environment (as an example it could output numpy arrays or python lists).
Today given a model in tensorflow 2.0 (built using the keras library),
out_np = model.predict(x)
provides a numpy array which can, as an example, be printed with print(out_np)
.
On the other hand,
out_tf = model(x)
results into a tensorflow object, wich can be converted to a numpy array with .numpy()
The two results are equivalent, as an example, we have that the following is True,
out_np.max() == out_tf.numpy().max()
The format may be different, but the meaning of model(x)
and model.predict(x)
is the same:
given an input x, it is the value of the output nodes of a network characterized by its structure, weights and biases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With