Skip to content

Commit

Permalink
add kt support (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
haifeng-jin committed Apr 13, 2020
1 parent b692344 commit 68a2522
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 48 deletions.
13 changes: 8 additions & 5 deletions autokeras/auto_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AutoModel(object):
The input node(s) of the AutoModel.
outputs: A list of Node or Head instances.
The output node(s) or head(s) of the AutoModel.
name: String. The name of the AutoModel. Defaults to 'auto_model'.
project_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.
Expand All @@ -92,18 +92,20 @@ class AutoModel(object):
project of the same name if one is found. Otherwise, overwrites the
project.
seed: Int. Random seed.
**kwargs: Any arguments supported by kerastuner.Tuner.
"""

def __init__(self,
inputs: Union[Input, List[Input]],
outputs: Union[head_module.Head, node_module.Node, list],
name: str = 'auto_model',
project_name: str = 'auto_model',
max_trials: int = 100,
directory: Union[str, Path, None] = None,
objective: str = 'val_loss',
tuner: Union[str, Type[AutoTuner]] = 'greedy',
overwrite: bool = False,
seed: Optional[int] = None):
seed: Optional[int] = None,
**kwargs):
self.inputs = nest.flatten(inputs)
self.outputs = nest.flatten(outputs)
self.seed = seed
Expand All @@ -122,7 +124,8 @@ def __init__(self,
max_trials=max_trials,
directory=directory,
seed=self.seed,
project_name=name)
project_name=project_name,
**kwargs)
self._split_dataset = False
self._heads = [output_node.in_blocks[0] for output_node in self.outputs]
self._input_adapters = [input_node.get_adapter()
Expand All @@ -147,7 +150,7 @@ def directory(self):
return self.tuner.directory

@property
def name(self):
def project_name(self):
return self.tuner.project_name

def _assemble(self):
Expand Down
42 changes: 27 additions & 15 deletions autokeras/tasks/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ImageClassifier(SupervisedImagePipeline):
loss: A Keras loss function. Defaults to use 'binary_crossentropy' or
'categorical_crossentropy' based on the number of classes.
metrics: A list of Keras metrics. Defaults to use 'accuracy'.
name: String. The name of the AutoModel. Defaults to 'image_classifier'.
project_name: String. The name of the AutoModel.
Defaults to 'image_classifier'.
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.
Expand All @@ -44,31 +45,34 @@ class ImageClassifier(SupervisedImagePipeline):
project of the same name if one is found. Otherwise, overwrites the
project.
seed: Int. Random seed.
**kwargs: Any arguments supported by AutoModel.
"""

def __init__(self,
num_classes: Optional[int] = None,
multi_label: bool = False,
loss: types.LossType = None,
metrics: Optional[types.MetricsType] = None,
name: str = 'image_classifier',
project_name: str = 'image_classifier',
max_trials: int = 100,
directory: Union[str, Path, None] = None,
objective: str = 'val_loss',
overwrite: bool = True,
seed: Optional[int] = None):
seed: Optional[int] = None,
**kwargs):
super().__init__(
outputs=hypermodels.ClassificationHead(num_classes=num_classes,
multi_label=multi_label,
loss=loss,
metrics=metrics),
max_trials=max_trials,
directory=directory,
name=name,
project_name=project_name,
objective=objective,
tuner=task_specific.ImageClassifierTuner,
overwrite=overwrite,
seed=seed)
seed=seed,
**kwargs)

def fit(
self,
Expand Down Expand Up @@ -136,7 +140,8 @@ class ImageRegressor(SupervisedImagePipeline):
If None, it will be inferred from the data.
loss: A Keras loss function. Defaults to use 'mean_squared_error'.
metrics: A list of Keras metrics. Defaults to use 'mean_squared_error'.
name: String. The name of the AutoModel. Defaults to 'image_regressor'.
project_name: String. The name of the AutoModel.
Defaults to 'image_regressor'.
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.
Expand All @@ -148,29 +153,32 @@ class ImageRegressor(SupervisedImagePipeline):
project of the same name if one is found. Otherwise, overwrites the
project.
seed: Int. Random seed.
**kwargs: Any arguments supported by AutoModel.
"""

def __init__(self,
output_dim: Optional[int] = None,
loss: types.LossType = 'mean_squared_error',
metrics: Optional[types.MetricsType] = None,
name: str = 'image_regressor',
project_name: str = 'image_regressor',
max_trials: int = 100,
directory: Union[str, Path, None] = None,
objective: str = 'val_loss',
overwrite: bool = True,
seed: Optional[int] = None):
seed: Optional[int] = None,
**kwargs):
super().__init__(
outputs=hypermodels.RegressionHead(output_dim=output_dim,
loss=loss,
metrics=metrics),
max_trials=max_trials,
directory=directory,
name=name,
project_name=project_name,
objective=objective,
tuner=greedy.Greedy,
overwrite=overwrite,
seed=seed)
seed=seed,
**kwargs)

def fit(
self,
Expand Down Expand Up @@ -242,7 +250,8 @@ class ImageSegmenter(SupervisedImagePipeline):
'categorical_crossentropy' based on the number of classes.
metrics: A list of metrics used to measure the accuracy of the model,
default to 'accuracy'.
name: String. The name of the AutoModel. Defaults to 'image_segmenter'.
project_name: String. The name of the AutoModel.
Defaults to 'image_segmenter'.
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.
Expand All @@ -254,31 +263,34 @@ class ImageSegmenter(SupervisedImagePipeline):
project of the same name if one is found. Otherwise, overwrites the
project.
seed: Int. Random seed.
**kwargs: Any arguments supported by AutoModel.
"""

def __init__(self,
num_classes: Optional[int] = None,
multi_label: bool = False,
loss: types.LossType = None,
metrics: Optional[types.MetricsType] = None,
name: str = 'image_classifier',
project_name: str = 'image_classifier',
max_trials: int = 100,
directory: Union[str, Path, None] = None,
objective: str = 'val_loss',
overwrite: bool = True,
seed: Optional[int] = None):
seed: Optional[int] = None,
**kwargs):
super().__init__(
outputs=hypermodels.SegmenterHead(num_classes=num_classes,
multi_label=multi_label,
loss=loss,
metrics=metrics),
max_trials=max_trials,
directory=directory,
name=name,
project_name=project_name,
objective=objective,
tuner=greedy.Greedy,
overwrite=overwrite,
seed=seed)
seed=seed,
**kwargs)

def fit(
self,
Expand Down
26 changes: 16 additions & 10 deletions autokeras/tasks/structured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class StructuredDataClassifier(SupervisedStructuredDataPipeline):
loss: A Keras loss function. Defaults to use 'binary_crossentropy' or
'categorical_crossentropy' based on the number of classes.
metrics: A list of Keras metrics. Defaults to use 'accuracy'.
name: String. The name of the AutoModel. Defaults to
project_name: String. The name of the AutoModel. Defaults to
'structured_data_classifier'.
max_trials: Int. The maximum number of different Keras Models to try.
The search may finish before reaching the max_trials. Defaults to 100.
Expand All @@ -169,6 +169,7 @@ class StructuredDataClassifier(SupervisedStructuredDataPipeline):
project of the same name if one is found. Otherwise, overwrites the
project.
seed: Int. Random seed.
**kwargs: Any arguments supported by AutoModel.
"""

def __init__(self,
Expand All @@ -178,12 +179,13 @@ def __init__(self,
multi_label=False,
loss=None,
metrics=None,
name='structured_data_classifier',
project_name='structured_data_classifier',
max_trials=100,
directory=None,
objective='val_accuracy',
overwrite=True,
seed=None):
seed=None,
**kwargs):
super().__init__(
outputs=hypermodels.ClassificationHead(num_classes=num_classes,
multi_label=multi_label,
Expand All @@ -193,11 +195,12 @@ def __init__(self,
column_types=column_types,
max_trials=max_trials,
directory=directory,
name=name,
project_name=project_name,
objective=objective,
tuner=greedy.Greedy,
overwrite=overwrite,
seed=seed)
seed=seed,
**kwargs)

def fit(self,
x=None,
Expand Down Expand Up @@ -263,7 +266,7 @@ class StructuredDataRegressor(SupervisedStructuredDataPipeline):
If None, it will be inferred from the data.
loss: A Keras loss function. Defaults to use 'mean_squared_error'.
metrics: A list of Keras metrics. Defaults to use 'mean_squared_error'.
name: String. The name of the AutoModel. Defaults to
project_name: String. The name of the AutoModel. Defaults to
'structured_data_regressor'.
max_trials: Int. The maximum number of different Keras Models to try.
The search may finish before reaching the max_trials. Defaults to 100.
Expand All @@ -276,6 +279,7 @@ class StructuredDataRegressor(SupervisedStructuredDataPipeline):
project of the same name if one is found. Otherwise, overwrites the
project.
seed: Int. Random seed.
**kwargs: Any arguments supported by AutoModel.
"""

def __init__(self,
Expand All @@ -284,12 +288,13 @@ def __init__(self,
output_dim: Optional[int] = None,
loss: types.LossType = 'mean_squared_error',
metrics: Optional[types.MetricsType] = None,
name: str = 'structured_data_regressor',
project_name: str = 'structured_data_regressor',
max_trials: int = 100,
directory: Union[str, pathlib.Path, None] = None,
objective: str = 'val_loss',
overwrite: bool = True,
seed: Optional[int] = None):
seed: Optional[int] = None,
**kwargs):
super().__init__(
outputs=hypermodels.RegressionHead(output_dim=output_dim,
loss=loss,
Expand All @@ -298,8 +303,9 @@ def __init__(self,
column_types=column_types,
max_trials=max_trials,
directory=directory,
name=name,
project_name=project_name,
objective=objective,
tuner=greedy.Greedy,
overwrite=overwrite,
seed=seed)
seed=seed,
**kwargs)
28 changes: 18 additions & 10 deletions autokeras/tasks/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class TextClassifier(SupervisedTextPipeline):
loss: A Keras loss function. Defaults to use 'binary_crossentropy' or
'categorical_crossentropy' based on the number of classes.
metrics: A list of Keras metrics. Defaults to use 'accuracy'.
name: String. The name of the AutoModel. Defaults to 'text_classifier'.
project_name: String. The name of the AutoModel.
Defaults to 'text_classifier'.
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.
Expand All @@ -40,31 +41,34 @@ class TextClassifier(SupervisedTextPipeline):
project of the same name if one is found. Otherwise, overwrites the
project.
seed: Int. Random seed.
**kwargs: Any arguments supported by AutoModel.
"""

def __init__(self,
num_classes: Optional[int] = None,
multi_label: bool = False,
loss: types.LossType = None,
metrics: Optional[types.MetricsType] = None,
name: str = 'text_classifier',
project_name: str = 'text_classifier',
max_trials: int = 100,
directory: Union[str, pathlib.Path, None] = None,
objective: str = 'val_loss',
overwrite: bool = True,
seed: Optional[int] = None):
seed: Optional[int] = None,
**kwargs):
super().__init__(
outputs=hypermodels.ClassificationHead(num_classes=num_classes,
multi_label=multi_label,
loss=loss,
metrics=metrics),
max_trials=max_trials,
directory=directory,
name=name,
project_name=project_name,
objective=objective,
tuner=task_specific.TextClassifierTuner,
overwrite=overwrite,
seed=seed)
seed=seed,
**kwargs)

def fit(self,
x=None,
Expand Down Expand Up @@ -131,7 +135,8 @@ class TextRegressor(SupervisedTextPipeline):
If None, it will be inferred from the data.
loss: A Keras loss function. Defaults to use 'mean_squared_error'.
metrics: A list of Keras metrics. Defaults to use 'mean_squared_error'.
name: String. The name of the AutoModel. Defaults to 'text_regressor'.
project_name: String. The name of the AutoModel.
Defaults to 'text_regressor'.
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.
Expand All @@ -143,29 +148,32 @@ class TextRegressor(SupervisedTextPipeline):
project of the same name if one is found. Otherwise, overwrites the
project.
seed: Int. Random seed.
**kwargs: Any arguments supported by AutoModel.
"""

def __init__(self,
output_dim=None,
loss='mean_squared_error',
metrics=None,
name='text_regressor',
project_name='text_regressor',
max_trials=100,
directory=None,
objective='val_loss',
overwrite=True,
seed=None):
seed=None,
**kwargs):
super().__init__(
outputs=hypermodels.RegressionHead(output_dim=output_dim,
loss=loss,
metrics=metrics),
max_trials=max_trials,
directory=directory,
name=name,
project_name=project_name,
objective=objective,
tuner=greedy.Greedy,
overwrite=overwrite,
seed=seed)
seed=seed,
**kwargs)

def fit(self,
x=None,
Expand Down

0 comments on commit 68a2522

Please sign in to comment.