【问题标题】:Keras Cropping2D changes color channelKeras Cropping2D 改变颜色通道
【发布时间】:2017-01-29 20:47:03
【问题描述】:

我尝试使用以下代码 sn-p 可视化 keras 裁剪 2D 的效果:

from keras import backend as K
from keras.layers.convolutional import Cropping2D
from keras.models import Sequential
# with a Sequential model
model = Sequential()
model.add(Cropping2D(cropping=((22, 0), (0, 0)), input_shape=(160, 320, 3)))
cropping_output = K.function([model.layers[0].input],
                                  [model.layers[0].output])
cropped_image = cropping_output([image[None,...]])[0]
compare_images(image,
               cropped_image.reshape(cropped_image.shape[1:]))

这是绘图功能:

def compare_images(left_image, right_image):    
    print(image.shape)
    f, (ax1, ax2) = plt.subplots(1, 2, figsize=(24, 9))
    f.tight_layout()
    ax1.imshow(left_image)
    ax1.set_title('Shape '+ str(left_image.shape),
                  fontsize=50)
    ax2.imshow(right_image)
    ax2.set_title('Shape '+ str(right_image.shape)
                  , fontsize=50)
    plt.show()

结果是

显然,颜色通道已更改。但为什么?我的代码中有错误还是可能是 keras 错误?

【问题讨论】:

  • 你是如何绘制这些图像的?
  • 我将其编辑为原始问题
  • 由于某种原因,matplotlib 有时会拍摄照片的底片而不是原始照片。你能比较两张图片中的实际值并检查它们是否不同吗?

标签: keras keras-layer


【解决方案1】:

这不是 Keras 错误。张量通常是float32 类型,因此在评估输出时,它们也是float32 类型。显示前需要将图片数据转换为uint8类型。

ax2.imshow(np.uint8(right_image))

compare_images 中应该正确显示图像。

【讨论】:

    猜你喜欢
    • 2019-01-02
    • 1970-01-01
    • 1970-01-01
    • 2014-06-07
    • 2014-08-26
    • 2017-06-11
    • 2016-09-03
    • 2022-10-23
    • 1970-01-01
    相关资源
    最近更新 更多