为什么在运行TensorFlow示例时会收到大量警告消息?

为什么在运行TensorFlow示例时会收到大量警告消息?,tensorflow,jupyter,Tensorflow,Jupyter,我正在学习教程: 为什么我会收到以下许多错误?此外,最终损失分数也不同。文件说: {'global_step': 1000, 'loss': 1.9650059e-11} 而我的损失是:{'loss':6.3995182e-09,'global_step':1000} import tensorflow as tf # NumPy is often used to load, manipulate and preprocess data. import numpy as np # Decla

我正在学习教程:

为什么我会收到以下许多错误?此外,最终损失分数也不同。文件说:

{'global_step': 1000, 'loss': 1.9650059e-11}
而我的损失是:
{'loss':6.3995182e-09,'global_step':1000}

import tensorflow as tf
# NumPy is often used to load, manipulate and preprocess data.
import numpy as np

# Declare list of features. We only have one real-valued feature. There are many
# other types of columns that are more complicated and useful.
features = [tf.contrib.layers.real_valued_column("x", dimension=1)]

# An estimator is the front end to invoke training (fitting) and evaluation
# (inference). There are many predefined types like linear regression,
# logistic regression, linear classification, logistic classification, and
# many neural network classifiers and regressors. The following code
# provides an estimator that does linear regression.
estimator = tf.contrib.learn.LinearRegressor(feature_columns=features)

# TensorFlow provides many helper methods to read and set up data sets.
# Here we use `numpy_input_fn`. We have to tell the function how many batches
# of data (num_epochs) we want and how big each batch should be.
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)

# We can invoke 1000 training steps by invoking the `fit` method and passing the
# training data set.
estimator.fit(input_fn=input_fn, steps=1000)

# Here we evaluate how well our model did. In a real example, we would want
# to use a separate validation and testing data set to avoid overfitting.
print(estimator.evaluate(input_fn=input_fn))

INFO:tensorflow:Using default config.
INFO:tensorflow:Using config: {'_task_type': None, '_task_id': 0, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x7f1555e351d0>, '_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': 100, '_save_checkpoints_secs': 600, '_save_checkpoints_steps': None, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_model_dir': None}
WARNING:tensorflow:Using temporary folder as model directory: /tmp/tmpol66d18y
WARNING:tensorflow:Rank of input Tensor (1) should be the same as output_rank (2) for column. Will attempt to expand dims. It is highly recommended that you resize your input, as this behavior may change.
WARNING:tensorflow:From /home/abigail/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/estimators/head.py:615: 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.
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Saving checkpoints for 1 into /tmp/tmpol66d18y/model.ckpt.
INFO:tensorflow:loss = 2.25, step = 1
INFO:tensorflow:global_step/sec: 2197.95
INFO:tensorflow:loss = 0.0537609, step = 101 (0.047 sec)
INFO:tensorflow:global_step/sec: 2106.83
INFO:tensorflow:loss = 0.0114769, step = 201 (0.047 sec)
INFO:tensorflow:global_step/sec: 2184.51
INFO:tensorflow:loss = 0.00149274, step = 301 (0.046 sec)
INFO:tensorflow:global_step/sec: 2126.71
INFO:tensorflow:loss = 0.000284785, step = 401 (0.047 sec)
INFO:tensorflow:global_step/sec: 2112.6
INFO:tensorflow:loss = 3.2641e-05, step = 501 (0.048 sec)
INFO:tensorflow:global_step/sec: 2048.21
INFO:tensorflow:loss = 3.71825e-06, step = 601 (0.048 sec)
INFO:tensorflow:global_step/sec: 2154.48
INFO:tensorflow:loss = 1.1719e-06, step = 701 (0.047 sec)
INFO:tensorflow:global_step/sec: 2287.71
INFO:tensorflow:loss = 1.42258e-07, step = 801 (0.043 sec)
INFO:tensorflow:global_step/sec: 3059.53
INFO:tensorflow:loss = 7.27343e-08, step = 901 (0.033 sec)
INFO:tensorflow:Saving checkpoints for 1000 into /tmp/tmpol66d18y/model.ckpt.
INFO:tensorflow:Loss for final step: 6.50745e-09.
WARNING:tensorflow:Rank of input Tensor (1) should be the same as output_rank (2) for column. Will attempt to expand dims. It is highly recommended that you resize your input, as this behavior may change.
WARNING:tensorflow:From /home/abigail/anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/estimators/head.py:615: 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.
INFO:tensorflow:Starting evaluation at 2017-05-08-06:39:50
INFO:tensorflow:Restoring parameters from /tmp/tmpol66d18y/model.ckpt-1000
INFO:tensorflow:Finished evaluation at 2017-05-08-06:39:51
INFO:tensorflow:Saving dict for global step 1000: global_step = 1000, loss = 6.39952e-09
WARNING:tensorflow:Skipping summary for global_step, must be a float or np.float32.
{'loss': 6.3995182e-09, 'global_step': 1000}
将tensorflow导入为tf
#NumPy通常用于加载、操作和预处理数据。
将numpy作为np导入
#声明特性列表。我们只有一个实值特征。有很多
#更复杂、更有用的其他类型的列。
features=[tf.contrib.layers.real\u valued\u column(“x”,维度=1)]
#估计器是调用训练(拟合)和评估的前端
#(推论)。有许多预定义类型,如线性回归,
#逻辑回归、线性分类、逻辑分类和
#许多神经网络分类器和回归器。下面的代码
#提供进行线性回归的估计器。
估计器=tf.contrib.learn.LinearRegressor(特征列=特征)
#TensorFlow提供了许多辅助方法来读取和设置数据集。
#这里我们使用'numpy\u input\u fn'。我们必须告诉函数有多少批
#我们需要的数据数量(数量)以及每批数据的大小。
x=np.数组([1,2,3,4.]))
y=np.数组([0.,-1.,-2.,-3.]))
input_fn=tf.contrib.learn.io.numpy_input_fn({“x”:x},y,批处理大小=4,
num_epochs=1000)
#通过调用'fit'方法并传递
#训练数据集。
拟合(输入值=输入值,步长=1000)
#在这里,我们评估我们的模型做得有多好。在一个真实的例子中,我们希望
#使用单独的验证和测试数据集以避免过度拟合。
打印(估计器评估(输入\ fn=输入\ fn))
信息:tensorflow:使用默认配置。
信息:tensorflow:使用配置:{“任务类型”:无,“\u任务id”:0,“\u集群规格”:,“\u主节点”:“,”,“\u数量\u ps \u副本”:0,“\u数量\u工作者\u副本”:0,“\u环境”:“本地”,“u是首席节点”:True,“\u评估\u主节点”:“,”u tf \u配置:“gpu选项”{
每处理器gpu内存分数:1.0
}
“无”,“保存检查点摘要”步骤:100,“保存检查点”步骤:600,“保存检查点”步骤:无,“保留检查点最多”:5,“每小时保留一次检查点”:10000,“模型:无”
警告:tensorflow:使用临时文件夹作为模型目录:/tmp/tmpol66d18y
警告:tensorflow:输入张量(1)的秩应与列的输出_秩(2)相同。将尝试扩展dims。强烈建议您调整输入大小,因为此行为可能会更改。
警告:tensorflow:From/home/abigail/anaconda3/lib/python3.6/site packages/tensorflow/contrib/learn/python/learn/estimators/head.py:615:scalar_summary(来自tensorflow.python.ops.logging_ops)已被弃用,并将在2016-11-30后删除。
更新说明:
请切换到tf.summary.scalar。请注意,tf.summary.scalar使用节点名而不是标记。这意味着TensorFlow将根据创建摘要名称的范围自动消除重复的摘要名称。此外,不再支持将张量或标记列表传递给标量摘要op。
信息:tensorflow:创建检查点SaveRhook。
信息:tensorflow:将1的检查点保存到/tmp/tmpol66d18y/model.ckpt。
信息:tensorflow:损耗=2.25,步长=1
信息:tensorflow:global_step/sec:2197.95
信息:tensorflow:损耗=0.0537609,步长=101(0.047秒)
信息:tensorflow:global_step/sec:2106.83
信息:tensorflow:损耗=0.0114769,步长=201(0.047秒)
信息:tensorflow:global_step/sec:2184.51
信息:tensorflow:损耗=0.00149274,步长=301(0.046秒)
信息:tensorflow:global_step/sec:2126.71
信息:tensorflow:损耗=0.000284785,步长=401(0.047秒)
信息:tensorflow:global_step/sec:2112.6
信息:tensorflow:损耗=3.2641e-05,步长=501(0.048秒)
信息:tensorflow:global_step/sec:2048.21
信息:tensorflow:损耗=3.71825e-06,步长=601(0.048秒)
信息:tensorflow:global_step/sec:2154.48
信息:tensorflow:损耗=1.1719e-06,步长=701(0.047秒)
信息:tensorflow:global_step/sec:2287.71
信息:tensorflow:损耗=1.42258e-07,步长=801(0.043秒)
信息:tensorflow:global_step/sec:3059.53
信息:tensorflow:损耗=7.27343e-08,阶跃=901(0.033秒)
信息:tensorflow:将1000的检查点保存到/tmp/tmpol66d18y/model.ckpt。
信息:tensorflow:最后一步损失:6.50745e-09。
警告:tensorflow:输入张量(1)的秩应与列的输出_秩(2)相同。将尝试扩展dims。强烈建议您调整输入大小,因为此行为可能会更改。
警告:tensorflow:From/home/abigail/anaconda3/lib/python3.6/site packages/tensorflow/contrib/learn/python/learn/estimators/head.py:615:scalar_summary(来自tensorflow.python.ops.logging_ops)已被弃用,并将在2016-11-30后删除。
更新说明:
请切换到tf.summary.scalar。请注意,tf.summary.scalar使用节点名而不是标记。这意味着TensorFlow将根据创建摘要名称的范围自动消除重复的摘要名称。此外,不再支持将张量或标记列表传递给标量摘要op。
信息:tensorflow:2017-05-08-06:39:50开始评估
信息:tensorflow:从/tmp/tmpol66d18y/model.ckpt-1000恢复参数
信息:tensorflow:于2017-05-08-06:39:51完成评估
信息:tensorflow:为全局步骤1000保存dict:全局步骤=1000,损失=6.39952e-09
警告:tensorflow:正在跳过全局_步骤的摘要,必须是浮点或np.float32。
{'loss':6.3995182e-09,'global_step':1000}

这正按预期工作

由于诸如随机初始化之类的问题,您不希望每次运行程序时得到完全相同的数值损失。(如果需要确定性输出,可以尝试将Tensorflow graph random seed设置为固定值。)

警告和信息消息是良性的;我同意他们看起来有点吓人。你几乎总是可以忽略的信息
tf.logging.set_verbosity(tf.logging.ERROR)
estimator=tf.estimator.LinearRegressor(feature_columns = feature_columns)
estimator=tf.estimator.LinearRegressor(feature_columns = feature_columns, model_dir="D:\test") #Or any other directory as per your wish