【发布时间】:2021-08-28 02:19:23
【问题描述】:
此论坛上已发布并回答了与此类似的问题,但这个特殊情况我没有找到任何解决方案。 (我正在使用 Keras)
我有 (150,75,3) 形状的图像,我将 numpy 数组重新整形为 (1,150,75,3)
这应该可以工作,但出现了这个错误:
ValueError: Error when checking input: expected conv2d_input to have 4 dimensions, but got array with shape (1, 1, 1, 150, 75, 3)
编辑:这就是我处理图像的方式:
self.pinballEnvironmrnt = PinballEnv(self.screenDimensions,self.startPosition)
image = pygame.surfarray.array3d(self.pinballEnvironmrnt.screen)
#image = Image.fromarray(image)
#image = image.resize(self.resize)
self.state = numpy.array([image])#.reshape((-1,1200,600,3))
print('the shape of the state ------------------> ',self.state.shape)
pool_size = (2, 2)
# MODEL 1
self.model = Sequential()
self.model.add(Conv2D(4, (3, 3),input_shape=(150,75,3),activation='relu'))
# Conv Layer 2
self.model.add(Conv2D(8, (3, 3),activation='relu'))
# Pooling 1
self.model.add(MaxPooling2D(pool_size=pool_size))
self.model.add(Flatten())
self.model.add(Dense(128,activation='relu'))
self.model.add(Dense(64,activation='relu'))
self.model.add(Dense(16,activation='relu'))
self.model.add(Dense(actions,activation='linear'))
print(self.model.summary())
【问题讨论】:
-
请在您创建输入的地方添加代码并定义您的模型,否则只有一些随机猜测。
-
好的,我添加了代码,我希望现在问题更清楚了
-
仍不清楚。当您向
model.fit()提供输入时会引发错误。所以,你应该添加这一行。还有model.compile()以及您在哪里准确定义和重塑您的输入。您添加了一些代码,将数组重塑为(1,1200,600,3),但您的错误是关于形状为(1,150,75,3)的数组。
标签: python keras conv-neural-network dqn