為什麼要使用reshape
2019/09/08 下午 09:05
機器學習共學討論版
蕭琮寶
觀看數:52
回答數:2
收藏數:0
ml100-2-d96
ml100-2
if K.image_data_format() == 'channels_first':
x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)
x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)
input_shape = (1, img_rows, img_cols)
else:
x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
input_shape = (img_rows, img_cols, 1)
請問老師範例這一段為甚麼要reshape我不太懂
回答列表
-
2019/09/09 上午 10:51張維元 (WeiYuan)贊同數:1不贊同數:0留言數:0
把 x_train 跟 x_test 調整成原始 img 的 row & col
-
2019/09/09 下午 11:01Seanyu.TW贊同數:1不贊同數:0留言數:0
應該是因為預設的資料格式為 (N, 784),所以為了要餵給 CNN, 需要為 (N, H, W, C) 格式或是 (N, C, H, W) 格式,所以才需要做 reshape