Skip to content

Commit

Permalink
Typed automodel and type checking during tests. (#957)
Browse files Browse the repository at this point in the history
* Typed automodel.

* Used isort.

* Fixed types.

* Fixed tests.

* Small change.

* Chanding tmp_dir -> tmp_path

* Fixed all incorrect types.

* Fix imports.

* Changes according to review.

* Bump keras-autodoc version and fix types.
  • Loading branch information
gabrieldemarmiesse authored Feb 17, 2020
1 parent b695b5e commit 252a5e8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
26 changes: 17 additions & 9 deletions autokeras/auto_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from pathlib import Path
from typing import List
from typing import Optional
from typing import Type
from typing import Union

import numpy as np
import tensorflow as tf
from tensorflow.python.util import nest
Expand All @@ -9,6 +15,8 @@
from autokeras import utils
from autokeras.engine import head as head_module
from autokeras.engine import node as node_module
from autokeras.engine.tuner import AutoTuner
from autokeras.nodes import Input

TUNER_CLASSES = {
'bayesian': tuners.BayesianOptimization,
Expand Down Expand Up @@ -87,15 +95,15 @@ class AutoModel(object):
"""

def __init__(self,
inputs,
outputs,
name='auto_model',
max_trials=100,
directory=None,
objective='val_loss',
tuner='greedy',
overwrite=False,
seed=None):
inputs: Union[Input, List[Input]],
outputs: Union[head_module.Head, node_module.Node, list],
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):
self.inputs = nest.flatten(inputs)
self.outputs = nest.flatten(outputs)
self.seed = seed
Expand Down
3 changes: 2 additions & 1 deletion autokeras/tasks/image.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pathlib import Path
from typing import Callable
from typing import List
from typing import Optional
Expand Down Expand Up @@ -48,7 +49,7 @@ def __init__(self,
metrics: Optional[List[Union[str, Callable]]] = None,
name: str = 'image_classifier',
max_trials: int = 100,
directory: Optional[str] = None,
directory: Union[str, Path, None] = None,
objective: str = 'val_loss',
overwrite: bool = True,
seed: Optional[int] = None):
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Our documentation uses extended Markdown, as implemented by [MkDocs](http://mkdo
## Building the documentation

- Install MkDocs and the material theme: `pip install mkdocs mkdocs-material`
- Install keras-autodoc: `pip install keras-autodoc==0.4.0`
- Install keras-autodoc: `pip install keras-autodoc==0.4.1`
- `pip install -e .` to make sure that Python will import your modified version of AutoKeras.
- From the root directory, `cd` into the `docs/` folder and run:
- `python autogen.py`
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
keras-autodoc
keras-autodoc==0.4.1
mkdocs
mkdocs-material
pygments
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ filterwarnings =

addopts=-v
--durations=10
--typeguard-packages=autokeras

# Do not run tests in the build folder
norecursedirs= build
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
'isort',
'pytest-xdist',
'pytest-cov',
'coverage'
'coverage',
'typeguard>=2,<3'
],
},
packages=find_packages(exclude=('tests',)),
Expand Down
1 change: 0 additions & 1 deletion tests/autokeras/typed_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# TODO: add types and remove all elements from
# the exception list.
EXCEPTION_LIST = [
autokeras.AutoModel,
autokeras.Block,
autokeras.Head,
autokeras.Node,
Expand Down

0 comments on commit 252a5e8

Please sign in to comment.