Python - AttributeError:'numpy.ndarray'对象没有属性'input_shapes'

问题描述 投票:-2回答:1

这与我的问题有关。

我现在有更新的代码如下:

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D
import pickle

X = pickle.load(open("X.pickle","rb"))
y = pickle.load(open("y.pickle","rb"))

X = X/255.0;

model = Sequential()
model.add(Conv2D(64,(3,3),input_shape = X.input_shape[:1]))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2,2)))

model.add(Conv2D(64),(3,3))
model.add(Activation("relu"))
model.add(MaxPooling2D(pool_size = (2,2)))

model.add(Flatten())
model.add(Dense(64))

model.add(Activation("sigmoid"))

model.compile(loss="binary_crossentropy",
              optimizer = "data",
              metrics=['accuracy'])
model.fit(X,y,batch_size = 32, validation_split = 0.1)

当我尝试训练我的程序时,我收到此错误,但实际结果将开始训练我的数据。

Traceback (most recent call last):
  File "intermediate.py", line 12, in <module>
    model.add(Conv2D(64,(3,3),input_shape = X.input_shapes[:1]))
AttributeError: 'numpy.ndarray' object has no attribute 'input_shapes'

我该如何解决这个问题?

谢谢。

python tensorflow image-processing pattern-recognition
1个回答
0
投票

使用X.shape而不是X.input_shapes

© www.soinside.com 2019 - 2024. All rights reserved.