加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – num_epochs和步骤有什么区别?

发布时间:2020-12-20 11:59:33 所属栏目:Python 来源:网络整理
导读:在tensorflow入门代码中: import tensorflow as tfimport numpy as npfeatures = [tf.contrib.layers.real_valued_column("x",dimension=1)]estimator = tf.contrib.learn.LinearRegressor(feature_columns=features)x = np.array([1.,2.,3.,4.])y = np.arr
在tensorflow入门代码中:

import tensorflow as tf
import numpy as np

features = [tf.contrib.layers.real_valued_column("x",dimension=1)]
estimator = tf.contrib.learn.LinearRegressor(feature_columns=features)
x = np.array([1.,2.,3.,4.])
y = np.array([0.,-1.,-2.,-3.])
input_fn = tf.contrib.learn.io.numpy_input_fn({"x":x},y,batch_size=4,num_epochs=1000)
estimator.fit(input_fn=input_fn,steps=1000)
estimator.evaluate(input_fn=input_fn)

我知道batch_size是什么意思,但是当只有4个训练样例时,num_epochs和步骤分别是什么意思?

解决方法

时代意味着使用您拥有的全部数据.

步骤意味着使用单个批次数据.

所以,n_steps =单个纪元// batch_size中的数据数量.

根据https://www.tensorflow.org/api_docs/python/tf/contrib/learn/Trainable,

>步骤:训练模型的步骤数.如果没有,永远训练. ‘steps’以递增方式工作.如果您调用两次(步数= 10),则总共20个步骤进行训练.如果您不想有增量行为,请改为设置max_steps.如果设置,则max_steps必须为None.> batch_size:要在输入上使用的小批量大小,默认为x的第一个维度.如果提供input_fn,则必须为None.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读