tensorflow中用summary.merge_all 时出现 Nontype问题
来源:互联网 发布:ps在mac上如何下载 编辑:程序博客网 时间:2024/05/16 18:15
我用的是python3.5,tensorflow版本是1.4。
错误的意思,是在运行 summary_str = sess.run(summary_op) 时,summary_op没有被定义。
但是我在前面妥妥的加了summary_op = tf.summary.merge_all()这句话,当我调试的时候,发现summary_op真的是Nonetype,这问题就很奇怪,折磨了我好久。
后来我就换了一种数据传递的方式:
一开始,我用的是placeholder + feed_dict的方式,summary_op一直都显示没有被定义
然后,我改成了直接传入数据的方式,就没有问题了(见下面代码)
说来很玄学。。。可能是tensorflow更新太快的缘故吧
代码很简单,放出正确的代码
import tensorflow as tfimport numpy as npimport pandas as pdimport oslr =0.001batch_size = 32capacity = 2000MAX_STEP = 100000#获取一批数据def get_batch(data, label): data = tf.cast(data, tf.float32) label = tf.cast(label, tf.float32) input_queue = tf.train.slice_input_producer([data, label])#input_queue是大小为2的list label = input_queue[1] data = input_queue[0] data_batch, label_batch = tf.train.batch([data, label], batch_size= batch_size, num_threads= 64, capacity = capacity) return data_batch, label_batchdef add_layer(inputs, in_size, out_size, activation_function=None,norm = False): with tf.name_scope('layer'): with tf.name_scope('weights'): Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='W') with tf.name_scope('biases'): biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b') with tf.name_scope('Wx_plus_b'): Wx_plus_b = tf.add(tf.matmul(inputs, Weights), biases) if activation_function is None: outputs = Wx_plus_b else: outputs = activation_function(Wx_plus_b, ) return outputs
data = pd.read_csv("data.csv")label = pd.read_csv("label.csv")data = np.array(data)label = np.array(label)s= data.shapeinput_size = s[1]with tf.name_scope('inputs'): data_batch,label_batch = get_batch(data, label)# define placeholder for inputs to network#with tf.name_scope('inputs'):# xs = tf.placeholder(tf.float32, [None, input_size])# ys = tf.placeholder(tf.float32, [None, 1])# add hidden layerl1 = add_layer(data_batch, input_size, 2*input_size, activation_function= tf.nn.relu,norm = True)l2 = add_layer(l1,2*input_size,2*input_size, activation_function= tf.nn.relu,norm = True)l3 = add_layer(l2,2*input_size,input_size, activation_function= tf.nn.relu,norm = True)l4 = add_layer(l3,input_size,int(input_size/2), activation_function= tf.nn.relu,norm = True)l5 = add_layer(l4,int(input_size/2),int(input_size/4), activation_function= tf.nn.relu,norm = True)# add output layerprediction = add_layer(l5,int(input_size/4),1, activation_function= None)with tf.name_scope('loss'): loss = tf.reduce_mean(tf.reduce_sum(tf.square(tf.subtract(label_batch,prediction)), reduction_indices=[1]))with tf.name_scope('train'): train_op = tf.train.AdamOptimizer(lr).minimize(loss)summary_op = tf.summary.merge_all()sess = tf.Session()init = tf.global_variables_initializer()writer = tf.summary.FileWriter(logs_train_dir, sess.graph)saver = tf.train.Saver()sess.run(init)for step in np.arange(MAX_STEP): _,train_loss = sess.run([train_op,loss]) if step % 2000 == 0: summary_str = sess.run(summary_op) writer.add_summary(summary_str,step) print('loss: ', train_loss)
在上述代码中
阅读全文
0 0
- tensorflow中用summary.merge_all 时出现 Nontype问题
- tensorflow学习笔记(二十九):merge_all引发的血案
- TensorBoard tf.summary.merge_all() AttributeError: 'NoneType' object has no attribute 'bucket 错误
- spring中用@responsebody返回json时出现乱码问题
- Tensorflow中用VGG19做二分类-loss出现0.693174解决方法
- 安装tensorflow+1050,运行import tensorflow出现问题
- tensorflow训练中出现nan问题
- Spyder中import tensorflow出现问题
- window配置TensorFlow-gpu版本出现问题
- 集群配置tensorflow出现的问题汇总
- tensorflow训练中出现nan问题
- 解决domino 中用ajax 时 send的中文参数出现乱码问题
- 在myeclipse中用maven进行项目的打包时出现内存泄露问题
- Tensorflow中用VGG19做二分类loss出现0.693174解决方法2
- sqlserver中用了user关键子出现的问题
- win7中用 httplistener 出现 503 错误的问题
- 在android中用eventBus.2.4.jar中出现的问题
- MFC中用CFtpFileFind去遍历目录出现问题
- 数学问题合集
- 防火墙
- Git shell 命令大全
- 新华三的前世今生
- 面试涉及的框架与设计模式
- tensorflow中用summary.merge_all 时出现 Nontype问题
- C基礎
- Python数据结构之二叉树(涵盖了构建、删除、查找、字典转换、非递归与递归遍历等)
- 微信支付生成二维码方法封装
- 获取时间日期函数整理(部分来源于网络)
- PAT 甲级 1132. Cut Integer (20)
- 初识大数据
- 使用boot2docker管理Docker
- SpringCloud之Ribbon+Rest调用负载均衡