简体   繁体   English

如何从我不小心更改的keras.layers恢复core.py文件

[英]How to restore core.py file from keras.layers that I accidentally changed

I was working with keras in Spyder and I accidentally changed the core.py file and compiled it. 我在Spyder中使用keras时,不小心更改了core.py文件并进行了编译。 Of course, some errors occurred. 当然,发生了一些错误。 Then I reversed the changes but for some odd reasons my actual code that uses the file is giving the following error. 然后,我撤消了更改,但是出于某些奇怪的原因,使用该文件的实际代码给出了以下错误。

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

Now I know there is no problem in my code which is: 现在我知道我的代码没有问题了:

#...
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) 

And I reversed the changes i made to core.py file but i want to tackle this problem without having to uninstall and reinstall everything 我撤消了对core.py文件的更改,但是我想解决此问题而不必卸载并重新安装所有内容

因此,在我用github.com/keras-team/keras/blob/master/keras/layers/core.py中的代码替换了core.py文件中的代码后,它起初没有工作,但随后我重新声明了spyder和有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM