我正在尝试实现Keras中的here模型。我或多或少认为Keras模型相当于:
inputShape = (32, 640, 3)
model = Sequential()
model.add(Conv2D(NC//2, kernel_size=(4,4), strides=(2,2), kernel_regularizer=regularizers.l2(1e-5), activation='relu', padding='same', input_shape=inputShape))
model.add(Conv2D(NC, kernel_size=(4,4), strides=(2,1), activation='relu', kernel_regularizer=regularizers.l2(1e-5), padding='same'))
model.add(Conv2D(NC, kernel_size=(8,5), strides=(8,5), activation='relu', kernel_regularizer=regularizers.l2(1e-5), padding='same'))
model.add(Reshape((-1, MAX_CHAR, NC)))
训练数据由5000、32x640个随机生成的字符串图像组成,并分成两个数组,输入A
和输出Y
A
是图像的矩阵(NIMG, Height, Width, Channel)
Y
是字符矩阵(NIMG, MAX_CHAR)
MAX_CHAR
是图像中的最大字符数,在本例中为64。NC
是可能的不同字符数,在本例中为63
问题是,当我运行model.fit(A, Y)
时,我得到:
ValueError: Error when checking target: expected reshape_1 to have 4 dimensions, but got array with shape (5001, 64)
这是有道理的,就像在博客上说的:
the target matrix is a 3D matrix with the three dimensions corresponding to sample, character, and 1-hot encoding respectively.
我试过model.Flatten()
,但这给我留下了一个形状(4032,)
,比训练数据中的64个字符大得多。我也尝试过使用重塑向量值,但没有真正的效果
所以我的问题是:我做错什么了吗?是有什么我根本误解的地方,还是有什么我似乎想不出/找不到的解决办法
显然,正如在评论中提到的,一个热编码标签(即
Y
)解决了这个问题注意:这个答案作为社区wiki发布,如"Question with no answers, but issue solved in the comments (or extended in chat)"的accepted answer所示
相关问题 更多 >
编程相关推荐