Skip to content

Commit

Permalink
Merge 4c039d1 into 6da80da
Browse files Browse the repository at this point in the history
  • Loading branch information
haifeng-jin committed Oct 27, 2019
2 parents 6da80da + 4c039d1 commit 05a1413
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
9 changes: 5 additions & 4 deletions autokeras/auto_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class AutoModel(object):
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.
"""

Expand All @@ -39,6 +41,7 @@ def __init__(self,
name='auto_model',
max_trials=100,
directory=None,
objective='val_loss',
seed=None):
self.inputs = nest.flatten(inputs)
self.outputs = nest.flatten(outputs)
Expand All @@ -48,6 +51,7 @@ def __init__(self,
self.directory = directory
self.seed = seed
self.hyper_graph = None
self.objective = objective
self._split_dataset = False
if all([isinstance(output_node, base.Head)
for output_node in self.outputs]):
Expand All @@ -69,7 +73,6 @@ def fit(self,
callbacks=None,
validation_split=0,
validation_data=None,
objective='val_loss',
**kwargs):
"""Search for the best model and hyperparameters for the AutoModel.
Expand Down Expand Up @@ -104,8 +107,6 @@ def fit(self,
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.
objective: String. Name of model metric to minimize
or maximize, e.g. 'val_accuracy'. Defaults to 'val_loss'.
**kwargs: Any arguments supported by keras.Model.fit.
"""
dataset, validation_data = self._prepare_data(
Expand All @@ -128,7 +129,7 @@ def fit(self,
hyper_graph=self.hyper_graph,
fit_on_val_data=self._split_dataset,
hypermodel=keras_graph,
objective=objective,
objective=self.objective,
max_trials=self.max_trials,
directory=self.directory,
seed=self.seed,
Expand Down
32 changes: 24 additions & 8 deletions autokeras/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class ImageClassifier(SupervisedImagePipeline):
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.
"""

Expand All @@ -39,6 +41,7 @@ def __init__(self,
name='image_classifier',
max_trials=100,
directory=None,
objective='val_loss',
seed=None):
super().__init__(
outputs=head.ClassificationHead(num_classes=num_classes,
Expand All @@ -48,6 +51,7 @@ def __init__(self,
max_trials=max_trials,
directory=directory,
name=name,
objective=objective,
seed=seed)


Expand All @@ -66,6 +70,8 @@ class ImageRegressor(SupervisedImagePipeline):
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.
"""

Expand All @@ -76,6 +82,7 @@ def __init__(self,
name='image_regressor',
max_trials=100,
directory=None,
objective='val_loss',
seed=None):
super().__init__(
outputs=head.RegressionHead(output_dim=output_dim,
Expand All @@ -84,6 +91,7 @@ def __init__(self,
max_trials=max_trials,
directory=directory,
name=name,
objective=objective,
seed=seed)


Expand All @@ -110,6 +118,8 @@ class TextClassifier(SupervisedTextPipeline):
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.
"""

Expand All @@ -121,6 +131,7 @@ def __init__(self,
name='text_classifier',
max_trials=100,
directory=None,
objective='val_loss',
seed=None):
super().__init__(
outputs=head.ClassificationHead(num_classes=num_classes,
Expand All @@ -130,6 +141,7 @@ def __init__(self,
max_trials=max_trials,
directory=directory,
name=name,
objective=objective,
seed=seed)


Expand All @@ -148,6 +160,8 @@ class TextRegressor(SupervisedTextPipeline):
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.
"""

Expand All @@ -158,6 +172,7 @@ def __init__(self,
name='text_regressor',
max_trials=100,
directory=None,
objective='val_loss',
seed=None):
super().__init__(
outputs=head.RegressionHead(output_dim=output_dim,
Expand All @@ -166,6 +181,7 @@ def __init__(self,
max_trials=max_trials,
directory=directory,
name=name,
objective=objective,
seed=seed)


Expand Down Expand Up @@ -204,7 +220,6 @@ def fit(self,
callbacks=None,
validation_split=0,
validation_data=None,
objective='val_loss',
**kwargs):
"""Search for the best model and hyperparameters for the task.
Expand Down Expand Up @@ -237,8 +252,6 @@ def fit(self,
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.
objective: String. Name of model metric to minimize
or maximize. Defaults to 'val_accuracy'.
**kwargs: Any arguments supported by keras.Model.fit.
"""
# x is file path of training data
Expand All @@ -256,7 +269,6 @@ def fit(self,
callbacks=callbacks,
validation_split=validation_split,
validation_data=validation_data,
objective=objective,
**kwargs)

def predict(self, x, batch_size=32, **kwargs):
Expand Down Expand Up @@ -333,6 +345,8 @@ class StructuredDataClassifier(SupervisedStructuredDataPipeline):
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. Defaults to 'val_accuracy'.
seed: Int. Random seed.
"""

Expand All @@ -346,6 +360,7 @@ def __init__(self,
name='structured_data_classifier',
max_trials=100,
directory=None,
objective='val_accuracy',
seed=None):
super().__init__(
outputs=head.ClassificationHead(num_classes=num_classes,
Expand All @@ -357,6 +372,7 @@ def __init__(self,
max_trials=max_trials,
directory=directory,
name=name,
objective=objective,
seed=seed)

def fit(self,
Expand All @@ -366,7 +382,6 @@ def fit(self,
callbacks=None,
validation_split=0,
validation_data=None,
objective='val_accuracy',
**kwargs):
"""Search for the best model and hyperparameters for the task.
Expand Down Expand Up @@ -395,8 +410,6 @@ def fit(self,
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.
objective: String. Name of model metric to minimize
or maximize. Defaults to 'val_accuracy'.
**kwargs: Any arguments supported by keras.Model.fit.
"""
super().fit(x=x,
Expand All @@ -405,7 +418,6 @@ def fit(self,
callbacks=callbacks,
validation_split=validation_split,
validation_data=validation_data,
objective=objective,
**kwargs)


Expand All @@ -428,6 +440,8 @@ class StructuredDataRegressor(SupervisedStructuredDataPipeline):
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.
"""

Expand All @@ -440,6 +454,7 @@ def __init__(self,
name='structured_data_regressor',
max_trials=100,
directory=None,
objective='val_loss',
seed=None):
super().__init__(
outputs=head.RegressionHead(output_dim=output_dim,
Expand All @@ -450,4 +465,5 @@ def __init__(self,
max_trials=max_trials,
directory=directory,
name=name,
objective=objective,
seed=seed)

0 comments on commit 05a1413

Please sign in to comment.