繁体   English   中英

使用高级API tf.contrib.learn.DNNClassifier时Tensorflow批处理大小是多少

[英]what is the Tensorflow batch size when you use high-level API tf.contrib.learn.DNNClassifier

def binaryClassify_DNN(units,steps,trainingFilePath,testingFilePath,modelPath):

    # Data sets

    # Load datasets.
    training_set = tf.contrib.learn.datasets.base.load_csv(filename=trainingFilePath,target_dtype=np.float)
    test_set = tf.contrib.learn.datasets.base.load_csv(filename=testingFilePath,target_dtype=np.float)

    # Build 3 layer DNN with 10, 20, 10 units respectively.
    classifier = tf.contrib.learn.DNNClassifier(hidden_units=units,n_classes=2,model_dir=modelPath,optimizer=tf.train.ProximalAdagradOptimizer(learning_rate=0.1))

    # Fit model.
    classifier.fit(x=training_set.data,
                   y=training_set.target,
                   steps=steps)

    # Evaluate accuracy.
    accuracy_score = classifier.evaluate(x=test_set.data,
                                         y=test_set.target)["accuracy"]
    print('Accuracy: {0:f}'.format(accuracy_score))

我在上面的源代码中进行了编码,与https://www.tensorflow.org/versions/r0.10/tutorials/tflearn/index.html#tf-contrib-learn-quickstart几乎没有变化

如您所见,我没有为batch_size添加可以添加到classifier.fi()

我尝试执行此代码,似乎没有批处理大小就在循环。 我的意思是,这看起来像是在训练完整数据而不是小批量数据。

是真的吗

我想知道批处理大小的默认设置是什么。

提前致谢。

对不起,我应该在发布之前研究一下源代码

def fit(self, x=None, y=None, input_fn=None, steps=None, batch_size=None,
      monitors=None, max_steps=None):
"""Trains a model given training data `x` predictions and `y` targets.

Args:
  x: Matrix of shape [n_samples, n_features...]. Can be iterator that
     returns arrays of features. The training input samples for fitting the
     model. If set, `input_fn` must be `None`.
  y: Vector or matrix [n_samples] or [n_samples, n_outputs]. Can be
     iterator that returns array of targets. The training target values
     (class labels in classification, real numbers in regression). If set,
     `input_fn` must be `None`.
  input_fn: Input function. If set, `x`, `y`, and `batch_size` must be
    `None`.
  steps: Number of steps for which to train model. If `None`, train forever.
    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.
  monitors: List of `BaseMonitor` subclass instances. Used for callbacks
    inside the training loop.
  max_steps: Number of total steps for which to train model. If `None`,
    train forever. If set, `steps` must be `None`.

    Two calls to `fit(steps=100)` means 200 training
    iterations. On the other hand, two calls to `fit(max_steps=100)` means
    that the second call will not do any iteration since first call did
    all 100 steps.

Returns:
  `self`, for chaining.

Raises:
  ValueError: If `x` or `y` are not `None` while `input_fn` is not `None`.
  ValueError: If both `steps` and `max_steps` are not `None`.
"""

如您所见,默认batch_size是'x'的第一维

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM