tflearn中num_epoch含义就是针对所有样本的一次迭代

In tensorflow get started code:

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)

I know what batch_size means, but what do num_epochs and steps mean respectively when there are only 4 training examples?

share|improve this question
 
1                                                                                  
Possible duplicate of What is the difference between steps and epochs?                     – ml4294                 Apr 17 '17 at 15:15                                                                            
                                                                                                                        
I think this is a duplicate of stackoverflow.com/questions/38340311/…. You might find a well-explained answer there.                     – ml4294                 Apr 17 '17 at 15:16                                                                            
                                                                                                                        
Also, check out the documentation: tensorflow.org/api_docs/python/tf/contrib/learn/Trainable                     – Jeff                 Apr 17 '17 at 15:17                                                                            
                                                                                                                        
Thanks. It does help a lot.                     – iamabug                 Apr 18 '17 at 2:42                                                                            
                

                                2 Answers                                 2                        

         up vote2down voteaccepted

An epoch means using the whole data you have.

A step means using a single batch data.

So, n_steps = Number of data in single epoch // batch_size.

According to https://www.tensorflow.org/api_docs/python/tf/contrib/learn/Trainable,

  • steps: Number of steps for which to train model. If None, train forever. 'steps' works incrementally. If you call two times fit(steps=10) then training occurs in total 20 steps. If you don't want to have incremental behaviour please set max_steps instead. If set, max_steps must be None.

  • batch_size: minibatch size to use on the input, defaults to first dimension of x. Must be None if input_fn is provided.

原文地址:https://www.cnblogs.com/bonelee/p/8383746.html