Соответствующий код
Не стесняйтесь спрашивать больше, если есть пропущенные части кода.
def get_decoder_layers(char_list, encoder_state=None):
input = layers.Input(shape=(None, len(char_list)))
cells = []
for hidden in [256, 256]:
cells.append(layers.GRUCell(hidden))
decoder = layers.RNN(cells, return_state=True, return_sequences=True)
state = decoder(input, initial_state=encoder_state)
output = state[0] # only get the output
dense = layers.Dense(len(char_list), activation='linear')
output = dense(output)
return input, output, decoder, dense
def get_encoder_layers(char_list):
input = layers.Input(shape=(None, len(char_list)))
cells = []
for hidden in [256, 256]:
cells.append(layers.GRUCell(hidden))
encoder = layers.RNN(cells, return_state=True)
output = encoder(input)
states = output[1:] # get rid of the ouput
return input, states
decoder_input, decoder_output, decoder, dense = m.get_decoder_layers(french_chars)
encoder_input, encoder_states = m.get_encoder_layers(english_chars)
Ошибка здесь:
encoder_inference_model, decoder_inference_model = m.get_inference_models(
encoder_input=encoder_input,
decoder_input=decoder_input,
states=encoder_states,
decoder=decoder,
dense_layer=dense)
def get_inference_models(encoder_input=None, decoder_input=None, states=None, decoder=None, dense_layer=None):
encoder_inference = keras.Model(encoder_input, states)
decoder_state_input_a = layers.Input(shape=(256,)) # these have to be different variables
decoder_state_input_b = layers.Input(shape=(256,))
decoder_output_states = decoder(decoder_input, initial_state=states)
output = decoder_output_states[0] # the first element is the output
decoder_states = decoder_output_states[1:] # the rest are states
output = dense_layer(output)
return encoder_inference, keras.Model(inputs=[decoder_input, decoder_state_input_a, decoder_state_input_b], outputs=[output] + decoder_states) # error is at `keras.Model`
Error
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1664, in <module>
main()
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Users/zoe/Developer/CoreText/Lis/main.py", line 51, in <module>
dense_layer=dense)
File "/Users/zoe/Developer/CoreText/Lis/model.py", line 86, in get_decoder_inference
return encoder_inference, keras.Model(inputs=[decoder_input, decoder_state_input_a, decoder_state_input_b], outputs=[output] + decoder_states)
File "/Users/zoe/Developer/CoreText/Lis/venv/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/Users/zoe/Developer/CoreText/Lis/venv/lib/python2.7/site-packages/keras/engine/network.py", line 93, in __init__
self._init_graph_network(*args, **kwargs)
File "/Users/zoe/Developer/CoreText/Lis/venv/lib/python2.7/site-packages/keras/engine/network.py", line 231, in _init_graph_network
self.inputs, self.outputs)
File "/Users/zoe/Developer/CoreText/Lis/venv/lib/python2.7/site-packages/keras/engine/network.py", line 1443, in _map_graph_network
str(layers_with_complete_input))
ValueError: Graph disconnected: cannot obtain value for tensor Tensor("input_1:0", shape=(?, ?, 31), dtype=float32) at layer "input_1". The following previous layers were accessed without issue: []
Ошибка указывает, что некоторые из моих слоев отключены, но, похоже, все мои слои подключены (за исключением decoder_state_input_a
и decoder_state_input_b
, которые я считаю нормальными).