简体   繁体   中英

fit_generator() in keras model

def Generate():
i = 0

while 1:
    i = i%int(Numb/batch_size) 
    my_input_batch = my_input[i*batch_size : (i+1)*batch_size]
    my_output_batch = my_output[i*batch_size : (i+1)*batch_size]
    encoder_input_data = np.array(np.zeros((batch_size, max_encoder_text_length, num_dictonary),dtype='float32'))
    decoder_input_data = np.array(np.zeros((batch_size, max_decoder_text_length, num_dictonary),dtype='float32'))
    decoder_target_data = np.array(np.zeros((batch_size, max_decoder_text_length, num_dictonary),dtype='float32'))

    for i, (text_input, text_output) in enumerate(zip(my_input_batch, my_output_batch)):
        for t, word in enumerate(my_input_batch):
            encoder_input_data[i, t, word] = 1.
        for t, word in enumerate(my_output_batch):
            decoder_input_data[i, t, word] = 1.
            if t > 0:
                decoder_target_data[i, t - 1, word] = 1.
    i = i + 1     
    yield ({encoder_input_data, decoder_input_data}, {decoder_target_data})

I would like to train my model with fit_generator() in Keras. But when I start train I get mistakes:

File "test.py", line 146, in Generate yield ({encoder_input_data, decoder_input_data}, {decoder_target_data}) 
TypeError: unhashable type: 'numpy.ndarray'

How I can solve this problem? What I do wrong?

This particular statement {encoder_input_data, decoder_input_data}, {decoder_target_data} is creating a set out of numpy array. That operation is not possible.

May be you would like to change that statement to

yield ((encoder_input_data, decoder_input_data), (decoder_target_data))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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