【Tensorflow】报错的坑--could not broadcast input array from shape (100,784) into shape (100)
来源:互联网 发布:交警网络执法直播流程 编辑:程序博客网 时间:2024/06/05 03:27
用tensorflow实现自编码机的时候,关于batch的选择,一直报错:
ValueError: could not broadcast input array from shape (100,784) into shape (100)
定位代码:
batch_test_x = mnist.train.next_batch(batch_size)可以看到是因为选取数据集时出了问题
在训练的时候,需要选择合适batch的数据集训练,有两种正确的选取方法:
方法一:使用mnist.train.next_batch(batch_size)
在使用mnist.train.next_batch(batch_size)方法选择batch的时候,一定要注意正确的代码是:batch_test_x, batch_test_y= mnist.train.next_batch(batch_size)
数据集和标签一定要同时选择,可以只将batch_test_x丢进自编码机中训练:cost,_ = sess.run([cost,optimizer],feed_dict={x:batch_test_x})
方法二:使用自定义函数随机选择数据集的范围
代码为:这时候,就可以将batch_test_x丢进自编码机训练了def get_random_block_from_data(data, batch_size): start_index = np.random.randint(0, len(data) - batch_size ) return data[start_index:(start_index + batch_size)]batch_test_x = get_random_block_from_data(x_train, batch_size)c,_ = sess.run([cost,optimizer],feed_dict={x:batch_test_x})方法三:batch = mnist.train.next_batch(50)avg_acc = sess.run(accuracy, feed_dict={x: batch[0], y: batch[1], keep_prob: 1.0})
阅读全文
0 0
- 【Tensorflow】报错的坑--could not broadcast input array from shape (100,784) into shape (100)
- ValueError: could not broadcast input array from shape (300,2,300,1) into shape (300,2,1,1)
- tensorflow的shape问题
- 【边喝caffee边Caffe 】(二)python版本的报错:Mean shape incompatible with input shape
- 关于hibernate总是报错 配置factory的id找不到,mapping配置文件Could not parse mapping document from input stream
- tensorflow中获取shape的方法比较
- array shape输出数组的行列
- tensorflow报错:Shape must be rank 2 but is rank 3 for 'MatMul' (op: 'MatMul')
- tensorflow报错:Shape must be rank 2 but is rank 3 for 'MatMul' (op: 'MatMul')
- python array.shape
- shape
- Shape
- shape
- shape
- Shape
- shape
- shape
- shape
- 字符串转换算法
- 【分布式】--消息kafka保证消顺序一致性(358)
- python实现静态变量
- LINUX下分区命令Parted详解
- jQuery的事件方法参考手册
- 【Tensorflow】报错的坑--could not broadcast input array from shape (100,784) into shape (100)
- form表单中的input有哪些类型及其用途
- L9 Linux特殊权限set_uid,set_gid,stick_bit,软链接和硬连接文件
- Java创建类的对象时遇到的问题1:Scanner输出输入的字符串
- @PathVariable和@RequestParam的区别【2全面版】
- Jenkins + Gradle + SonarQube 项目持续集成并分析环境搭建
- Dynamic loading in embedded sytem
- 迭代器、生成器
- 十个值得一试的开源深度学习框架