ValueError:检查输入时出错:预期input_1具有形状(None,65563),但数组的形状为(374,65536) [英] ValueError: Error when checking input: expected input_1 to have shape (None, 65563) but got array with shape (374, 65536)

查看:213
本文介绍了ValueError:检查输入时出错:预期input_1具有形状(None,65563),但数组的形状为(374,65536)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Keras编写的自动编码器,如下所示.我收到以下错误,并且不确定如何解决,有什么想法吗?

I have an autoencoder written in Keras shown below. I'm getting the following error, and not sure how to solve it, any ideas?

ValueError:检查输入时出错:预期input_1具有形状 (无,65563),但数组的形状为(374,65536)

ValueError: Error when checking input: expected input_1 to have shape (None, 65563) but got array with shape (374, 65536)

from keras.layers import Input, Dense, Flatten
from keras.models import Model
from keras.preprocessing.image import img_to_array
import cv2
import numpy
import os

training_directory = '/training'
validation_directory ='/validation'
results_directory = '/results'
training_images = []
validation_images = []

# the size of the encoded represenatation
encoding_dimension = 784
# input placeholder
input_image = Input(shape=(65563,))
# the encoded representation of the input
encoded = Dense(encoding_dimension,activation='relu')(input_image)
# reconstruction of the input (lossy)
decoded = Dense(65563,activation='sigmoid')(encoded)
# map the input image to its reconstruction
autoencoder = Model(input_image,decoded)

# encoder model
# map an input image to its encoded representation
encoder = Model(input_image,encoded)

# decoder model

# place holder fpr an encoded input
encoded_input = Input(shape=(encoding_dimension,))
# retrieve the last layer of the autoencoder model
decoder_layer = autoencoder.layers[-1]
# create the decoder model
decoder = Model(encoded_input,decoder_layer(encoded_input))

for root, dirs, files in os.walk(training_directory):
    for file in files:
        image = cv2.imread(root + '/' + file)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        image = img_to_array(image)
        training_images.append(image)

training_images = numpy.array(training_images)

for root, dirs, files in os.walk(validation_directory):
    for file in files:
        image = cv2.imread(root + '/' + file)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        image = img_to_array(image)
        validation_images.append(image)

validation_images = numpy.array(validation_images)

# reshape data
training_images = training_images.reshape((len(training_images), numpy.prod(training_images.shape[1:])))
validation_images = validation_images.reshape((len(validation_images), numpy.prod(validation_images.shape[1:])))

autoencoder.compile(optimizer='adam',loss='binary_crossentropy')

autoencoder.fit(training_images,epochs=10,batch_size=20,shuffle=True,validation_data=(validation_images))

encoded_images = encoder.predict(validation_images)
decoded_images = decoder.predict(encoded_images)

谢谢.

推荐答案

65563而不是65536可能是造成此问题的错字.

Writing 65563 instead of 65536 might have been a typo causing the issue.

这篇关于ValueError:检查输入时出错:预期input_1具有形状(None,65563),但数组的形状为(374,65536)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆