AutoModel

[source]

AutoModel class

autokeras.auto_model.AutoModel(
    inputs, outputs, name="auto_model", max_trials=100, directory=None, objective="val_loss", seed=None
)

A Model defined by inputs and outputs.

AutoModel combines a HyperModel and a Tuner to tune the HyperModel. The user can use it in a similar way to a Keras model since it also has fit() and predict() methods.

The user can specify the inputs and outputs of the AutoModel. It will infer the rest of the high-level neural architecture.

Arguments

  • inputs: A list of or a HyperNode instance. The input node(s) of the AutoModel.
  • outputs: A list of or a HyperHead instance. The output head(s) of the AutoModel.
  • name: String. The name of the AutoModel. Defaults to 'auto_model'.
  • max_trials: Int. The maximum number of different Keras Models to try. The search may finish before reaching the max_trials. Defaults to 100.
  • directory: String. The path to a directory for storing the search outputs. Defaults to None, which would create a folder with the name of the AutoModel in the current directory.
  • objective: String. Name of model metric to minimize or maximize, e.g. 'val_accuracy'. Defaults to 'val_loss'.
  • seed: Int. Random seed.

[source]

fit method

AutoModel.fit(
    x=None, y=None, epochs=None, callbacks=None, validation_split=0, validation_data=None, **kwargs
)

Search for the best model and hyperparameters for the AutoModel.

It will search for the best model based on the performances on validation data.

Arguments

  • x: numpy.ndarray or tensorflow.Dataset. Training data x.
  • y: numpy.ndarray or tensorflow.Dataset. Training data y.
  • epochs: Int. The number of epochs to train each model during the search. If unspecified, by default we train for a maximum of 1000 epochs, but we stop training if the validation loss stops improving for 10 epochs (unless you specified an EarlyStopping callback as part of the callbacks argument, in which case the EarlyStopping callback you specified will determine early stopping).
  • callbacks: List of Keras callbacks to apply during training and validation.
  • validation_split: Float between 0 and 1. Fraction of the training data to be used as validation data. The model will set apart this fraction of the training data, will not train on it, and will evaluate the loss and any model metrics on this data at the end of each epoch. The validation data is selected from the last samples in the x and y data provided, before shuffling. This argument is not supported when x is a dataset. The best model found would be fit on the entire dataset including the validation data.
  • validation_data: Data on which to evaluate the loss and any model metrics at the end of each epoch. The model will not be trained on this data. validation_data will override validation_split. The type of the validation data should be the same as the training data. The best model found would be fit on the training dataset without the validation data.
  • **kwargs: Any arguments supported by keras.Model.fit.

[source]

predict method

AutoModel.predict(x, batch_size=32, **kwargs)

Predict the output for a given testing data.

Arguments

  • x: Any allowed types according to the input node. Testing data.
  • batch_size: Int. Defaults to 32.
  • **kwargs: Any arguments supported by keras.Model.predict.

Returns

A list of numpy.ndarray objects or a single numpy.ndarray. The predicted results.