Когда я запускаю функцию «crossover_rnn», программа сообщает об ошибке. Это из-за слишком высокой версии keras?
Traceback (most recent call last):
File "E:/chauncey/ensemble-time-series-master/Ensemble.py", line 631, in <module>
main()
File "E:/chauncey/ensemble-time-series-master/Ensemble.py", line 621, in main
evaluate_ga(datasets[0])
File "E:/chauncey/ensemble-time-series-master/Ensemble.py", line 547, in evaluate_ga
new_rnn_model = crossover_rnn(rnn_model_1, rnn_model_2)
File "E:/chauncey/ensemble-time-series-master/Ensemble.py", line 287, in crossover_rnn
new_model.layers = cross_layers
File "D:\ProgramData\Anaconda3\lib\site-packages\keras\engine\network.py", line 316, in __setattr__
super(Network, self).__setattr__(name, value)
AttributeError: can't set attribute
Предварительные условия:
Python: 3.6.5
Keras: 2.2.4
Tensorflow: 1.5.0
Функция «crossover_rnn» использует Генетический алгоритм для создания скрытого слоя после кроссовера, но при копировании происходит сбой..
def crossover_rnn(model_1, model_2):
"""
Executes crossover for the RNN in the GA for 2 models, modifying the first model
:param model_1:
:param model_2:
:return:
"""
# new_model = copy.copy(model_1)
new_model = model_1
...
# Add input layer randomly from parent 1 or parent 2
bit_random = random.randint(0, 1)
if bit_random == 0:
cross_layers.insert(0, model_1.layers[0])
else:
cross_layers.insert(0, model_2.layers[0])
bit_random = random.randint(0, 1)
if bit_random == 0:
cross_layers.append(model_1.layers[len(model_1.layers) - 1])
else:
cross_layers.append(model_2.layers[len(model_2.layers) - 1])
# Set new layers
new_model.layers = cross_layers
return new_model