Closed DanlanChen closed 7 years ago
Input does not include samples. It is of shape (channels, rows, cols). Can you post a gist of your full code? Its hard to say without looking at it.
def get_chunk(images,tracks,img_rows,img_cols,num_labels): while True: for stepStart in range(len(images)): file = images[stepStart] data = read_h5(file) data = normalize_image(data,mean_v,std_v) data = np.array(data) data = np.reshape(data,(-1,1,img_rows,img_cols))
y = np.reshape(np.array(tracks[stepStart]),(1,num_labels))
# y = tracks[stepStart]
# print y.shape
yield (data,y)
If I do not use fit_generator in training, just use keras fit function to train the whole dataset, it works, and model.predict_generator works well, I do not know why.
def get_test_chunk(images,img_rows,img_cols): while True: for stepStart in range(len(images)): file = images[stepStart] data = read_h5(file) data = normalize_image(data,mean_v,std_v) data = np.array(data) data = np.reshape(data,(-1,1,img_rows,img_cols)) yield data
what does the call to fit_generator look like? The generator needs to return a tuple of (inputs, outputs) not list of tuple (input, output)
def model_training(model,train_generator, validation_generator, img_rows,img_cols,batch_size,nb_epoch,samples_per_epoch,ModelCheckpoint_file):
checkpointer = ModelCheckpoint(filepath=ModelCheckpoint_file, verbose=1, save_best_only=True)
early_stop = EarlyStopping(monitor = 'val_loss', patience = 5, mode = 'min')
hist = model.fit_generator(generator = train_generator,samples_per_epoch=samples_per_epoch, nb_epoch=nb_epoch,callbacks=[checkpointer,early_stop],validation_data= validation_generator, nb_val_samples=6525, nb_worker=10)
# hist = model.fit(train_generator, validation_generator, batch_size=batch_size, nb_epoch=nb_epoch, show_accuracy=True, verbose=1, validation_split=0.1,callbacks=[checkpointer])
print (hist.history)
return hist
can you show the code for train_generator?
closing due to inactivity. Reopen if you are still facing this issue.
Exception: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None Why I am getting this error? But when I am using other models, it does not get the error, the input is (-1,1,224,224) output is (1,8), and I adjust it to the model too.