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

时间:2019-04-10 16:42:15

标签: python tensorflow image-processing pattern-recognition

这与我的问题有关,在这里。

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

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'

我该如何解决这个问题?

谢谢。

1 个答案:

答案 0 :(得分:0)

使用X.shape代替X.input_shapes