python - 如何更改tensorflow的SKCompat中的global_step

标签 python tensorflow scikit-learn

我使用 tensorflow.contrib.learn 中的 SKCompat 类对 MNIST 数据进行分类:

import tensorflow as tf
from tensorflow.contrib.learn import SKCompat
from tensorflow.contrib.learn import RunConfig

config = tf.contrib.learn.RunConfig(save_summary_steps=1000
                                    ,log_step_count_steps=1000
                                    ,model_dir = "tmp/TF/")

feature_columns = tf.contrib.learn.infer_real_valued_columns_from_input(X_train)

dnn_clf = SKCompat(tf.contrib.learn.DNNClassifier(hidden_units=[1200,600, 
     300, 150, 75], n_classes=10 ,feature_columns=feature_columns, dropout = .5, 
     config=config))

dnn_clf.fit(x=X_train, y=y_train, batch_size=128, steps=5000)

它按预期工作,但有一个小问题:它每 100 步输出信息消息,我怀疑这些信息编码在 global_step 变量中:

INFO:tensorflow:Using config: {'_task_type': None, '_task_id': 0, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x7f3a663d09b0>, '_master': '', '_num_ps_replicas': 0, '_num_worker_replicas': 0, '_environment': 'local', '_is_chief': True, '_evaluation_master': '', '_tf_config': gpu_options {
  per_process_gpu_memory_fraction: 1.0
}
, '_tf_random_seed': None, '_save_summary_steps': 1000, '_save_checkpoints_secs': 600, '_log_step_count_steps': 1000, '_session_config': None, '_save_checkpoints_steps': None, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_model_dir': 'tmp/TF/'}
WARNING:tensorflow:From /home/sergey/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/estimators/head.py:641: scalar_summary (from tensorflow.python.ops.logging_ops) is deprecated and will be removed after 2016-11-30.
Instructions for updating:
Please switch to tf.summary.scalar. Note that tf.summary.scalar uses the node name instead of the tag. This means that TensorFlow will automatically de-duplicate summary names based on the scope they are created in. Also, passing a tensor or list of tags to a scalar summary op is no longer supported.
WARNING:tensorflow:From /home/sergey/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/estimators/dnn.py:192: get_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.get_global_step
WARNING:tensorflow:From /home/sergey/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/layers/python/layers/optimizers.py:161: assert_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.assert_global_step
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Saving checkpoints for 1 into tmp/TF/model.ckpt.
INFO:tensorflow:loss = 2.50853, step = 1
INFO:tensorflow:global_step/sec: 60.7314
INFO:tensorflow:loss = 1.46667, step = 101 (1.648 sec)
INFO:tensorflow:global_step/sec: 53.2696
INFO:tensorflow:loss = 1.00616, step = 201 (1.877 sec)
INFO:tensorflow:global_step/sec: 57.6543
INFO:tensorflow:loss = 0.625174, step = 301 (1.734 sec)
INFO:tensorflow:global_step/sec: 53.0346
INFO:tensorflow:loss = 0.692355, step = 401 (1.885 sec)
...

问题:

是否有办法将信息输出减少到每 1,000 步?

下载数据*:

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/")
X_train = mnist.train.images
X_test = mnist.test.images
y_train = mnist.train.labels.astype("int")
y_test = mnist.test.labels.astype("int")

*来源:使用 Scikit-learn 和 Tensorflow 进行机器学习实践

最佳答案

您可以使用RunConfig设置运行配置。对于您的案例设置log_step_count_steps=1000

config = tf.contrib.learn.RunConfig(master=None, num_cores=0,
    log_device_placement=False,
    gpu_memory_fraction=1,
    tf_random_seed=None,
    save_summary_steps=100,
    save_checkpoints_secs=_USE_DEFAULT,
    save_checkpoints_steps=None,
    keep_checkpoint_max=5,
    keep_checkpoint_every_n_hours=10000,
    log_step_count_steps=1000,
    evaluation_master='',
    model_dir=None,
    session_config=None)

dnn_clf = SKCompat(tf.contrib.learn.DNNClassifier(hidden_units=[1200,600, 
     300, 150, 75], n_classes=10 ,feature_columns=feature_columns, dropout = .5, 
     config=config))

关于python - 如何更改tensorflow的SKCompat中的global_step,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46013115/

相关文章:

performance - Tensorflow:高效的多项式采样(Theano x50 更快?)

python - TensorFlow ExportOutputs、PredictOuput 并指定 signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY

machine-learning - 使用fit_transform()和transform()

tensorflow - 如何使用 tensorflow 服务为pytorch或sklearn模型提供服务

machine-learning - scikit learn 中序数数据和分类数据作为标签的区别

python - 在 Python 中伪造类似 LISP 的闭包?

python - 从多索引 pandas 系列创建 1 列数据框

python - 是否有可能用纯 Python 编写与魔兽世界一样大的 3D 游戏?

iphone - 在 iPhone OS 应用程序中使用 Ruby/Python 代码?

python - 剪切渐变时出错