ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python – Keras:test_on_batch和predict_on_batch之间的区别

2019-08-28 05:58:14  阅读:1785  来源: 互联网

标签:python keras machine-learning neural-network deep-learning


在Philippe Remy的blog post状态LSTM上,他在底部说:“你可能必须通过调用predict_on_batch()或test_on_batch()手动进行验证/测试”.

看看the documentation,predict_on_batch这样做:

predict_on_batch(self, x)

Returns predictions for a single batch of samples.

Arguments

    x: Input samples, as a Numpy array.

Returns

Numpy array(s) of predictions.

test_on_batch执行此操作:

test_on_batch(self, x, y, sample_weight=None)

Test the model on a single batch of samples.

Arguments

    x: Numpy array of test data, or list of Numpy arrays if the model has multiple inputs. If all inputs in the model are named, you can also pass a dictionary mapping input names to Numpy arrays.
    y: Numpy array of target data, or list of Numpy arrays if the model has multiple outputs. If all outputs in the model are named, you can also pass a dictionary mapping output names to Numpy arrays.
    sample_weight: Optional array of the same length as x, containing weights to apply to the model's loss for each sample. In the case of temporal data, you can pass a 2D array with shape (samples, sequence_length), to apply a different weight to every timestep of every sample. In this case you should make sure to specify sample_weight_mode="temporal" in compile().

Returns

Scalar test loss (if the model has a single output and no metrics) or list of scalars (if the model has multiple outputs and/or metrics). The attribute model.metrics_names will give you the display labels for the scalar outputs

我在训练循环中使用train_on_batch,基本上与博客文章一样.我如何知道是否使用predict_on_batch或test_on_batch进行交叉验证?

解决方法:

所以基本上:

> predict_on_batch为您提供的一组预测作为参数提供给您.如果您训练网络识别猫和狗 – 一旦您将图像提供给predict_on_batch方法 – 如果给定图像中有猫或狗,您将获得概率.您还可以使用这些概率来评估模型.
> test_on_batch为您提供一个标量,用于衡量您的模型表现如何.给定图像和真实标签 – 它计算一堆损失和指标(在模型编译中定义),用于衡量模型如何适合数据.

后缀on_batch来自模型一次执行所有计算的事实.有时这是不可行的,所以最好将数据分成小块并执行多次计算. keras为您提供自动执行此操作的功能.所以predict相当于predict_on_batch和evaluate – 相当于test_on_batch.

为了选择交叉验证期间使用的功能 – 您需要使用:

>在需要实际预测时预测/ predict_on_batch,而不仅仅是指标值.但是,在这种情况下,您仍需要计算指标值.
> test_on_batch /在您只需要指标值时进行评估.

所以 – 正如您所看到的 – 您可以在评估模型时实际组合这两个功能.如果你只是想要指标 – 尝试test_on_batch / evaluate,因为它可以为你节省大量的计算.

标签:python,keras,machine-learning,neural-network,deep-learning
来源: https://codeday.me/bug/20190828/1748835.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有