AttributeError:“张量”对象没有属性“ _keras_shape”
我正在尝试运行此模型,但是由于基于此错误,我会遇到此错误:
File "C:\ProgramData\Anaconda3\envs\py35\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\envs\py35\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/hendy/Documents/All/LHP_Modell_Control/Validate_Closed_Loop_Controller.py", line 18, in <module>
model = Model_object.structure(nn, depth, 32,inputs)
File "C:\Users\hendy\Documents\All\LHP_Modell_Control\Model_LHP_stateful.py", line 52, in structure
model = Model(inputs=[inp_ext, y_refeed, h_ext, c_ext], outputs=[out, h_out, c_out])
File "C:\ProgramData\Anaconda3\envs\py35\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\envs\py35\lib\site-packages\keras\engine\network.py", line 93, in __init__
self._init_graph_network(*args, **kwargs)
File "C:\ProgramData\Anaconda3\envs\py35\lib\site-packages\keras\engine\network.py", line 247, in _init_graph_network
input_shapes=[x._keras_shape for x in self.inputs],
File "C:\ProgramData\Anaconda3\envs\py35\lib\site-packages\keras\engine\network.py", line 247, in <listcomp>
input_shapes=[x._keras_shape for x in self.inputs],
AttributeError: 'Tensor' object has no attribute '_keras_shape'`enter code here`
我也尝试通过:
进行升级pip3 install --upgrade tensorflow-gpu
and updated keras to 2.2.4
pip install Keras==2.2.4
我知道我们可以在代码中使用两种Keras。 Keras包或仅使用tf.keras。在这段代码中,我使用Keras软件包,即我尝试不混用!如您在代码中所见
import pandas as pds
import numpy as np
from keras.models import Model
from keras.layers import Input
from keras.layers import Dense
from keras.layers import add
from recurrentshop import LSTMCell
from recurrentshop import RecurrentModel
def structure(self, node_number, depth, batch_shape, inputs):
timesteps = self.timesteps
inp_ext = Input(shape=(timesteps, inputs))
y_refeed = Input(shape=(timesteps, inputs))
h_ext = Input(shape=(inputs,))
c_ext = Input(shape=(inputs,))
inp = Input(batch_shape=(batch_shape, inputs))
readout_input = Input(batch_shape=(batch_shape, inputs))
h_tm1 = Input(batch_shape=(batch_shape, inputs))
c_tm1 = Input(batch_shape=(batch_shape, inputs))
lstms_input = add([inp, readout_input])
cells = [LSTMCell(node_number) for _ in range(depth)]
lstms_output = Dense(node_number)(lstms_input)
h = Dense(node_number)(h_tm1)
c = Dense(node_number)(c_tm1)
for cell in cells:
lstms_output, h, c = cell([lstms_output, h, c])
lstms_output = Dense(inputs)(lstms_output)
h = Dense(inputs)(h)
c = Dense(inputs)(c)
y = lstms_output
rnn = RecurrentModel(input=inp, initial_states=[h_tm1, c_tm1], output=y, final_states=[h, c], readout_input=readout_input, return_sequences=True, return_states=True, name="RecurrentModel")
out, h_out, c_out = rnn(inp_ext, ground_truth=y_refeed, initial_state=[h_ext, c_ext])
model = Model(inputs=[inp_ext, y_refeed, h_ext, c_ext], outputs=[out, h_out, c_out])
return model