ProgJ
2018-01-28 03:25
采纳率: 88.1%
浏览 3.9k

tensorflow 灰度化之后shape[]少一维

想把彩色图像灰度化,但是RGB三通道灰度化之后,shape少了一维,feed_dic shape维数不匹配了
Traceback (most recent call last):
File "trainModel.py", line 75, in
kernel_initializer=tf.glorot_normal_initializer())
File "/usr/lib/python2.7/site-packages/tensorflow/python/layers/convolutional.py", line 608, in conv2d
return layer.apply(inputs)
File "/usr/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 671, in apply
return self.__call__(inputs, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 550, in call
self._assert_input_compatibility(inputs)
File "/usr/lib/python2.7/site-packages/tensorflow/python/layers/base.py", line 1044, in _assert_input_compatibility
str(x.get_shape().as_list()))
ValueError: Input 0 of layer conv2d_1 is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: [None, 100, 100]

似乎是因为灰度化操作之后读取的图片数据的通道那一维就没了,有没有办法解决啊,新手不是很懂

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • blownewbee 2018-01-28 08:38

    RGB三通道就是三维,你要转换成ARGB的四通道,才是四维。

    点赞 打赏 评论
  • linhaobo 2018-01-28 09:21

    TF的RGB数据的位置和Theano是不一样的,看看你是不是搞混了

    点赞 打赏 评论
  • 你可以用reshape,比如原来的shape是[10,28,28],reshape后[10,28,8,1]

    点赞 打赏 评论
  • 小宋是呢 2019-11-04 23:00

    使用np.expand_dims增加最后一个纬度。其实np.reshape也是一样的作用,因为前面格式确定了。。

    点赞 打赏 评论

相关推荐 更多相似问题