AttributeError: 'Sequential' object has no attribute 'score'
AttributeError: 'Sequential' object has no attribute 'score'
我正在使用卷积神经网络,而在使用顺序时我遇到了训练数据的问题。使用顺序是不可能获得最高分的吗??
from numpy import array
from numpy import reshape
import numpy as np
def model_CNN(X_train,Y_train,X_test,Y_test):
model = Sequential()
model.add(Conv1D(filters=512, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu', input_shape=(256, 1)))
model.add(Conv1D(filters=512, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Dropout(0.2)) # This is the dropout layer. It's main function is to inactivate 20% of neurons in order to prevent overfitting
model.add(Conv1D(filters=256, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Dropout(0.2))
model.add(Conv1D(filters=256, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Flatten())
optimizer = keras.optimizers.SGD(lr=0.01, momentum=0.5)
model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
convolutional_model = model.fit(X_train, Y_train, epochs=5,batch_size=64,verbose=1, validation_data=(X_test, Y_test))
print(convolutional_model.score(X_train,Y_train))
model.summary()
return model
回溯收到错误:
AttributeError Traceback (most recent call last)
<ipython-input-50-9a2005301144> in <module>()
1
----> 2 convolutional_model= model_CNN(X_train,Y_train,X_test,Y_test)
3 print(convolutional_model)
<ipython-input-49-bac0ec08f100> in model_CNN(X_train, Y_train, X_test, Y_test)
34 model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
35 convolutional_model = model.fit(X_train, Y_train, epochs=5,batch_size=64,verbose=1, validation_data=(X_test, Y_test))
---> 36 print(convolutional_model.score(X_train,Y_train))
37 # Print the summary of the model
38 model.summary()
AttributeError: 'Sequential' object has no attribute 'score'
由于我是python的新手,我很困扰并检查了各种资源,但没有任何帮助,请指导我...
我从这一行得到了错误
print(convolutional_model.score(X_train,Y_train))
如果不可能,请指导我做一个更好的...
您应该使用 model
而不是 convolutional_model
对象。 fit
函数 returns 一个历史对象,它包含一些关于训练阶段的信息,如损失、准确性。这取决于你的损失函数和度量函数。
你能试试这个吗?
print(model.evaluate(X_train, Y_train))
我正在使用卷积神经网络,而在使用顺序时我遇到了训练数据的问题。使用顺序是不可能获得最高分的吗??
from numpy import array
from numpy import reshape
import numpy as np
def model_CNN(X_train,Y_train,X_test,Y_test):
model = Sequential()
model.add(Conv1D(filters=512, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu', input_shape=(256, 1)))
model.add(Conv1D(filters=512, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Dropout(0.2)) # This is the dropout layer. It's main function is to inactivate 20% of neurons in order to prevent overfitting
model.add(Conv1D(filters=256, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Dropout(0.2))
model.add(Conv1D(filters=256, kernel_size=32, padding='same', kernel_initializer='normal', activation='relu'))
model.add(Flatten())
optimizer = keras.optimizers.SGD(lr=0.01, momentum=0.5)
model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
convolutional_model = model.fit(X_train, Y_train, epochs=5,batch_size=64,verbose=1, validation_data=(X_test, Y_test))
print(convolutional_model.score(X_train,Y_train))
model.summary()
return model
回溯收到错误:
AttributeError Traceback (most recent call last)
<ipython-input-50-9a2005301144> in <module>()
1
----> 2 convolutional_model= model_CNN(X_train,Y_train,X_test,Y_test)
3 print(convolutional_model)
<ipython-input-49-bac0ec08f100> in model_CNN(X_train, Y_train, X_test, Y_test)
34 model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
35 convolutional_model = model.fit(X_train, Y_train, epochs=5,batch_size=64,verbose=1, validation_data=(X_test, Y_test))
---> 36 print(convolutional_model.score(X_train,Y_train))
37 # Print the summary of the model
38 model.summary()
AttributeError: 'Sequential' object has no attribute 'score'
由于我是python的新手,我很困扰并检查了各种资源,但没有任何帮助,请指导我... 我从这一行得到了错误
print(convolutional_model.score(X_train,Y_train))
如果不可能,请指导我做一个更好的...
您应该使用 model
而不是 convolutional_model
对象。 fit
函数 returns 一个历史对象,它包含一些关于训练阶段的信息,如损失、准确性。这取决于你的损失函数和度量函数。
你能试试这个吗?
print(model.evaluate(X_train, Y_train))