Tensorflow中踩过的坑

1.程序报错:feed的值不能是一个tensor,只能是标量、字符串、列表、数组等,所以不能用tf.reshape, 应该使用np.reshape。

    with tf.Session() as sess:
        tf.global_variables_initializer().run()
        v_x = tf.reshape(mnist.validation.images, [mnist.validation.num_examples, 28, 28, 1])
        t_x = tf.reshape(mnist.test.images, [mnist.test.num_examples, 28, 28, 1])
        validate_feed = {x: v_x, y: mnist.validation.labels}
        test_feed = {x: t_x, y: mnist.test.labels}

TypeError: The value of a feed cannot be a tf.Tensor object. 
Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.

2.pool_shape的第一维是None,这是为了便于调整batch大小,但是这样的话tf.reshape无法将输出的矩阵转换为向量。可以直接使用slim.flatten()函数进行转换,不需要读取shape的大小。

# 将输出矩阵拉伸成一个向量
    pool_shape = pool2.get_shape().as_list()    # 只有tensor能用get_shape,as_list将元组转换为列表
    nodes = pool_shape[1]*pool_shape[2]*pool_shape[3]
    reshaped = tf.reshape(pool2, [pool_shape[0], nodes])

TypeError: Failed to convert object of type <class 'list'> to Tensor.
    pool_shape = pool2.get_shape().as_list()   
    nodes = pool_shape[1]*pool_shape[2]*pool_shape[3]
    reshaped = tf.contrib.slim.flatten(pool2)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值