[英]Keras Error fitting model: Too many elements provided
Goal: Evaluate a set of 5 images and produce an image as the output. 目标:评估一组5个图像并生成图像作为输出。
Problem: I am currently getting an error Too many elements provided. 问题:我目前收到错误提供的元素太多。
Disclaimer: I'm new to Keras and Deep learning as a whole, I fully expect that this approach is wrong but I would like to understand why I'm getting this error 免责声明:我是Keras和Deep学习的新手,我完全相信这种方法是错误的,但我想理解为什么我会收到这个错误
The shape of the output and input look correct to me. 输出和输入的形状对我来说是正确的。
I have tried making the output just a Dense layer with a shape of (None,6912.) 我试过让输出只是一个形状为(无,6912)的密集层。
I have tried having the output be a Conv2d but then I get the following error, I am unsure why the output is (46,46,3) and not (48,48,3) 我试过输出是一个Conv2d然后我得到以下错误,我不确定为什么输出是(46,46,3)而不是(48,48,3)
Error when checking target: expected conv2d_1 to have shape (None, 46, 46, 3) but got array with shape (379, 48, 48, 3)
Code: 码:
width = 48
height = 48
png = []
for image_path in glob.glob(r"D:\temp\*.png"):
png.append(misc.imread(image_path))
im = np.asarray(png)
print ('dataset: ', im.shape)
window = 6
dataset = np.zeros([len(im) - window, window,width,height,3])
for i in range(len(dataset)):
dataset[i, :] = im[i:i + window]
x_train = dataset[:,:-1]
y_train = dataset[:,-1]
y_train1 = y_train.reshape(-1,width*height*3)
print("x_train: ", x_train.shape)
print("y_train:" ,y_train.shape)
print("y_train1:" ,y_train1.shape)
model = Sequential()
model.add(Conv3D(filters=40,
kernel_size=(5,10,10),
input_shape=(5,width,height,3),
padding='same',
activation='relu'))
model.add(Activation('relu'))
model.add(Conv3D(filters=40,
kernel_size=(3,3,3),
padding='same',
activation='relu'))
model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(width * height * 3, activation='softmax'))
model.add(Reshape((48,48,3)))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
print("model Input: " ,model.input_shape)
print("model output:", model.output_shape)
model.fit(x_train, y_train, batch_size=10, epochs=300, validation_split=0.05)
Output: 输出:
Using TensorFlow backend.
dataset: (385, 48, 48, 3)
x_train: (379, 5, 48, 48, 3)
y_train: (379, 48, 48, 3)
y_train1: (379, 6912)
model Input: (None, 5, 48, 48, 3)
model output: (None, 48, 48, 3)
Traceback (most recent call last):
....
File "D:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 424, in make_tensor_proto
(shape_size, nparray.size))
ValueError: Too many elements provided. Needed at most -1109917696, but received 1
Model Summary: 型号摘要:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv3d_1 (Conv3D) (None, 5, 48, 48, 40) 60040
_________________________________________________________________
activation_1 (Activation) (None, 5, 48, 48, 40) 0
_________________________________________________________________
conv3d_2 (Conv3D) (None, 5, 48, 48, 40) 43240
_________________________________________________________________
flatten_1 (Flatten) (None, 460800) 0
_________________________________________________________________
dropout_1 (Dropout) (None, 460800) 0
_________________________________________________________________
dense_1 (Dense) (None, 6912) -110991078
_________________________________________________________________
reshape_1 (Reshape) (None, 48, 48, 3) 0
=================================================================
Thank in advanced. 谢谢高级。
In the Conv2D
case, you've probably forgotten to use padding = 'same'
. 在
Conv2D
案例中,您可能忘记使用padding = 'same'
。 A (3,3) kernel removes 2 pixes in each dimension. (3,3)内核在每个维度中移除2个像素。
And by the negative number of parameters shown in the Dense layer, I believe you've got a model bigger than supported. 通过Dense图层中显示的负数参数,我相信你的模型比支持的更大。
Maybe there is a maximum limit of parameters for a single layer. 也许单层的参数有最大限制。 In that case, I'd reduce the number of filters in the convolutions, or sum the channels before the flatten layer.
在这种情况下,我会减少卷积中的滤波器数量,或者在展平层之前对通道求和。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.