AttributeError: 'tuple' object has no attribute 'rank' when calling fit on a Keras model with custom generator

后端 未结 1 963
孤独总比滥情好
孤独总比滥情好 2021-01-21 18:48

I want to build a Neural Network with two inputs: for image data and for numeric data. So I wrote custom data generator for that. The train and validation

相关标签:
1条回答
  • 2021-01-21 19:35

    You need to convert all the individual objects returned by both the training and validation generators to Numpy arrays:

        yield [np.array(imgs), np.array(cols)], np.array(targets)
    

    Alternatively, a simpler and much more efficient solution is to not iterate over the data batch at all; instead, we can take advantage of the fact that these objects are already Numpy arrays when returned by ImageDataGenerator, so we can write:

        imgs = data[0]
        cols = data[1][:,:-1]
        targets = data[1][:,-1:]
        yield [imgs, cols], targets
    
    0 讨论(0)
提交回复
热议问题