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

How to pass tuple in hp.Choice #388

Open msaad1311 opened 4 years ago

msaad1311 commented 4 years ago

I am building a ConvLSTM2D for time series prediction and in that i need to check the results on kernel_size (1,3) and (1,5)but i found out that the hp.Choice doesnt allow that. Is there any other way this can be done? I tried looking over the documentation but couldnt find anything that can help.

Looking forward to hear from you soon. Thanks

yixingfu commented 4 years ago

You can use a string (hp.Choice('kernel_size', ['(1, 3)', '(1, 5)']) ) and parse it, or only make the choice on the particular elements of the tuple (hp.Choice('kernel_size_1', [3, 5])).

yixingfu commented 4 years ago

@omalleyt12 @haifeng-jin Is there a reason for not supporting tuples?

msaad1311 commented 4 years ago

@yixingfu i cant pass hp.Choice('Kernel_size_1',[3,5])as that would generate the kernel size of 3x3and 5x5whereas, i want to generate the kernels of 1x3 and 1x5. I will, however, try passing as a string but will it work since wouldnt that be considered a string in the ConvLSTM2Dparameter?

Furthermore, is there any other way to pass the tuple into the algorithm?

yixingfu commented 4 years ago

@msaad1311

I am not completely sure about how you want to use it, but what I meant was

kernel_size_1 = hp.Choice('kernel_size_1', [3, 5])
kernel_size = (1, kernel_size_1)

and then use kernel_size in the place you need it. If this does not work, would you elaborate a bit on what you are trying to do with a short code snippet? Thanks.

Right now I don't think hyperparameters take tuple in general, which I assume would cause some problem for some of the search algorithms.

msaad1311 commented 4 years ago

Okay cool. Thanks a lot, i will try it out and let you know :)

haifeng-jin commented 4 years ago

@omalleyt12 @haifeng-jin Is there a reason for not supporting tuples?

I didn't know we are not supporting tuples. I think we are able to support anything that is naively serializable in python.