0

i tried to make a training model with multiple inputs and outputs.

This model worked very well with single input and output but i got an error message.

AttributeError: 'numpy.ndarray' object has no attribute 'strip'

I guess the problem is that the fit_generator can't process the numpy array.

my fit generator looks like that:

def train_model(model, X_train, X_valid, y_train, y_valid):
    """
    Train the model
    """

    checkpoint = ModelCheckpoint('model-{epoch:03d}-Hunet-LSTM-Canny_Final_bc50.h5',
                                 monitor='val_loss',
                                 verbose=0,
                                 save_best_only=True,
                                 mode='auto')


    model.compile(loss='mse', optimizer=Adam(lr=0.0001))
    X=X_train
    print(X)
    y=y_train
    print(y)

    history = model.fit_generator(batcher(data_dir, X_train, y_train, batch_size, True),
                        samples_per_epoch,
                        nb_epoch,
                        max_q_size=1,
                        validation_data=batcher(data_dir, X_valid, y_valid, batch_size, False),
                        nb_val_samples=len(X_valid),
                        callbacks=[checkpoint],
                        verbose=1)

and the results of the Print(X_train)

[['images/photo6190.jpg' 0.119999997318]
 ['images/photo8791.jpg' 0.10000000149]
 ['images/photo12711.jpg' 0.060000006109499994]
 ...
 ['images/photo9846.jpg' 0.0700000077486]
 ['images/photo10800.jpg' 0.109999999404]
 ['images/photo2733.jpg' 0.10000000149]]

and print(y_train)

[[ 0.20000002  0.12      ]
 [ 0.30000001  0.1       ]
 [-0.19999999  0.06000001]
 ...
 [ 0.30000001  0.07000001]
 [ 0.5         0.11      ]
 [ 0.40000001  0.1       ]]

Any idea to fixing it?

You Hur
  • 35
  • 1
  • 7
  • Your `X_train` is an array with the first column being file names, and the second some number. Does that make sense? Are you looking for some pattern/fit in the names? – hpaulj Nov 29 '19 at 17:33
  • It totally makes sense because the first column on Input and Ouput was that i used and worked fine. I added the second columns on boths – You Hur Nov 29 '19 at 18:13

1 Answers1

0

From the docs, you cannot simply pass a numpy array in the fit_generator() function. As the name suggests fit_generator() takes in a python generator as an argument. You can use the Keras ImageDataGenerator() generator function to get a generator or you can make your own custom generator function which yields your x and y training pairs

This sample example might help: https://keras.io/examples/cifar10_cnn/

techytushar
  • 673
  • 5
  • 17
  • In your example they used also fit generator with Data generator. I have a batch_generator which works like Data generator. So u mean i have to correct the batch generator in which i let generate data? – You Hur Nov 29 '19 at 16:01