tensorflow2中model predict和__call__方法的区别
@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对象。
【点赞、关注、评论三连生活更美好】
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步