Python 3.x TypeError:获取参数None的类型无效<;类别';非类型'&燃气轮机;在张量流中

Python 3.x TypeError:获取参数None的类型无效<;类别';非类型'&燃气轮机;在张量流中,python-3.x,tensorflow,Python 3.x,Tensorflow,我试图在Tensorflow中建立一个简单的线性回归模型。我不明白“无”的东西是从哪里来的 我已经检查了这类问题的一些答案,但不明白这个错误背后的主要原因 “s_mer”是否没有价值?如果是,为什么? 是否会出现此错误的其他实例 代码如下: import tensorflow as tf import numpy as np import pandas as pd from sklearn.datasets import load_boston import matplotlib.pyplot

我试图在Tensorflow中建立一个简单的线性回归模型。我不明白“无”的东西是从哪里来的

我已经检查了这类问题的一些答案,但不明白这个错误背后的主要原因

“s_mer”是否没有价值?如果是,为什么? 是否会出现此错误的其他实例

代码如下:

import tensorflow as tf
import numpy as np
import pandas as pd
from sklearn.datasets import load_boston
import matplotlib.pyplot as plt

boston=load_boston()
type(boston)
boston.feature_names

bd=pd.DataFrame(data=boston.data,columns=boston.feature_names)

bd['Price']=pd.DataFrame(data=boston.target)
np.random.shuffle(bd.values)


W0=tf.Variable(0.0000000003)
W1=tf.Variable(0.000000000002)
b=tf.Variable(0.0000000000001)
    #print(bd.shape[1])

    #tf.summary.histogram('Weights', W0)
    #tf.summary.histogram('Weights', W1)
    #tf.summary.histogram('Biases', b)



dataset_input=bd.iloc[:, 0 : bd.shape[1]-1];
    #dataset_input.head(2)

dataset_output=bd.iloc[:, bd.shape[1]-1]
dataset_output=dataset_output.values
dataset_output=dataset_output.reshape((bd.shape[0],1)) #converted (506,) to (506,1) because in pandas
    #the shape was not changing and it was needed later in feed_dict


dataset_input=dataset_input.values  #only dataset_input is in DataFrame form and converting it into np.ndarray

    # ADDED
dataset_input = np.array(dataset_input, dtype=np.float32)
    # ADDED
dataset_output = np.array(dataset_output, dtype=np.float32)

X=tf.placeholder(tf.float32, shape=(None,bd.shape[1]-1))
Y=tf.placeholder(tf.float32, shape=(None,1))

Y_=W0*X*X + W1*X + b
    #Y_pred = tf.add(tf.multiply(tf.pow(X, pow_i), W), Y_pred)
print(X.shape)
print(Y.shape)


loss=tf.reduce_mean(tf.square(Y_-Y))
    #tf.summary.scalar('loss',loss)

optimizer=tf.train.GradientDescentOptimizer(0.0000000000001)
train=optimizer.minimize(loss)

init=tf.global_variables_initializer()#tf.global_variables_initializer()#tf.initialize_all_variables()
sess=tf.Session()
sess.run(init)



wb_=[]
with tf.Session() as sess:
    summary_merge = tf.summary.merge_all()

    writer=tf.summary.FileWriter("Users/ajay/Documents",sess.graph)

    epochs=10
    sess.run(init)

    for i in range(epochs):
        s_mer=sess.run(summary_merge,feed_dict={X: dataset_input, Y: dataset_output})  #ERROR________ERROR
        sess.run(train,feed_dict={X:dataset_input,Y:dataset_output})

            #CHANGED
        print("loss",sess.run(loss, feed_dict={X:dataset_input,Y:dataset_output}))
        #sess.run(loss, feed_dict={X:dataset_input,Y:dataset_output})
        writer.add_summary(s_mer,i)

            #tf.summary.histogram(name="loss",values=loss)
        if(i%5==0):
            print(i, sess.run([W0,W1,b]))
            wb__.append(sess.run([W0,W1,b]))

        print(writer.get_logdir())
        print(writer.close())
并获取以下错误:

(?, 13)
(?, 1)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-186c4033eb74> in <module>()
     73 
     74     for i in range(epochs):
---> 75         s_mer=sess.run(summary_merge,feed_dict={X: dataset_input, Y: dataset_output})  #ERROR________ERROR
     76         sess.run(train,feed_dict={X:dataset_input,Y:dataset_output})
     77 

~/anaconda3/envs/Tensorflow/lib/python3.6/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
    776     try:
    777       result = self._run(None, fetches, feed_dict, options_ptr,
--> 778                          run_metadata_ptr)
    779       if run_metadata:
    780         proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

~/anaconda3/envs/Tensorflow/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
    967 
    968     # Create a fetch handler to take care of the structure of fetches.
--> 969     fetch_handler = _FetchHandler(self._graph, fetches, feed_dict_string)
    970 
    971     # Run request and get response.

~/anaconda3/envs/Tensorflow/lib/python3.6/site-packages/tensorflow/python/client/session.py in __init__(self, graph, fetches, feeds)
    406     """
    407     with graph.as_default():
--> 408       self._fetch_mapper = _FetchMapper.for_fetch(fetches)
    409     self._fetches = []
    410     self._targets = []

~/anaconda3/envs/Tensorflow/lib/python3.6/site-packages/tensorflow/python/client/session.py in for_fetch(fetch)
    225     if fetch is None:
    226       raise TypeError('Fetch argument %r has invalid type %r' %
--> 227                       (fetch, type(fetch)))
    228     elif isinstance(fetch, (list, tuple)):
    229       # NOTE(touts): This is also the code path for namedtuples.

TypeError: Fetch argument None has invalid type <class 'NoneType'>
(?,13)
(?, 1)
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
73
74表示范围内的i(历元):
--->75 s_mer=sess.run(摘要_合并,提要_dict={X:dataset_输入,Y:dataset_输出})#错误
76 sess.run(train,feed_dict={X:dataset_输入,Y:dataset_输出})
77
运行中的~/anaconda3/envs/Tensorflow/lib/python3.6/site-packages/Tensorflow/python/client/session.py(self、fetches、feed\u dict、options、run\u元数据)
776尝试:
777结果=self.\u运行(无、取数、输入、选项、,
-->778运行(元数据)
779如果运行\u元数据:
780 proto_data=tf_session.tf_GetBuffer(run_metadata_ptr)
运行中的~/anaconda3/envs/Tensorflow/lib/python3.6/site-packages/Tensorflow/python/client/session.py(self、handle、fetches、feed、dict、options、run\u元数据)
967
968#创建一个获取处理程序来处理获取的结构。
-->969 fetch\u handler=\u FetchHandler(self.\u图形、fetches、feed\u dict\u字符串)
970
971#运行请求并获取响应。
~/anaconda3/envs/Tensorflow/lib/python3.6/site-packages/Tensorflow/python/client/session.py in uuuuu init_uuu(self、graph、fetches、feed)
406     """
407,带有graph.as_default():
-->408 self.\u fetch\u mapper=\u FetchMapper.for\u fetch(fetches)
409 self._fetches=[]
410自我目标=[]
~/anaconda3/envs/Tensorflow/lib/python3.6/site-packages/Tensorflow/python/client/session.py in for_fetch(fetch)
225如果fetch为None:
226 raise TypeError('获取参数%r的类型无效%r'%
-->227(提取,键入(提取)))
228 elif isinstance(获取,(列表,元组)):
229注意(touts):这也是namedtuples的代码路径。
TypeError:获取参数None的类型无效

您没有任何摘要(它们都被注释掉)。在这种情况下,
merge\u all
返回所述的
None
。请在使用
merge\u all
之前添加一些实际摘要