码迷,mamicode.com
首页 > 其他好文 > 详细

tensorflow2中model predict和__call__方法的区别

时间:2020-04-24 15:58:10      阅读:349      评论:0      收藏:0      [点我收藏+]

标签:ons   color   isa   elf   eth   cal   注释   gen   oss   

 @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对象。

tensorflow2中model predict和__call__方法的区别

标签:ons   color   isa   elf   eth   cal   注释   gen   oss   

原文地址:https://www.cnblogs.com/oldBook/p/12767875.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!