我在Spyder中使用keras时,不小心更改了core.py文件并对其进行了编译。当然,发生了一些错误。然后我撤消了更改,但是出于某些奇怪的原因,我使用该文件的实际代码给出了以下错误。
File "<ipython-input-18-18c6a7ab4e93>", line 1, in <module>
runfile('F:/Python Codes/HFE/HCM_LSTM_LDA_1.py', wdir='F:/Python Codes/HFE')
File "e:\ProgramData\Anaconda3\lib\site-
packages\spyder_kernels\customize\spydercustomize.py", line 668, in runfile
execfile(filename, namespace)
File "e:\ProgramData\Anaconda3\lib\site-
packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "F:/Python Codes/HFE/HCM_LSTM_LDA_1.py", line 195, in <module>
classifier.add(Dense(1))
File "e:\ProgramData\Anaconda3\lib\site-
packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "e:\ProgramData\Anaconda3\lib\site-packages\keras\layers\core.py", line
844, in __init__
super(Dense, self).__init__(**kwargs)
TypeError: super(type, obj): obj must be an instance or subtype of type
现在我知道我的代码没有问题了,
#...
from keras.layers import Dropout
#...
classifier = Sequential()
classifier.add(LSTM(units = 100, activation = 'relu'))
classifier.add(Dense(1))
classifier.add(Dropout(0.0001));
classifier.add(Dense(1))
classifier.compile(optimizer = 'Nadam', loss ='mean_absolute_percentage_error', metrics = ['accuracy'])
classifier.fit(Feature_train, Label_train, epochs=100, batch_size=168,
verbose=2) #Fit classifier
RNN_Predict=classifier.predict(Feature_test)
我撤消了对core.py文件的更改,但我想解决此问题而不必卸载并重新安装所有内容
答案 0 :(得分:1)
因此,在我用github.com/keras-team/keras/blob/master/keras/layers/core.py中的代码替换了core.py文件的代码后,它起初没有工作,但后来我重新设计的间谍,它奏效了。