keras-team / keras-tuner

A Hyperparameter Tuning Library for Keras
https://keras.io/keras_tuner/
Apache License 2.0
2.86k stars 397 forks source link

Error when tuning with Recall as metric for multi-class problem #289

Open rsd96 opened 4 years ago

rsd96 commented 4 years ago

I am trying to fine-tune resnet for multi-class problem. Since my dataset is very unbalanced I would like to use recall as my metric. However, it does not seems to work...

`from kerastuner.applications import HyperResNet from kerastuner.tuners import RandomSearch, Hyperband from kerastuner import Objective

hypermodel = HyperResNet(input_shape=(IMG_SIZE, IMG_SIZE, 3), classes=8)

Tuner

tuner = RandomSearch( hypermodel, metrics=[tf.keras.metrics.Precision(name='specificity'), tf.keras.metrics.Recall(name='sensitivity')], objective= Objective("val_sensitivity", direction="max"), max_trials=10, tune_new_entries=True, executions_per_trial=1, directory='FineTune/Resnet', project_name='Resnet_Lesion_8_1')

Search

tuner.search(train_generator, verbose = 1, epochs=100, shuffle=True, validation_data=val_generator)`

This gives me the error:

Shapes (None, 8) and (None, 1) are incompatible

yixingfu commented 4 years ago

Is error still happening? Can you provide a bit more detail on how you prepare your input? What are the shapes of your data? I cannot reproduce the error using some other example datasets I have.