【发布时间】: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