@disable_multi_worker def predict(self, x, batch_size=None, verbose=0, steps=None, callbacks=None, max_queue_size=10, workers=1, use_multiprocessing=False): """Generates output predictions for the input samples. Computation is done in batches. This method is designed for performance in large scale inputs. For small amount of inputs that fit in one batch, directly using `__call__` is recommended for faster execution, e.g., `model(x)`, or `model(x, training=False)` if you have layers such as `tf.keras.layers.BatchNormalization` that behaves differently during inference. Also, note the fact that test loss is not affected by regularization layers like noise and dropout.
上述代碼是tensorflow2.0.0中的一段源碼,下面的注釋中提到當少量數據的時候使用__call__比較快。
實際使用中有些地方使用predict會直接卡住。
__call__方法調用后得到的是Tensor對象,使用numpy()方法可以得到ndarray對象。
