Here,
X_train = 75% of my cancer image data, which has 3 classes.
Y_train = images are labeled as [0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2]
X_test = 25% image of my cancer dataset
results = model.fit(X_train,Y_train, X_test, validation_split=0.1, batch_size=6, epochs=5,
##################################
But getting this errors, which should I pass into model.fit()
TypeError Traceback (most recent call last)
<ipython-input-132-c29910126b61> in <module>()
5 tf.keras.callbacks.TensorBoard(log_dir='logs')]
6
----> 7 results = model.fit(X_train,Y_train, X_test, validation_split=0.1, batch_size=6,
epochs=5, callbacks=callbacks)
8
9 ####################################
1 frames
/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
62 filtered_tb = None
63 try:
---> 64 return fn(*args, **kwargs)
65 except Exception as e: # pylint: disable=broad-except
66 filtered_tb = _process_traceback_frames(e.__traceback__)
TypeError: fit() got multiple values for argument 'batch_size'
CodePudding user response:
The fit method doesn't know what to do with X_test, the validation data needs to be passed explicitly
history = model.fit(
x_train,
y_train,
batch_size=64,
epochs=2,
# We pass some validation for
# monitoring validation loss and metrics
# at the end of each epoch
validation_data=(x_val, y_val),
)
It's good practice to go through the documentation once or twice: Training and evaluation with the built-in methods
CodePudding user response:
If you're going to use validation_split
to create your validation set, it is easier in my experience, if done when you create your data generator.
train_datagen = ImageDataGenerator(validation_split=0.1)
test_datagen = ImageDataGenerator()
You then use your data generator, either with flow
, or flow_from_directory
, using your train data.
train_iter = train_datagen.flow(X_train, Y_train, batch_size=6, subset="training")
val_iter = train_datagen.flow(X_train, Y_train, batch_size=6, subset="validation")
test_iter = test_datagen.flow(X_test, Y_test, batch_size=6, shuffle=False)
Then .fit
your model using train_iter
as x-input and val_iter
as input for validation_data
.
model.fit(train_iter, steps_per_epoch=len(train_iter), validation_data=val_iter, validation_steps=len(val_iter), epochs=5, shuffle=True)
Then use test_iter
to evaluate/predict.
model.evaluate(test_iter, steps=len(test_iter))
model.predict(test_iter, steps=len(test_iter))