keras-team/keras-tuner

Stop searching after raising Skip Oversized model error

Opened this issue · 1 comments

Describe the bug

I have developed a code for searching different CNN models with a specific number of parameters, however after an architecture sampled during the optimization that exceeds the number of parameters, it stops searching by raising an error of "Oversized model: 180376 parameters. Skip model."

Expected behavior

It should skip that specific model and takes the second sample until it finishes the maximum number of trials.

Same here. I made a small work-around technique.

I am not familiar with Github, but basically this is what I made, it worked fine :)

I made a small variable outside get_model.

__run_once = True

This is the code, hope it will help!

__run_once = True   # set this True, if the code suddenly stops after at least one tuning you need to edit it and set it to False 

def get_model(args, hp):
    global __run_once 

    trial_param1 = hp.Int("num_layers", 1, 30, step=1)
    trial_param2 = hp.Choice("num_filters", [16, 32, 64])  
    trial_param3 = hp.Choice("dp_rate1", [0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
    trial_param4 = hp.Choice("dp_rate2", [0.0, 0.1, 0.2, 0.3, 0.4, 0.5])
    trial_param5 = hp.Boolean("use_bias")

    m = build_model_with_params(args, trial_param1, trial_param2, trial_param3, trial_param4, trial_param5)

    if __run_once:
       __run_once = False
       return None
   
    return m