autokeras
autokeras copied to clipboard
Cannot set dropout rate in custom AutoModel
Bug Description
I would like to create a custom AutoModel regressor with a 5% dropout rate in both the dense block and regression head:
import autokeras as ak
input_node = StructuredDataInput()
output_node = ak.Normalization()(input_node)
output_node = ak.DenseBlock(dropout=0.05)(output_node)
output_node = ak.RegressionHead(dropout=0.05)(output_node)
reg = ak.AutoModel(inputs=input_node, outputs=output_node, overwrite=True, max_trials=2)
However, this raises an error when trying to initialise the AutoModel:
AttributeError: 'float' object has no attribute 'get_config'
Setup Details
Include the details about the versions of:
- OS type and version: Linux, Ubuntu 18.04.3
- Python: 3.9.4
- autokeras: 1.0.16
- keras-tuner: 1.0.4
- scikit-learn: 0.24.2
- numpy: 1.19.5
- pandas: 1.2.4
- tensorflow: 2.5.0
Additional context
I'm attempting to build an AutoModel where the dropout is applied both at the training stage and the prediction stage, so I can get a distribution of predictions and incorporate bayesian uncertainty. Maybe this is a bit off-topic, but this is how I'm going to approach the problem, by following the suggestion from here and replacing each instance of Dropout with this:
class MonteCarloDropout(keras.layers.Dropout):
def call(self, inputs):
return super().call(inputs, training=True)
Anyway, if you know of an easier/better way to do this then please let me know