What should the generator return if it is used in a multi-input/output Keras model built with functional API?

后端 未结 1 1456
小蘑菇
小蘑菇 2020-12-22 11:10

Following this article, I\'m trying to implement a generative RNN. In the mentioned article, the training and validation data are passed as fully loaded np.array

相关标签:
1条回答
  • 2020-12-22 11:58

    Since your model has two inputs and one output, the generator should return a tuple with two elements where the first element is a list containing two arrays, which corresponds to two input layers, and the second element is an array corresponding to output layer:

    def generator():
        ...
        yield [input_samples1, input_samples2], targets
    

    Generally, in a model with M inputs and N outputs, the generator should return a tuple of two lists where the first one has M arrays and the second one has N arrays:

    def generator():
            ...
            yield [in1, in2, ..., inM], [out1, out2, ..., outN]
    

    If instead of a Python generator, an instance of Sequence class is used to generate data, the format is the same with the only difference that you would use return instead of yield in the __getitem__ method.

    0 讨论(0)
提交回复
热议问题