Showing preview only (646K chars total). Download the full file or copy to clipboard to get everything.
Repository: keras-team/autokeras
Branch: master
Commit: a2446cf16edc
Files: 184
Total size: 601.8 KB
Directory structure:
gitextract_87bybot9/
├── .devcontainer/
│ ├── Dockerfile
│ ├── devcontainer.json
│ └── setup.sh
├── .dockerignore
├── .github/
│ ├── CODEOWNERS
│ ├── CODE_OF_CONDUCT.md
│ ├── CONTRIBUTING.md
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.md
│ │ ├── custom.md
│ │ ├── feature_request.md
│ │ └── new-task-template.md
│ ├── PULL_REQUEST_TEMPLATE.md
│ ├── dependabot.yml
│ └── workflows/
│ └── actions.yml
├── .gitignore
├── LICENSE
├── README.md
├── RELEASE.md
├── autokeras/
│ ├── __init__.py
│ ├── adapters/
│ │ ├── __init__.py
│ │ ├── input_adapters.py
│ │ ├── input_adapters_test.py
│ │ ├── output_adapters.py
│ │ └── output_adapters_test.py
│ ├── analysers/
│ │ ├── __init__.py
│ │ ├── input_analysers.py
│ │ ├── input_analysers_test.py
│ │ ├── output_analysers.py
│ │ └── output_analysers_test.py
│ ├── auto_model.py
│ ├── auto_model_test.py
│ ├── blocks/
│ │ ├── __init__.py
│ │ ├── basic.py
│ │ ├── basic_test.py
│ │ ├── heads.py
│ │ ├── heads_test.py
│ │ ├── preprocessing.py
│ │ ├── preprocessing_test.py
│ │ ├── reduction.py
│ │ ├── reduction_test.py
│ │ ├── wrapper.py
│ │ └── wrapper_test.py
│ ├── conftest.py
│ ├── engine/
│ │ ├── __init__.py
│ │ ├── adapter.py
│ │ ├── adapter_test.py
│ │ ├── analyser.py
│ │ ├── analyser_test.py
│ │ ├── block.py
│ │ ├── block_test.py
│ │ ├── head.py
│ │ ├── head_test.py
│ │ ├── hyper_preprocessor.py
│ │ ├── io_hypermodel.py
│ │ ├── named_hypermodel.py
│ │ ├── node.py
│ │ ├── node_test.py
│ │ ├── preprocessor.py
│ │ ├── serializable.py
│ │ ├── tuner.py
│ │ └── tuner_test.py
│ ├── graph.py
│ ├── graph_test.py
│ ├── hyper_preprocessors.py
│ ├── hyper_preprocessors_test.py
│ ├── integration_tests/
│ │ ├── __init__.py
│ │ ├── functional_api_test.py
│ │ ├── io_api_test.py
│ │ └── task_api_test.py
│ ├── keras_layers.py
│ ├── keras_layers_test.py
│ ├── nodes.py
│ ├── nodes_test.py
│ ├── pipeline.py
│ ├── pipeline_test.py
│ ├── preprocessors/
│ │ ├── __init__.py
│ │ ├── common.py
│ │ ├── common_test.py
│ │ ├── encoders.py
│ │ ├── encoders_test.py
│ │ ├── postprocessors.py
│ │ └── postprocessors_test.py
│ ├── tasks/
│ │ ├── __init__.py
│ │ ├── image.py
│ │ ├── image_test.py
│ │ ├── structured_data.py
│ │ ├── structured_data_test.py
│ │ ├── text.py
│ │ └── text_test.py
│ ├── test_utils.py
│ ├── tuners/
│ │ ├── __init__.py
│ │ ├── bayesian_optimization.py
│ │ ├── greedy.py
│ │ ├── greedy_test.py
│ │ ├── hyperband.py
│ │ ├── hyperband_test.py
│ │ ├── random_search.py
│ │ ├── random_search_test.py
│ │ ├── task_specific.py
│ │ └── task_specific_test.py
│ └── utils/
│ ├── __init__.py
│ ├── data_utils.py
│ ├── data_utils_test.py
│ ├── io_utils.py
│ ├── layer_utils.py
│ ├── types.py
│ ├── utils.py
│ └── utils_test.py
├── benchmark/
│ ├── README.md
│ ├── __init__.py
│ ├── datasets/
│ │ ├── titanic_test.csv
│ │ └── titanic_train.csv
│ ├── experiments/
│ │ ├── __init__.py
│ │ ├── experiment.py
│ │ ├── image.py
│ │ ├── structured_data.py
│ │ └── text.py
│ ├── performance.py
│ └── run.py
├── codecov.yml
├── docker/
│ ├── Dockerfile
│ ├── Makefile
│ ├── README.md
│ ├── devel.Dockerfile
│ ├── pre-commit.Dockerfile
│ └── pre_commit.py
├── docs/
│ ├── README.md
│ ├── autogen.py
│ ├── ipynb/
│ │ ├── customized.ipynb
│ │ ├── export.ipynb
│ │ ├── image_classification.ipynb
│ │ ├── image_regression.ipynb
│ │ ├── multi.ipynb
│ │ ├── structured_data_classification.ipynb
│ │ ├── structured_data_regression.ipynb
│ │ ├── text_classification.ipynb
│ │ └── text_regression.ipynb
│ ├── keras_autodoc/
│ │ ├── __init__.py
│ │ ├── autogen.py
│ │ ├── docstring.py
│ │ ├── examples.py
│ │ ├── gathering_members.py
│ │ ├── get_signatures.py
│ │ └── utils.py
│ ├── mkdocs.yml
│ ├── py/
│ │ ├── customized.py
│ │ ├── export.py
│ │ ├── image_classification.py
│ │ ├── image_regression.py
│ │ ├── multi.py
│ │ ├── structured_data_classification.py
│ │ ├── structured_data_regression.py
│ │ ├── text_classification.py
│ │ └── text_regression.py
│ ├── requirements.txt
│ ├── run_py_files.sh
│ ├── templates/
│ │ ├── about.md
│ │ ├── index.md
│ │ ├── install.md
│ │ ├── stylesheets/
│ │ │ └── extra.css
│ │ └── tutorial/
│ │ ├── faq.md
│ │ └── overview.md
│ └── tutobooks.py
├── examples/
│ ├── automodel_with_cnn.py
│ ├── celeb_age.py
│ ├── cifar10.py
│ ├── imdb.py
│ ├── mnist.py
│ ├── new_pop.py
│ └── reuters.py
├── pyproject.toml
├── setup.cfg
└── shell/
├── contributors.py
├── contributors.sh
├── copyright.txt
├── cov.sh
├── coverage.sh
├── docs.sh
├── format.sh
├── generate_json.js
├── lint.sh
├── perf.sh
├── pre-commit.sh
└── pypi.sh
================================================
FILE CONTENTS
================================================
================================================
FILE: .devcontainer/Dockerfile
================================================
FROM mcr.microsoft.com/vscode/devcontainers/python:3.10
COPY setup.sh /setup.sh
================================================
FILE: .devcontainer/devcontainer.json
================================================
{
"dockerFile": "Dockerfile",
"postCreateCommand": "sh /setup.sh",
"customizations": {
"vscode": {
"settings": {
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.pylintEnabled": false,
"python.testing.pytestEnabled": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"editor.rulers": [
80
]
},
"extensions": [
"ms-python.python",
"ms-python.isort",
"ms-python.flake8",
"ms-python.black-formatter"
]
}
},
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
}
}
================================================
FILE: .devcontainer/setup.sh
================================================
sudo pip install --upgrade pip
sudo pip install -e ".[tests]"
echo "sh shell/lint.sh" > .git/hooks/pre-commit
chmod a+x .git/hooks/pre-commit
================================================
FILE: .dockerignore
================================================
.git
.github
*.Dockerfile
================================================
FILE: .github/CODEOWNERS
================================================
* @haifeng-jin @fchollet
================================================
FILE: .github/CODE_OF_CONDUCT.md
================================================
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at jin@tamu.edu. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
================================================
FILE: .github/CONTRIBUTING.md
================================================
# Contributing Guide
Contributions are welcome, and greatly appreciated!
This page is only a guide of the best practices of contributing code to AutoKeras.
The best way to contribute is to join our community by reading [this](https://autokeras.com/#contributing-code).
We will get you started right away.
Follow the tag of [good first issue](https://github.com/keras-team/autokeras/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
for the issues for beginner.
## Pull Request Guide
1. Is this the first pull request that you're making with GitHub? If so, read the guide [Making a pull request to an open-source project](https://github.com/gabrieldemarmiesse/getting_started_open_source).
2. Include "resolves #issue_number" in the description of the pull request if applicable. Briefly describe your contribution.
3. Submit the pull request from the first day of your development and create it as a [draft pull request](https://github.blog/2019-02-14-introducing-draft-pull-requests/). Click `ready for review` when finished and passed the all the checks.
4. For the case of bug fixes, add new test cases which would fail before your bug fix.
## Setup Environment
We introduce 3 different options: **GitHub Codespaces**, **VS Code & Dev Containers**, **the general setup**.
You can choose base on your preference.
### Option 1: GitHub Codespaces
You can simply open the repository in GitHub Codespaces.
The environment is already setup there.
### Option 2: VS Code & Dev Containers
Open VS Code.
Install the `Dev Containers` extension.
Press `F1` key. Enter `Dev Containers: Open Folder in Container...` to open the repository root folder.
The environment is already setup there.
### Option 3: The General Setup
Install [Virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/).
Create a new virtualenv named `ak` based on python3.
```
mkvirtualenv -p python3 ak
```
Please use this virtualenv for development.
Clone the repo. Go to the repo directory.
Run the following commands.
```
workon ak
pip install -e ".[tests]"
pip uninstall autokeras
add2virtualenv .
```
## Run Tests
### GitHub Codespaces or VS Code & Dev Containers
If you are using "GitHub Codespaces" or "VS Code & Dev Containers",
you can simply open any `*_test.py` file under the `tests` directory,
and wait a few seconds, you will see the test tab on the left of the window.
### General Setup
If you are using the general setup.
Activate the virtualenv.
Go to the repo directory
Run the following lines to run the tests.
Run all the tests.
```
pytest tests
```
Run all the unit tests.
```
pytest tests/autokeras
```
Run all the integration tests.
```
pytest tests/integration_tests
```
## Code Style
You can run the following manually every time you want to format your code.
1. Run `shell/format.sh` to format your code.
2. Run `shell/lint.sh` to check.
## Docstrings
Docstrings should follow our style.
Just check the style of other docstrings in AutoKeras.
================================================
FILE: .github/ISSUE_TEMPLATE/bug_report.md
================================================
---
name: Bug report
about: Create a report to help us improve
labels: ["bug report"]
title: "Bug: "
---
### Bug Description
<!---
A clear and concise description of what the bug is.
-->
### Bug Reproduction
Code for reproducing the bug:
Data used by the code:
### Expected Behavior
<!---
If not so obvious to see the bug from the running results,
please briefly describe the expected behavior.
-->
### Setup Details
Include the details about the versions of:
- OS type and version:
- Python:
- autokeras: <!--- e.g. 0.4.0, 1.0.2, master-->
- keras-tuner:
- scikit-learn:
- numpy:
- pandas:
- tensorflow:
### Additional context
<!---
If applicable, add any other context about the problem.
-->
================================================
FILE: .github/ISSUE_TEMPLATE/custom.md
================================================
---
name: Custom issue template
about: Describe this issue template's purpose here.
---
================================================
FILE: .github/ISSUE_TEMPLATE/feature_request.md
================================================
---
name: Feature request
about: Suggest an idea for this project
labels: ["feature request"]
title: "Feature: "
---
### Feature Description
### Code Example
<!---
Please provide a code example for using that feature
given the proposed feature is implemented.
-->
```python
```
### Reason
<!---
Why do we need the feature?
-->
### Solution
<!---
Please tell us how to implement the feature,
if you have one in mind.
-->
================================================
FILE: .github/ISSUE_TEMPLATE/new-task-template.md
================================================
---
name: New Task Template
about: Add a new machine learning task
labels: ["algorithm"]
title: "New Task: "
---
<!---
Please label your issue with `new_task_module`.
-->
### Suggested Name
<!---
Give a suggested name of the new task module, e.g. TextClassifier, ImageClassifier.
-->
### Task Description
<!---
A clear and concise description of the machine learning task to be added, its problem statement and learning outcome.
-->
### Evaluation Metrics
<!---
e.g. Mean Square Error, F1-score, Accuracy, AUC.
-->
### Benchmark Datasets
<!---
Any public available datasets you know for the task,
please provide the name and link.
-->
### Reason
<!---
A clear and concise description of why this feature would be useful for the project.
-->
### Solution
<!---
A clear and concise description of what you want to happen.
-->
### Additional Context
<!---
Add any other context or screenshots about the feature request here.
-->
================================================
FILE: .github/PULL_REQUEST_TEMPLATE.md
================================================
<!-- STEP 1: Give the pull request a meaningful title. -->
### Which issue(s) does this Pull Request fix?
<!-- STEP 2: Replace the "000" with the issue ID this pull request resolves. -->
resolves #000
### Details of the Pull Request
<!-- STEP 3: Add details/comments on the pull request. -->
<!-- STEP 4: If the pull request is in progress, click the down green arrow to select "Create Draft Pull Request", and click the button. If the pull request is ready to be reviewed, click "Create Pull Request" button directly. -->
================================================
FILE: .github/dependabot.yml
================================================
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
time: "11:00"
open-pull-requests-limit: 10
ignore:
- dependency-name: sphinx
versions:
- ">= 3.1.a, < 3.2"
- dependency-name: typeguard
versions:
- ">= 2.11.a, < 2.12"
- dependency-name: typeguard
versions:
- ">= 2.12.a, < 2.13"
================================================
FILE: .github/workflows/actions.yml
================================================
name: Tests
on:
push:
branches: [ master ]
pull_request:
release:
types: [created]
jobs:
build:
name: Run tests
runs-on: ubuntu-latest
env:
KERAS_BACKEND: torch
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Get pip cache dir
id: pip-cache
run: |
python -m pip install --upgrade pip setuptools
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
- name: Install dependencies
run: |
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install -e ".[tests]" --progress-bar off
- name: Test with pytest
run: |
pytest --cov=autokeras --cov-report xml:coverage.xml
- name: Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
fail_ci_if_error: true
format:
name: Check the code format
runs-on: ubuntu-latest
env:
KERAS_BACKEND: torch
steps:
- uses: actions/checkout@v3
- name: Run pre-commit
run: bash shell/pre-commit.sh
build-docs:
name: Build the docs
runs-on: ubuntu-latest
env:
KERAS_BACKEND: torch
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install -e .
pip install -r docs/requirements.txt
- name: Build the docs
run: |
cd docs
python autogen.py
mkdocs build
deploy:
needs: [build, format, build-docs]
if: github.event_name == 'release' && github.event.action == 'created'
runs-on: ubuntu-latest
env:
KERAS_BACKEND: torch
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip build twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python -m build
twine upload dist/*
================================================
FILE: .gitignore
================================================
# vim swp files
*.swp
# caffe/pytorch model files
*.pth
# Mkdocs
/docs/sources
/docs/site
.DS_Store
.vscode
settings.json
.idea
.pytest_cache
/experiments
# resource temp folder
tests/resources/temp/*
!tests/resources/temp/.gitkeep
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
cov.xml
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
.static_storage/
.media/
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
examples/text_cnn/glove_embedding/
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2020 The AutoKeras Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: README.md
================================================
<p align="center">
<img width="500" alt="logo" src="https://autokeras.com/img/row_red.svg"/>
</p>
[](https://github.com/keras-team/autokeras/actions?query=workflow%3ATests+branch%3Amaster)
[](https://codecov.io/gh/keras-team/autokeras)
[](https://badge.fury.io/py/autokeras)
[](https://github.com/keras-team/autokeras/issues)
Official Website: [autokeras.com](https://autokeras.com)
##
AutoKeras: An AutoML system based on Keras.
It is developed by <a href="http://faculty.cs.tamu.edu/xiahu/index.html" target="_blank" rel="nofollow">DATA Lab</a> at Texas A&M University.
The goal of AutoKeras is to make machine learning accessible to everyone.
## Learning resources
* A short example.
```python
import autokeras as ak
clf = ak.ImageClassifier()
clf.fit(x_train, y_train)
results = clf.predict(x_test)
```
* [Official website tutorials](https://autokeras.com/tutorial/overview/).
* The book of [*Automated Machine Learning in Action*](https://www.manning.com/books/automated-machine-learning-in-action?query=automated&utm_source=jin&utm_medium=affiliate&utm_campaign=affiliate&a_aid=jin).
* The LiveProjects of [*Image Classification with AutoKeras*](https://www.manning.com/liveprojectseries/autokeras-ser).
<p align="center">
<a href="https://www.manning.com/books/automated-machine-learning-in-action?query=automated&utm_source=jin&utm_medium=affiliate&utm_campaign=affiliate&a_aid=jin"><img src="https://images.manning.com/360/480/resize/book/0/fc56aaf-b2ba-4ef4-85b3-4a31edbe8ecc/Song-AML-HI.png" alt="drawing" width="266"/></a>
 
 
<a href="https://www.manning.com/liveprojectseries/autokeras-ser"><img src="https://images.manning.com/360/480/resize/liveProjectSeries/9/38c715a-0c8c-4f66-b440-83d29993877a/ImageClassificationwithAutoKeras.jpg" alt="drawing" width="250"/></a>
</p>
## Installation
To install the package, please use the `pip` installation as follows:
```shell
pip3 install autokeras
```
Please follow the [installation guide](https://autokeras.com/install) for more details.
**Note:** Currently, AutoKeras is only compatible with **Python >= 3.7** and **TensorFlow >= 2.8.0**.
## Community
Ask your questions on our [GitHub Discussions](https://github.com/keras-team/autokeras/discussions).
## Contributing Code
Here is how we manage our project.
We pick the critical issues to work on from [GitHub issues](https://github.com/keras-team/autokeras/issues).
They will be added to this [Project](https://github.com/keras-team/autokeras/projects/3).
Some of the issues will then be added to the [milestones](https://github.com/keras-team/autokeras/milestones),
which are used to plan for the releases.
Refer to our [Contributing Guide](https://autokeras.com/contributing/) to learn the best practices.
Thank all the contributors!
[](https://github.com/keras-team/autokeras/graphs/contributors)
## Cite this work
Haifeng Jin, François Chollet, Qingquan Song, and Xia Hu. "AutoKeras: An AutoML Library for Deep Learning." *the Journal of machine Learning research* 6 (2023): 1-6. ([Download](http://jmlr.org/papers/v24/20-1355.html))
Biblatex entry:
```bibtex
@article{JMLR:v24:20-1355,
author = {Haifeng Jin and François Chollet and Qingquan Song and Xia Hu},
title = {AutoKeras: An AutoML Library for Deep Learning},
journal = {Journal of Machine Learning Research},
year = {2023},
volume = {24},
number = {6},
pages = {1--6},
url = {http://jmlr.org/papers/v24/20-1355.html}
}
```
## Acknowledgements
The authors gratefully acknowledge the D3M program of the Defense Advanced Research Projects Agency (DARPA) administered through AFRL contract FA8750-17-2-0116; the Texas A&M College of Engineering, and Texas A&M University.
================================================
FILE: RELEASE.md
================================================
# Release v2.0.0
## Breaking changes
* Requires `keras>=3.0.0` instead of `tf.keras`.
* Removed the structured data related tasks by removing the following public
APIs:
* `CategoricalToNumerical`
* `MultiCategoryEncoding`
* `StructuredDataInput`
* `StructuredDataBlock`
* `StructuredDataClassifier`
* `StructuredDataRegressor`
* Removed the Time series related tasks by removing the following public APIs:
* `TimeseriesInput`
* `TimeseriesForecaster`
* Reduced search space of Text related tasks by removing the following blocks.
* `Embedding`
* `TextToIntSequence`
* `TextToNgramVector`
* `Transformer`
# Release v1.1.0
## Breaking changes
* This only affect you if you use `BertTokenizer` or `BertEncoder` in AutoKeras
explicity. You are not affected if you only use `BertBlock`, `TextClassifier`
or `TextRegressor`. Removed the AutoKeras implementation of `BertTokenizer`
and `BertEncoder`. Use `keras-nlp` implementation instead.
## New features
## Bug fixes
* Now also support `numpy>=1.24`.
================================================
FILE: autokeras/__init__.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from autokeras.auto_model import AutoModel
from autokeras.blocks import ClassificationHead
from autokeras.blocks import ConvBlock
from autokeras.blocks import DenseBlock
from autokeras.blocks import EfficientNetBlock
from autokeras.blocks import Embedding
from autokeras.blocks import Flatten
from autokeras.blocks import ImageAugmentation
from autokeras.blocks import ImageBlock
from autokeras.blocks import Merge
from autokeras.blocks import Normalization
from autokeras.blocks import RegressionHead
from autokeras.blocks import ResNetBlock
from autokeras.blocks import RNNBlock
from autokeras.blocks import SpatialReduction
from autokeras.blocks import StructuredDataBlock
from autokeras.blocks import TemporalReduction
from autokeras.blocks import TextBlock
from autokeras.blocks import XceptionBlock
from autokeras.engine.block import Block
from autokeras.engine.head import Head
from autokeras.engine.node import Node
from autokeras.keras_layers import CastToFloat32
from autokeras.keras_layers import ExpandLastDim
from autokeras.nodes import ImageInput
from autokeras.nodes import Input
from autokeras.nodes import StructuredDataInput
from autokeras.nodes import TextInput
from autokeras.tasks import ImageClassifier
from autokeras.tasks import ImageRegressor
from autokeras.tasks import StructuredDataClassifier
from autokeras.tasks import StructuredDataRegressor
from autokeras.tasks import TextClassifier
from autokeras.tasks import TextRegressor
from autokeras.tuners import BayesianOptimization
from autokeras.tuners import Greedy
from autokeras.tuners import Hyperband
from autokeras.tuners import RandomSearch
__version__ = "3.0.0"
CUSTOM_OBJECTS = {
"CastToFloat32": CastToFloat32,
"ExpandLastDim": ExpandLastDim,
}
================================================
FILE: autokeras/adapters/__init__.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from autokeras.adapters.input_adapters import ImageAdapter
from autokeras.adapters.input_adapters import InputAdapter
from autokeras.adapters.input_adapters import StructuredDataAdapter
from autokeras.adapters.input_adapters import TextAdapter
from autokeras.adapters.output_adapters import ClassificationAdapter
from autokeras.adapters.output_adapters import RegressionAdapter
================================================
FILE: autokeras/adapters/input_adapters.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
from autokeras.engine import adapter as adapter_module
class InputAdapter(adapter_module.Adapter):
def check(self, x):
"""Record any information needed by transform."""
if not isinstance(x, np.ndarray):
raise TypeError(
"Expect the data to Input to be numpy.ndarray, "
"but got {type}.".format(type=type(x))
)
if isinstance(x, np.ndarray) and not np.issubdtype(x.dtype, np.number):
raise TypeError(
"Expect the data to Input to be numerical, but got "
"{type}.".format(type=x.dtype)
)
class ImageAdapter(adapter_module.Adapter):
def check(self, x):
"""Record any information needed by transform."""
if not isinstance(x, np.ndarray):
raise TypeError(
"Expect the data to ImageInput to be numpy.ndarray, "
"but got {type}.".format(type=type(x))
)
if isinstance(x, np.ndarray) and not np.issubdtype(x.dtype, np.number):
raise TypeError(
"Expect the data to ImageInput to be numerical, but got "
"{type}.".format(type=x.dtype)
)
class TextAdapter(adapter_module.Adapter):
def check(self, x):
"""Record any information needed by transform."""
if not isinstance(x, np.ndarray):
raise TypeError(
"Expect the data to TextInput to be numpy.ndarray, "
"but got {type}.".format(type=type(x))
)
class StructuredDataAdapter(adapter_module.Adapter):
def check(self, x):
if not isinstance(x, np.ndarray):
raise TypeError(
"Unsupported type {type} for "
"{name}.".format(type=type(x), name=self.__class__.__name__)
)
================================================
FILE: autokeras/adapters/input_adapters_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import pandas as pd
import pytest
from autokeras import test_utils
from autokeras.adapters import input_adapters
from autokeras.utils import data_utils
def test_image_input_adapter_transform_to_dataset():
x = test_utils.generate_data()
adapter = input_adapters.ImageAdapter()
assert isinstance(adapter.adapt(x), np.ndarray)
def test_image_input_unsupported_type():
x = "unknown"
adapter = input_adapters.ImageAdapter()
with pytest.raises(TypeError) as info:
x = adapter.adapt(x)
assert "Expect the data to ImageInput to be numpy" in str(info.value)
def test_image_input_numerical():
x = np.array([[["unknown"]]])
adapter = input_adapters.ImageAdapter()
with pytest.raises(TypeError) as info:
x = adapter.adapt(x)
assert "Expect the data to ImageInput to be numerical" in str(info.value)
def test_input_type_error():
x = "unknown"
adapter = input_adapters.InputAdapter()
with pytest.raises(TypeError) as info:
x = adapter.adapt(x)
assert "Expect the data to Input to be numpy" in str(info.value)
def test_input_numerical():
x = np.array([[["unknown"]]])
adapter = input_adapters.InputAdapter()
with pytest.raises(TypeError) as info:
x = adapter.adapt(x)
assert "Expect the data to Input to be numerical" in str(info.value)
def test_text_adapt_np():
x = np.array(["a b c", "b b c"])
adapter = input_adapters.TextAdapter()
x = adapter.adapt(x)
assert data_utils.dataset_shape(x) == [2]
assert isinstance(x, np.ndarray)
def test_text_input_type_error():
x = "unknown"
adapter = input_adapters.TextAdapter()
with pytest.raises(TypeError) as info:
x = adapter.adapt(x)
assert "Expect the data to TextInput to be numpy" in str(info.value)
def test_structured_data_input_unsupported_type_error():
with pytest.raises(TypeError) as info:
adapter = input_adapters.StructuredDataAdapter()
adapter.adapt("unknown")
assert "Unsupported type" in str(info.value)
def test_structured_data_input_transform_to_dataset():
x = pd.read_csv(test_utils.TRAIN_CSV_PATH).to_numpy().astype(str)
adapter = input_adapters.StructuredDataAdapter()
x = adapter.adapt(x)
assert isinstance(x, np.ndarray)
================================================
FILE: autokeras/adapters/output_adapters.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
from autokeras.engine import adapter as adapter_module
class HeadAdapter(adapter_module.Adapter):
def __init__(self, name, **kwargs):
super().__init__(**kwargs)
self.name = name
def check(self, dataset):
if not isinstance(dataset, np.ndarray):
raise TypeError(
f"Expect the target data of {self.name} to be"
f" np.ndarray, but got {type(dataset)}."
)
class ClassificationAdapter(HeadAdapter):
pass
class RegressionAdapter(HeadAdapter):
pass
================================================
FILE: autokeras/adapters/output_adapters_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import pytest
from autokeras.adapters import output_adapters
def test_unsupported_types_error():
adapter = output_adapters.ClassificationAdapter(name="a")
with pytest.raises(TypeError) as info:
adapter.adapt(1)
assert "Expect the target data of a to be" in str(info.value)
def test_reg_head_transform_1d_np():
adapter = output_adapters.RegressionAdapter(name="a")
y = adapter.adapt(np.random.rand(10))
assert isinstance(y, np.ndarray)
================================================
FILE: autokeras/analysers/__init__.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from autokeras.analysers.input_analysers import CATEGORICAL
from autokeras.analysers.input_analysers import NUMERICAL
from autokeras.analysers.input_analysers import ImageAnalyser
from autokeras.analysers.input_analysers import InputAnalyser
from autokeras.analysers.input_analysers import StructuredDataAnalyser
from autokeras.analysers.input_analysers import TextAnalyser
from autokeras.analysers.output_analysers import ClassificationAnalyser
from autokeras.analysers.output_analysers import RegressionAnalyser
================================================
FILE: autokeras/analysers/input_analysers.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
from autokeras.engine import analyser
CATEGORICAL = "categorical"
NUMERICAL = "numerical"
class InputAnalyser(analyser.Analyser):
def finalize(self):
return
class ImageAnalyser(InputAnalyser):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def finalize(self):
if len(self.shape) not in [3, 4]:
raise ValueError(
"Expect the data to ImageInput to have shape (batch_size, "
"height, width, channels) or (batch_size, height, width) "
"dimensions, but got input shape {shape}".format(
shape=self.shape
)
)
class TextAnalyser(InputAnalyser):
def correct_shape(self):
if len(self.shape) == 1:
return True
return len(self.shape) == 2 and self.shape[1] == 1
def finalize(self):
if not self.correct_shape():
raise ValueError(
"Expect the data to TextInput to have shape "
"(batch_size, 1), but "
"got input shape {shape}.".format(shape=self.shape)
)
if not (self.dtype == "string"):
raise TypeError(
"Expect the data to TextInput to be strings, but got "
"{type}.".format(type=self.dtype)
)
class StructuredDataAnalyser(InputAnalyser):
def __init__(self, column_names=None, column_types=None, **kwargs):
super().__init__(**kwargs)
self.column_names = column_names
self.column_types = column_types
# Variables for inferring column types.
self.count_numerical = None
self.count_categorical = None
self.count_unique_numerical = []
self.num_col = None
def update(self, data):
super().update(data)
# The super class set self.dtype to "string" based on the input numpy
# array. However, the preprocessor will encode it to float32. So, set
# self.dtype to "float32", which would be propagated to the Keras Input
# node.
self.dtype = "float32"
if len(self.shape) != 2:
return
# data is a numpy array containing all the data.
self.num_col = data.shape[1]
self.count_numerical = np.zeros(self.num_col)
self.count_categorical = np.zeros(self.num_col)
self.count_unique_numerical = [{} for _ in range(self.num_col)]
for i in range(self.num_col):
self._update_column(data[:, i], i)
def _update_column(self, column_data, i):
# Vectorized check for numerical values
def is_numerical(x):
try:
float(x)
return True
except (ValueError, TypeError):
return False
numerical_mask = np.vectorize(is_numerical)(column_data)
self.count_numerical[i] = np.sum(numerical_mask)
self.count_categorical[i] = len(column_data) - np.sum(numerical_mask)
if np.any(numerical_mask):
# Get numerical values
numerical_values = column_data[numerical_mask]
# Handle bytes
numerical_values = np.array(
[
x.decode("utf-8") if isinstance(x, bytes) else x
for x in numerical_values
]
)
numerical_floats = numerical_values.astype(float)
unique_vals, counts = np.unique(
numerical_floats, return_counts=True
)
self.count_unique_numerical[i] = dict(zip(unique_vals, counts))
def finalize(self):
self.check()
self.infer_column_types()
def get_input_name(self):
return "StructuredDataInput"
def check(self):
if len(self.shape) != 2:
raise ValueError(
"Expect the data to {input_name} to have shape "
"(batch_size, num_features), but "
"got input shape {shape}.".format(
input_name=self.get_input_name(), shape=self.shape
)
)
# Fill in the column_names
if self.column_names is None:
if self.column_types:
raise ValueError(
"column_names must be specified, if "
"column_types is specified."
)
self.column_names = [str(index) for index in range(self.shape[1])]
# Check if column_names has the correct length.
if len(self.column_names) != self.shape[1]:
raise ValueError(
"Expect column_names to have length {expect} "
"but got {actual}.".format(
expect=self.shape[1], actual=len(self.column_names)
)
)
def infer_column_types(self):
column_types = {}
for i in range(self.num_col):
if self.count_categorical[i] > 0:
column_types[self.column_names[i]] = CATEGORICAL
elif (
len(self.count_unique_numerical[i]) / self.count_numerical[i]
< 0.05
):
column_types[self.column_names[i]] = CATEGORICAL
else:
column_types[self.column_names[i]] = NUMERICAL
# Partial column_types is provided.
if self.column_types is None:
self.column_types = {}
for key, value in column_types.items():
if key not in self.column_types:
self.column_types[key] = value
================================================
FILE: autokeras/analysers/input_analysers_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
import numpy as np
import pandas as pd
import pytest
from autokeras import test_utils
from autokeras.analysers import input_analysers
def test_structured_data_input_less_col_name_error():
with pytest.raises(ValueError) as info:
analyser = input_analysers.StructuredDataAnalyser(
column_names=list(range(8))
)
dataset = np.random.rand(20, 10)
analyser.update(dataset)
analyser.finalize()
assert "Expect column_names to have length" in str(info.value)
def test_structured_data_infer_col_types():
analyser = input_analysers.StructuredDataAnalyser(
column_names=test_utils.COLUMN_NAMES,
column_types=None,
)
x = pd.read_csv(test_utils.TRAIN_CSV_PATH)
x.pop("survived")
dataset = x.values.astype(str)
analyser.update(dataset)
analyser.finalize()
assert analyser.column_types == test_utils.COLUMN_TYPES
def test_dont_infer_specified_column_types():
column_types = copy.copy(test_utils.COLUMN_TYPES)
column_types.pop("sex")
column_types["age"] = "categorical"
analyser = input_analysers.StructuredDataAnalyser(
column_names=test_utils.COLUMN_NAMES,
column_types=column_types,
)
x = pd.read_csv(test_utils.TRAIN_CSV_PATH)
x.pop("survived")
dataset = x.values.astype(str)
analyser.update(dataset)
analyser.finalize()
assert analyser.column_types["age"] == "categorical"
def test_structured_data_input_with_illegal_dim():
analyser = input_analysers.StructuredDataAnalyser(
column_names=test_utils.COLUMN_NAMES,
column_types=None,
)
dataset = np.random.rand(100, 32, 32)
with pytest.raises(ValueError) as info:
analyser.update(dataset)
analyser.finalize()
assert "Expect the data to StructuredDataInput to have shape" in str(
info.value
)
def test_image_input_analyser_shape_is_list_of_int():
analyser = input_analysers.ImageAnalyser()
dataset = np.random.rand(100, 32, 32, 3)
analyser.update(dataset)
analyser.finalize()
assert isinstance(analyser.shape, list)
assert all(map(lambda x: isinstance(x, int), analyser.shape))
def test_image_input_with_three_dim():
analyser = input_analysers.ImageAnalyser()
dataset = np.random.rand(100, 32, 32)
analyser.update(dataset)
analyser.finalize()
assert len(analyser.shape) == 3
def test_image_input_with_illegal_dim():
analyser = input_analysers.ImageAnalyser()
dataset = np.random.rand(100, 32)
with pytest.raises(ValueError) as info:
analyser.update(dataset)
analyser.finalize()
assert "Expect the data to ImageInput to have shape" in str(info.value)
def test_text_input_with_illegal_dim():
analyser = input_analysers.TextAnalyser()
dataset = np.random.rand(100, 32)
with pytest.raises(ValueError) as info:
analyser.update(dataset)
analyser.finalize()
assert "Expect the data to TextInput to have shape" in str(info.value)
def test_text_analyzer_with_one_dim_doesnt_crash():
analyser = input_analysers.TextAnalyser()
dataset = np.array(["a b c", "b b c"])
analyser.update(dataset)
analyser.finalize()
def test_text_illegal_type_error():
analyser = input_analysers.TextAnalyser()
dataset = np.random.rand(100, 1)
with pytest.raises(TypeError) as info:
analyser.update(dataset)
analyser.finalize()
assert "Expect the data to TextInput to be strings" in str(info.value)
================================================
FILE: autokeras/analysers/output_analysers.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
from autokeras.engine import analyser
class TargetAnalyser(analyser.Analyser):
def __init__(self, name=None, **kwargs):
super().__init__(**kwargs)
self.name = name
class ClassificationAnalyser(TargetAnalyser):
def __init__(self, num_classes=None, multi_label=False, **kwargs):
super().__init__(**kwargs)
self.num_classes = num_classes
self.label_encoder = None
self.multi_label = multi_label
self.labels = set()
def update(self, data):
super().update(data)
if len(self.shape) > 2:
raise ValueError(
"Expect the target data for {name} to have shape "
"(batch_size, num_classes), "
"but got {shape}.".format(name=self.name, shape=self.shape)
)
if len(self.shape) > 1 and self.shape[1] > 1:
return
self.labels = self.labels.union(set(np.unique(data)))
def finalize(self):
# TODO: support raw string labels for multi-label.
self.labels = sorted(list(self.labels))
# Infer the num_classes if not specified.
if not self.num_classes:
if self.encoded:
# Single column with 0s and 1s.
if len(self.shape) == 1 or self.shape[1:] == [1]:
self.num_classes = 2
else:
self.num_classes = self.shape[1]
else:
self.num_classes = len(self.labels)
if self.num_classes < 2:
raise ValueError(
"Expect the target data for {name} to have "
"at least 2 classes, but got {num_classes}.".format(
name=self.name, num_classes=self.num_classes
)
)
# Check shape equals expected shape.
expected = self.get_expected_shape()
actual = self.shape[1:]
if len(actual) == 0:
actual = [1]
if self.encoded and actual != expected:
raise ValueError(
"Expect the target data for {name} to have "
"shape {expected}, but got {actual}.".format(
name=self.name, expected=expected, actual=self.shape[1:]
)
)
def get_expected_shape(self):
# Compute expected shape from num_classes.
if self.num_classes == 2 and not self.multi_label:
return [1]
return [self.num_classes]
@property
def encoded(self):
return self.encoded_for_sigmoid or self.encoded_for_softmax
@property
def encoded_for_sigmoid(self):
if len(self.labels) != 2:
return False
return sorted(self.labels) == [0, 1]
@property
def encoded_for_softmax(self):
return len(self.shape) > 1 and self.shape[1] > 1
class RegressionAnalyser(TargetAnalyser):
def __init__(self, output_dim=None, **kwargs):
super().__init__(**kwargs)
self.output_dim = output_dim
def finalize(self):
if self.output_dim and (self.expected_dim() != self.output_dim):
raise ValueError(
"Expect the target data for {name} to have shape "
"(batch_size, {output_dim}), "
"but got {shape}.".format(
name=self.name, output_dim=self.output_dim, shape=self.shape
)
)
def expected_dim(self):
if len(self.shape) == 1:
return 1
return self.shape[1]
================================================
FILE: autokeras/analysers/output_analysers_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import pytest
from autokeras import test_utils
from autokeras.analysers import output_analysers
def test_clf_head_one_hot_shape_error():
analyser = output_analysers.ClassificationAnalyser(name="a", num_classes=9)
dataset = test_utils.generate_one_hot_labels(num_classes=10)
with pytest.raises(ValueError) as info:
analyser.update(dataset)
analyser.finalize()
assert "Expect the target data for a to have shape" in str(info.value)
def test_clf_head_more_dim_error():
analyser = output_analysers.ClassificationAnalyser(name="a", num_classes=9)
dataset = np.random.rand(100, 32, 32, 3)
with pytest.raises(ValueError) as info:
analyser.update(dataset)
analyser.finalize()
assert "Expect the target data for a to have shape" in str(info.value)
def test_wrong_num_classes_error():
analyser = output_analysers.ClassificationAnalyser(name="a", num_classes=5)
dataset = np.random.rand(10, 3)
with pytest.raises(ValueError) as info:
analyser.update(dataset)
analyser.finalize()
assert "Expect the target data for a to have shape" in str(info.value)
def test_one_class_error():
analyser = output_analysers.ClassificationAnalyser(name="a")
dataset = np.array(["a", "a", "a"])
with pytest.raises(ValueError) as info:
analyser.update(dataset)
analyser.finalize()
assert "Expect the target data for a to have at least 2 classes" in str(
info.value
)
def test_infer_ten_classes():
analyser = output_analysers.ClassificationAnalyser(name="a")
dataset = test_utils.generate_one_hot_labels(num_classes=10)
analyser.update(dataset)
analyser.finalize()
assert analyser.num_classes == 10
def test_infer_single_column_two_classes():
analyser = output_analysers.ClassificationAnalyser(name="a")
dataset = np.random.randint(0, 2, 10)
analyser.update(dataset)
analyser.finalize()
assert analyser.num_classes == 2
def test_specify_five_classes():
analyser = output_analysers.ClassificationAnalyser(name="a", num_classes=5)
dataset = np.random.rand(10, 5)
analyser.update(dataset)
analyser.finalize()
assert analyser.num_classes == 5
def test_specify_two_classes_fit_single_column():
analyser = output_analysers.ClassificationAnalyser(name="a", num_classes=2)
dataset = np.random.rand(10, 1)
analyser.update(dataset)
analyser.finalize()
assert analyser.num_classes == 2
def test_multi_label_two_classes_has_two_columns():
analyser = output_analysers.ClassificationAnalyser(
name="a", multi_label=True
)
dataset = np.random.rand(10, 2)
analyser.update(dataset)
analyser.finalize()
assert analyser.encoded
def test_reg_with_specified_output_dim_error():
analyser = output_analysers.RegressionAnalyser(name="a", output_dim=3)
dataset = np.random.rand(10, 2)
with pytest.raises(ValueError) as info:
analyser.update(dataset)
analyser.finalize()
assert "Expect the target data for a to have shape" in str(info.value)
def test_reg_with_specified_output_dim_and_single_column_doesnt_crash():
analyser = output_analysers.RegressionAnalyser(name="a", output_dim=1)
dataset = np.random.rand(10, 1)
analyser.update(dataset)
analyser.finalize()
def test_regression_analyser_expected_dim_1d():
analyser = output_analysers.RegressionAnalyser()
analyser.shape = [10] # 1D shape
assert analyser.expected_dim() == 1
def test_regression_analyser_expected_dim_2d():
analyser = output_analysers.RegressionAnalyser()
analyser.shape = [10, 3] # 2D shape
assert analyser.expected_dim() == 3
================================================
FILE: autokeras/auto_model.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pathlib import Path
from typing import List
from typing import Optional
from typing import Type
from typing import Union
import keras
import numpy as np
import tree
from autokeras import blocks
from autokeras import graph as graph_module
from autokeras import pipeline
from autokeras import tuners
from autokeras.engine import head as head_module
from autokeras.engine import node as node_module
from autokeras.engine import tuner
from autokeras.nodes import Input
from autokeras.utils import data_utils
from autokeras.utils import utils
TUNER_CLASSES = {
"bayesian": tuners.BayesianOptimization,
"random": tuners.RandomSearch,
"hyperband": tuners.Hyperband,
"greedy": tuners.Greedy,
}
def get_tuner_class(tuner):
if isinstance(tuner, str) and tuner in TUNER_CLASSES:
return TUNER_CLASSES.get(tuner)
else:
raise ValueError(
'Expected the tuner argument to be one of "greedy", '
'"random", "hyperband", or "bayesian", '
"but got {tuner}".format(tuner=tuner)
)
class AutoModel(object):
"""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 AutoModel has two use cases. In the first case, the user only specifies
the input nodes and output heads of the AutoModel. The AutoModel infers the
rest part of the model. In the second case, user can specify the high-level
architecture of the AutoModel by connecting the Blocks with the functional
API, which is the same as the Keras
[functional
API](https://keras.io/api/models/model/#with-the-functional-api).
# Example
```python
# The user only specifies the input nodes and output heads.
import autokeras as ak
ak.AutoModel(
inputs=[ak.ImageInput(), ak.TextInput()],
outputs=[ak.ClassificationHead(), ak.RegressionHead()]
)
```
```python
# The user specifies the high-level architecture.
import autokeras as ak
image_input = ak.ImageInput()
image_output = ak.ImageBlock()(image_input)
text_input = ak.TextInput()
text_output = ak.TextBlock()(text_input)
output = ak.Merge()([image_output, text_output])
classification_output = ak.ClassificationHead()(output)
regression_output = ak.RegressionHead()(output)
ak.AutoModel(
inputs=[image_input, text_input],
outputs=[classification_output, regression_output]
)
```
# Arguments
inputs: A list of Node instances.
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.
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. 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'.
tuner: String or subclass of AutoTuner. If string, it should be one of
'greedy', 'bayesian', 'hyperband' or 'random'. It can also be a
subclass of AutoTuner. Defaults to 'greedy'.
overwrite: Boolean. Defaults to `False`. If `False`, reloads an existing
project of the same name if one is found. Otherwise, overwrites the
project.
seed: Int. Random seed.
max_model_size: Int. Maximum number of scalars in the parameters of a
model. Models larger than this are rejected.
**kwargs: Any arguments supported by keras_tuner.Tuner.
"""
def __init__(
self,
inputs: Union[Input, List[Input]],
outputs: Union[head_module.Head, node_module.Node, list],
project_name: str = "auto_model",
max_trials: int = 100,
directory: Union[str, Path, None] = None,
objective: str = "val_loss",
tuner: Union[str, Type[tuner.AutoTuner]] = "greedy",
overwrite: bool = False,
seed: Optional[int] = None,
max_model_size: Optional[int] = None,
**kwargs
):
self.inputs = tree.flatten(inputs)
self.outputs = tree.flatten(outputs)
self.seed = seed
if seed:
np.random.seed(seed)
# TODO: Support passing a tuner instance.
# Initialize the hyper_graph.
graph = self._build_graph()
if isinstance(tuner, str):
tuner = get_tuner_class(tuner)
self.tuner = tuner(
hypermodel=graph,
overwrite=overwrite,
objective=objective,
max_trials=max_trials,
directory=directory,
seed=self.seed,
project_name=project_name,
max_model_size=max_model_size,
**kwargs
)
self.overwrite = overwrite
self._heads = [output_node.in_blocks[0] for output_node in self.outputs]
@property
def objective(self):
return self.tuner.objective
@property
def max_trials(self):
return self.tuner.max_trials
@property
def directory(self):
return self.tuner.directory
@property
def project_name(self):
return self.tuner.project_name
def _assemble(self):
"""Assemble the Blocks based on the input output nodes."""
inputs = tree.flatten(self.inputs)
outputs = tree.flatten(self.outputs)
middle_nodes = [
input_node.get_block()(input_node) for input_node in inputs
]
# Merge the middle nodes.
if len(middle_nodes) > 1:
output_node = blocks.Merge()(middle_nodes)
else:
output_node = middle_nodes[0]
outputs = tree.flatten(
[output_blocks(output_node) for output_blocks in outputs]
)
return graph_module.Graph(inputs=inputs, outputs=outputs)
def _build_graph(self):
# Using functional API.
if all(
[isinstance(output, node_module.Node) for output in self.outputs]
):
graph = graph_module.Graph(inputs=self.inputs, outputs=self.outputs)
# Using input/output API.
elif all(
[isinstance(output, head_module.Head) for output in self.outputs]
):
# Clear session to reset get_uid(). The names of the blocks will
# start to count from 1 for new blocks in a new AutoModel
# afterwards. When initializing multiple AutoModel with Task API,
# if not counting from 1 for each of the AutoModel, the predefined
# hp values in task specifiec tuners would not match the names.
keras.backend.clear_session()
graph = self._assemble()
self.outputs = graph.outputs
keras.backend.clear_session()
return graph
def fit(
self,
x=None,
y=None,
batch_size=32,
epochs=None,
callbacks=None,
validation_split=0.2,
validation_data=None,
verbose=1,
**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. Training data x.
y: numpy.ndarray. Training data y.
batch_size: Int. Number of samples per gradient update. Defaults to
32.
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. Defaults to 0.2.
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.
verbose: 0, 1, or 2. Verbosity mode. 0 = silent, 1 = progress bar,
2 = one line per epoch. Note that the progress bar is not
particularly useful when logged to a file, so verbose=2 is
recommended when not running interactively (eg, in a production
environment). Controls the verbosity of both KerasTuner search
and
[keras.Model.fit](https://keras.io/api/models/model_training_apis/#fit-method)
**kwargs: Any arguments supported by
[keras.Model.fit](https://keras.io/api/models/model_training_apis/#fit-method).
# Returns
history: A Keras History object corresponding to the best model.
Its History.history attribute is a record of training
loss values and metrics values at successive epochs, as well as
validation loss values and validation metrics values (if
applicable).
"""
# Check validation information.
if not validation_data and not validation_split:
raise ValueError(
"Either validation_data or a non-zero validation_split "
"should be provided."
)
if validation_data:
validation_split = 0
dataset, validation_data = self._check_and_adapt(
x=x, y=y, validation_data=validation_data
)
self._analyze_data(dataset)
self._build_hyper_pipeline()
# Split the data with validation_split.
if validation_data is None and validation_split:
dataset, validation_data = data_utils.split_dataset(
dataset, validation_split
)
x, y = dataset
history = self.tuner.search(
x=x,
y=y,
epochs=epochs,
callbacks=callbacks,
validation_data=validation_data,
validation_split=validation_split,
verbose=verbose,
batch_size=batch_size,
**kwargs
)
return history
def _adapt(self, dataset, hms):
sources = tree.flatten(dataset)
adapted = []
for source, hm in zip(sources, hms):
source = hm.get_adapter().adapt(source)
adapted.append(source)
if len(adapted) == 1:
return adapted[0]
return tuple(adapted)
def _check_numpy_arrays(self, data, name, in_val=""):
"""Check if all elements in the nested structure are numpy arrays."""
if not all([isinstance(a, np.ndarray) for a in tree.flatten(data)]):
raise ValueError(
"Expected "
"{name}{in_val} to be a numpy array, got {type}".format(
name=name,
in_val=in_val,
type=[type(a) for a in tree.flatten(data)],
)
)
def _check_array_count(self, actual, expected, name, in_val):
"""Check if the number of arrays matches the expected count."""
if actual != expected:
raise ValueError(
"Expected {name}{in_val} to have {expected} arrays, "
"but got {actual}".format(
name=name,
in_val=in_val,
expected=expected,
actual=actual,
)
)
def _check_data_format(self, x, y, validation=False, predict=False):
"""Check if the dataset has the same number of IOs with the model."""
if validation:
in_val = " in validation_data"
else:
in_val = ""
self._check_numpy_arrays(x, "x", in_val)
if y is not None:
self._check_numpy_arrays(y, "y", in_val)
self._check_array_count(
len(tree.flatten(x)), len(self.inputs), "x", in_val
)
# When predicting, y is not required.
if not predict and y is not None:
self._check_array_count(
len(tree.flatten(y)), len(self.outputs), "y", in_val
)
def _analyze_data(self, dataset):
input_analysers = [node.get_analyser() for node in self.inputs]
output_analysers = [head.get_analyser() for head in self._heads]
analysers = input_analysers + output_analysers
np_arrays = tree.flatten(dataset)
for array, analyser in zip(np_arrays, analysers):
analyser.update(array)
for analyser in analysers:
analyser.finalize()
for hm, analyser in zip(self.inputs + self._heads, analysers):
hm.config_from_analyser(analyser)
def _build_hyper_pipeline(self):
self.tuner.hyper_pipeline = pipeline.HyperPipeline(
inputs=[node.get_hyper_preprocessors() for node in self.inputs],
outputs=[head.get_hyper_preprocessors() for head in self._heads],
)
self.tuner.hypermodel.hyper_pipeline = self.tuner.hyper_pipeline
def _check_and_adapt(self, x, y, validation_data):
# Convert training data.
self._check_data_format(x, y)
x = self._adapt(x, self.inputs)
y = self._adapt(y, self._heads)
# Convert validation data
if validation_data:
self._check_data_format(*validation_data, validation=True)
x_val, y_val = validation_data
x_val = self._adapt(x_val, self.inputs)
y_val = self._adapt(y_val, self._heads)
validation_data = (x_val, y_val)
return (x, y), validation_data
def predict(self, x, batch_size=32, verbose=1, **kwargs):
"""Predict the output for a given testing data.
# Arguments
x: Any allowed types according to the input node. Testing data.
batch_size: Number of samples per batch.
If unspecified, batch_size will default to 32.
verbose: Verbosity mode. 0 = silent, 1 = progress bar.
Controls the verbosity of
[keras.Model.predict](https://keras.io/api/models/model_training_apis/#predict-method)
**kwargs: Any arguments supported by keras.Model.predict.
# Returns
A list of numpy.ndarray objects or a single numpy.ndarray.
The predicted results.
"""
self._check_data_format(x, None, predict=True)
dataset = self._adapt(x, self.inputs)
pipeline = self.tuner.get_best_pipeline()
model = self.tuner.get_best_model()
dataset = pipeline.transform_x(dataset)
y = utils.predict_with_adaptive_batch_size(
model=model,
batch_size=batch_size,
x=dataset,
verbose=verbose,
**kwargs
)
return pipeline.postprocess(y)
def evaluate(self, x, y=None, batch_size=32, verbose=1, **kwargs):
"""Evaluate the best model for the given data.
# Arguments
x: Any allowed types according to the input node. Testing data.
y: Any allowed types according to the head. Testing targets.
Defaults to None.
batch_size: Number of samples per batch.
If unspecified, batch_size will default to 32.
verbose: Verbosity mode. 0 = silent, 1 = progress bar.
Controls the verbosity of
[keras.Model.evaluate](https://keras.io/api/models/model_training_apis/#evaluate-method)
**kwargs: Any arguments supported by keras.Model.evaluate.
# Returns
Scalar test loss (if the model has a single output and no metrics)
or list of scalars (if the model has multiple outputs and/or
metrics). The attribute model.metrics_names will give you the
display labels for the scalar outputs.
"""
self._check_data_format(x, y)
x = self._adapt(x, self.inputs)
y = self._adapt(y, self._heads)
pipeline = self.tuner.get_best_pipeline()
x, y = pipeline.transform((x, y))
model = self.tuner.get_best_model()
return utils.evaluate_with_adaptive_batch_size(
model=model,
batch_size=batch_size,
x=x,
y=y,
verbose=verbose,
**kwargs
)
def export_model(self):
"""Export the best Keras Model.
# Returns
keras.Model instance. The best model found during the search, loaded
with trained weights.
"""
return self.tuner.get_best_model()
================================================
FILE: autokeras/auto_model_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from unittest import mock
import keras_tuner
import numpy as np
import pytest
import autokeras as ak
from autokeras import test_utils
def get_tuner_class(*args, **kwargs):
pipeline = mock.Mock()
pipeline.transform_x.side_effect = lambda x: x
tuner = mock.Mock()
tuner.get_best_pipeline.return_value = pipeline
tuner_class = mock.Mock()
tuner_class.return_value = tuner
return tuner_class
def test_auto_model_objective_is_kt_objective(tmp_path):
auto_model = ak.AutoModel(
ak.ImageInput(), ak.RegressionHead(), directory=tmp_path
)
assert isinstance(auto_model.objective, keras_tuner.Objective)
def test_auto_model_max_trial_field_as_specified(tmp_path):
auto_model = ak.AutoModel(
ak.ImageInput(), ak.RegressionHead(), directory=tmp_path, max_trials=10
)
assert auto_model.max_trials == 10
def test_auto_model_directory_field_as_specified(tmp_path):
auto_model = ak.AutoModel(
ak.ImageInput(), ak.RegressionHead(), directory=tmp_path
)
assert auto_model.directory == tmp_path
def test_auto_model_project_name_field_as_specified(tmp_path):
auto_model = ak.AutoModel(
ak.ImageInput(),
ak.RegressionHead(),
directory=tmp_path,
project_name="auto_model",
)
assert auto_model.project_name == "auto_model"
@mock.patch("autokeras.auto_model.get_tuner_class")
def test_evaluate(tuner_fn, tmp_path):
x_train = np.random.rand(100, 32)
y_train = np.random.rand(100, 1)
input_node = ak.Input()
output_node = input_node
output_node = ak.DenseBlock()(output_node)
output_node = ak.RegressionHead()(output_node)
auto_model = ak.AutoModel(
input_node, output_node, directory=tmp_path, max_trials=1
)
auto_model.fit(
x_train, y_train, epochs=1, validation_data=(x_train, y_train)
)
pipeline = tuner_fn.return_value.return_value.get_best_pipeline.return_value
pipeline.transform.return_value = (x_train, y_train)
auto_model.evaluate(x_train, y_train)
assert tuner_fn.called
def get_single_io_auto_model(tmp_path):
return ak.AutoModel(
ak.ImageInput(), ak.RegressionHead(), directory=tmp_path, max_trials=2
)
@mock.patch("autokeras.auto_model.get_tuner_class", side_effect=get_tuner_class)
def test_auto_model_predict(tuner_fn, tmp_path):
x_train = np.random.rand(100, 32, 32, 3)
y_train = np.random.rand(100, 1)
auto_model = get_single_io_auto_model(tmp_path)
auto_model.fit(x_train, y_train, epochs=2, validation_split=0.2)
auto_model.predict(x_train)
assert tuner_fn.called
@mock.patch("autokeras.auto_model.get_tuner_class")
def test_final_fit_concat(tuner_fn, tmp_path):
tuner = tuner_fn.return_value.return_value
x_train = np.random.rand(100, 32, 32, 3)
y_train = np.random.rand(100, 1)
auto_model = get_single_io_auto_model(tmp_path)
auto_model.fit(x_train, y_train, epochs=2, validation_split=0.2)
assert tuner.search.call_args_list[0][1]["validation_split"]
@mock.patch("autokeras.auto_model.get_tuner_class")
def test_final_fit_not_concat(tuner_fn, tmp_path):
tuner = tuner_fn.return_value.return_value
x_train = np.random.rand(100, 32, 32, 3)
y_train = np.random.rand(100, 1)
auto_model = get_single_io_auto_model(tmp_path)
auto_model.fit(
x_train, y_train, epochs=2, validation_data=(x_train, y_train)
)
assert not tuner.search.call_args_list[0][1]["validation_split"]
@mock.patch("autokeras.auto_model.get_tuner_class")
def test_overwrite(tuner_fn, tmp_path):
tuner_class = tuner_fn.return_value
x_train = np.random.rand(100, 32, 32, 3)
y_train = np.random.rand(100, 1)
auto_model = get_single_io_auto_model(tmp_path)
auto_model.fit(
x_train, y_train, epochs=2, validation_data=(x_train, y_train)
)
assert not tuner_class.call_args_list[0][1]["overwrite"]
@mock.patch("autokeras.auto_model.get_tuner_class")
def test_export_model(tuner_fn, tmp_path):
tuner_class = tuner_fn.return_value
tuner = tuner_class.return_value
x_train = np.random.rand(100, 32, 32, 3)
y_train = np.random.rand(100, 1)
auto_model = get_single_io_auto_model(tmp_path)
auto_model.fit(
x_train, y_train, epochs=2, validation_data=(x_train, y_train)
)
auto_model.export_model()
assert tuner.get_best_model.called
def get_multi_io_auto_model(tmp_path):
return ak.AutoModel(
[ak.ImageInput(), ak.ImageInput()],
[ak.RegressionHead(), ak.RegressionHead()],
directory=tmp_path,
max_trials=2,
overwrite=False,
)
def dataset_error(x, y, validation_data, message, tmp_path):
auto_model = get_multi_io_auto_model(tmp_path)
with pytest.raises(ValueError) as info:
auto_model.fit(x, y, epochs=2, validation_data=validation_data)
assert message in str(info.value)
@mock.patch("autokeras.auto_model.get_tuner_class", side_effect=get_tuner_class)
def test_multi_input_predict(tuner_fn, tmp_path):
auto_model = get_multi_io_auto_model(tmp_path)
x1 = test_utils.generate_data()
y1 = test_utils.generate_data(shape=(1,))
auto_model.fit(
x=(x1, x1), y=(y1, y1), epochs=2, validation_data=((x1, x1), (y1, y1))
)
auto_model.predict(x=((x1, x1),))
@mock.patch("autokeras.auto_model.get_tuner_class", side_effect=get_tuner_class)
def test_multi_input_predict2(tuner_fn, tmp_path):
auto_model = get_multi_io_auto_model(tmp_path)
x1 = test_utils.generate_data()
y1 = test_utils.generate_data(shape=(1,))
auto_model.fit(
x=(x1, x1), y=(y1, y1), epochs=2, validation_data=((x1, x1), (y1, y1))
)
auto_model.predict(x=(x1, x1))
def test_invalid_tuner_name_error(tmp_path):
with pytest.raises(ValueError) as info:
ak.AutoModel(
ak.ImageInput(),
ak.RegressionHead(),
directory=tmp_path,
tuner="unknown",
)
assert "Expected the tuner argument to be one of" in str(info.value)
def test_no_validation_data_nor_split_error(tmp_path):
auto_model = ak.AutoModel(
ak.ImageInput(), ak.RegressionHead(), directory=tmp_path
)
with pytest.raises(ValueError) as info:
auto_model.fit(
x=np.random.rand(100, 32, 32, 3),
y=np.random.rand(100, 1),
validation_split=0,
)
assert "Either validation_data or a non-zero" in str(info.value)
@mock.patch("autokeras.auto_model.get_tuner_class", side_effect=get_tuner_class)
def test_predict_tuple_x_and_tuple_y_predict_doesnt_crash(tuner_fn, tmp_path):
auto_model = ak.AutoModel(
ak.ImageInput(), ak.RegressionHead(), directory=tmp_path
)
x, y = (np.random.rand(100, 32, 32, 3),), (np.random.rand(100, 1),)
auto_model.fit(x, y)
auto_model.predict(x)
def test_fit_with_non_numpy_data_raises_error(tmp_path):
auto_model = ak.AutoModel(
ak.ImageInput(), ak.RegressionHead(), directory=tmp_path
)
x = [[[1, 2, 3]] * 32] * 32 # list, not np.ndarray
y = [1]
match_str = "Expected x to be a numpy array"
with pytest.raises(ValueError, match=match_str):
auto_model.fit(x, y)
def test_fit_with_wrong_array_count_raises_error(tmp_path):
auto_model = ak.AutoModel(
ak.ImageInput(), ak.RegressionHead(), directory=tmp_path
)
x = (
np.random.rand(10, 32, 32, 3),
np.random.rand(10, 32, 32, 3),
) # 2 arrays
y = np.random.rand(10, 1)
match_str = "Expected x to have 1 arrays, but got 2"
with pytest.raises(ValueError, match=match_str):
auto_model.fit(x, y)
================================================
FILE: autokeras/blocks/__init__.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import keras
from autokeras.blocks.basic import ConvBlock
from autokeras.blocks.basic import DenseBlock
from autokeras.blocks.basic import EfficientNetBlock
from autokeras.blocks.basic import Embedding
from autokeras.blocks.basic import ResNetBlock
from autokeras.blocks.basic import RNNBlock
from autokeras.blocks.basic import XceptionBlock
from autokeras.blocks.heads import ClassificationHead
from autokeras.blocks.heads import RegressionHead
from autokeras.blocks.preprocessing import ImageAugmentation
from autokeras.blocks.preprocessing import Normalization
from autokeras.blocks.reduction import Flatten
from autokeras.blocks.reduction import Merge
from autokeras.blocks.reduction import SpatialReduction
from autokeras.blocks.reduction import TemporalReduction
from autokeras.blocks.wrapper import GeneralBlock
from autokeras.blocks.wrapper import ImageBlock
from autokeras.blocks.wrapper import StructuredDataBlock
from autokeras.blocks.wrapper import TextBlock
from autokeras.utils import utils
def serialize(obj):
return utils.serialize_keras_object(obj)
def deserialize(config, custom_objects=None):
return utils.deserialize_keras_object(
config,
module_objects=globals(),
custom_objects=custom_objects,
)
================================================
FILE: autokeras/blocks/basic.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional
from typing import Union
import keras
import tree
from keras import applications
from keras import layers
from keras_tuner.engine import hyperparameters
from autokeras.blocks import reduction
from autokeras.engine import block as block_module
from autokeras.utils import io_utils
from autokeras.utils import layer_utils
from autokeras.utils import utils
RESNET_V1 = {
"resnet50": applications.ResNet50,
"resnet101": applications.ResNet101,
"resnet152": applications.ResNet152,
}
RESNET_V2 = {
"resnet50_v2": applications.ResNet50V2,
"resnet101_v2": applications.ResNet101V2,
"resnet152_v2": applications.ResNet152V2,
}
EFFICIENT_VERSIONS = {
"b0": applications.EfficientNetB0,
"b1": applications.EfficientNetB1,
"b2": applications.EfficientNetB2,
"b3": applications.EfficientNetB3,
"b4": applications.EfficientNetB4,
"b5": applications.EfficientNetB5,
"b6": applications.EfficientNetB6,
"b7": applications.EfficientNetB7,
}
PRETRAINED = "pretrained"
@keras.utils.register_keras_serializable(package="autokeras")
class DenseBlock(block_module.Block):
"""Block for Dense layers.
# Arguments
num_layers: Int or keras_tuner.engine.hyperparameters.Choice.
The number of Dense layers in the block.
If left unspecified, it will be tuned automatically.
num_units: Int or keras_tuner.engine.hyperparameters.Choice.
The number of units in each dense layer.
If left unspecified, it will be tuned automatically.
use_bn: Boolean. Whether to use BatchNormalization layers.
If left unspecified, it will be tuned automatically.
dropout: Float or keras_tuner.engine.hyperparameters.Choice.
The dropout rate for the layers.
If left unspecified, it will be tuned automatically.
"""
def __init__(
self,
num_layers: Optional[Union[int, hyperparameters.Choice]] = None,
num_units: Optional[Union[int, hyperparameters.Choice]] = None,
use_batchnorm: Optional[bool] = None,
dropout: Optional[Union[float, hyperparameters.Choice]] = None,
**kwargs,
):
super().__init__(**kwargs)
self.num_layers = utils.get_hyperparameter(
num_layers,
hyperparameters.Choice("num_layers", [1, 2, 3], default=2),
int,
)
self.num_units = utils.get_hyperparameter(
num_units,
hyperparameters.Choice(
"num_units", [16, 32, 64, 128, 256, 512, 1024], default=32
),
int,
)
self.use_batchnorm = use_batchnorm
self.dropout = utils.get_hyperparameter(
dropout,
hyperparameters.Choice("dropout", [0.0, 0.25, 0.5], default=0.0),
float,
)
def get_config(self):
config = super().get_config()
config.update(
{
"num_layers": io_utils.serialize_block_arg(self.num_layers),
"num_units": io_utils.serialize_block_arg(self.num_units),
"use_batchnorm": self.use_batchnorm,
"dropout": io_utils.serialize_block_arg(self.dropout),
}
)
return config
@classmethod
def from_config(cls, config):
config["num_layers"] = io_utils.deserialize_block_arg(
config["num_layers"]
)
config["num_units"] = io_utils.deserialize_block_arg(
config["num_units"]
)
config["dropout"] = io_utils.deserialize_block_arg(config["dropout"])
return cls(**config)
def build(self, hp, inputs=None):
inputs = tree.flatten(inputs)
utils.validate_num_inputs(inputs, 1)
input_node = inputs[0]
output_node = input_node
output_node = reduction.Flatten().build(hp, output_node)
use_batchnorm = self.use_batchnorm
if use_batchnorm is None:
use_batchnorm = hp.Boolean("use_batchnorm", default=False)
for i in range(utils.add_to_hp(self.num_layers, hp)):
units = utils.add_to_hp(self.num_units, hp, "units_{i}".format(i=i))
output_node = layers.Dense(units)(output_node)
if use_batchnorm:
output_node = layers.BatchNormalization()(output_node)
output_node = layers.ReLU()(output_node)
if utils.add_to_hp(self.dropout, hp) > 0:
output_node = layers.Dropout(utils.add_to_hp(self.dropout, hp))(
output_node
)
return output_node
@keras.utils.register_keras_serializable(package="autokeras")
class RNNBlock(block_module.Block):
"""An RNN Block.
# Arguments
return_sequences: Boolean. Whether to return the last output in the
output sequence, or the full sequence. Defaults to False.
bidirectional: Boolean or keras_tuner.engine.hyperparameters.Boolean.
Bidirectional RNN. If left unspecified, it will be
tuned automatically.
num_layers: Int or keras_tuner.engine.hyperparameters.Choice.
The number of layers in RNN. If left unspecified, it will
be tuned automatically.
layer_type: String or or keras_tuner.engine.hyperparameters.Choice.
'gru' or 'lstm'. If left unspecified, it will be tuned
automatically.
"""
def __init__(
self,
return_sequences: bool = False,
bidirectional: Optional[Union[bool, hyperparameters.Boolean]] = None,
num_layers: Optional[Union[int, hyperparameters.Choice]] = None,
layer_type: Optional[Union[str, hyperparameters.Choice]] = None,
**kwargs,
):
super().__init__(**kwargs)
self.return_sequences = return_sequences
self.bidirectional = utils.get_hyperparameter(
bidirectional,
hyperparameters.Boolean("bidirectional", default=True),
bool,
)
self.num_layers = utils.get_hyperparameter(
num_layers,
hyperparameters.Choice("num_layers", [1, 2, 3], default=2),
int,
)
self.layer_type = utils.get_hyperparameter(
layer_type,
hyperparameters.Choice(
"layer_type", ["gru", "lstm"], default="lstm"
),
str,
)
def get_config(self):
config = super().get_config()
config.update(
{
"return_sequences": self.return_sequences,
"bidirectional": io_utils.serialize_block_arg(
self.bidirectional
),
"num_layers": io_utils.serialize_block_arg(self.num_layers),
"layer_type": io_utils.serialize_block_arg(self.layer_type),
}
)
return config
@classmethod
def from_config(cls, config):
config["bidirectional"] = io_utils.deserialize_block_arg(
config["bidirectional"]
)
config["num_layers"] = io_utils.deserialize_block_arg(
config["num_layers"]
)
config["layer_type"] = io_utils.deserialize_block_arg(
config["layer_type"]
)
return cls(**config)
def build(self, hp, inputs=None):
inputs = tree.flatten(inputs)
utils.validate_num_inputs(inputs, 1)
input_node = inputs[0]
shape = list(input_node.shape)
if len(shape) != 3:
raise ValueError(
"Expect the input tensor of RNNBlock to have dimensions of "
"[batch_size, time_steps, vec_len], "
"but got {shape}".format(shape=input_node.shape)
)
feature_size = shape[-1]
output_node = input_node
bidirectional = utils.add_to_hp(self.bidirectional, hp)
layer_type = utils.add_to_hp(self.layer_type, hp)
num_layers = utils.add_to_hp(self.num_layers, hp)
rnn_layers = {"gru": layers.GRU, "lstm": layers.LSTM}
in_layer = rnn_layers[layer_type]
for i in range(num_layers):
return_sequences = True
if i == num_layers - 1:
return_sequences = self.return_sequences
if bidirectional:
output_node = layers.Bidirectional( # pragma: no cover
in_layer(feature_size, return_sequences=return_sequences)
)(output_node)
else:
output_node = in_layer(
feature_size, return_sequences=return_sequences
)(output_node)
return output_node
@keras.utils.register_keras_serializable(package="autokeras")
class ConvBlock(block_module.Block):
"""Block for vanilla ConvNets.
# Arguments
kernel_size: Int or keras_tuner.engine.hyperparameters.Choice.
The size of the kernel.
If left unspecified, it will be tuned automatically.
num_blocks: Int or keras_tuner.engine.hyperparameters.Choice.
The number of conv blocks, each of which may contain
convolutional, max pooling, dropout, and activation. If left
unspecified, it will be tuned automatically.
num_layers: Int or hyperparameters.Choice.
The number of convolutional layers in each block. If left
unspecified, it will be tuned automatically.
filters: Int or keras_tuner.engine.hyperparameters.Choice. The number of
filters in the convolutional layers. If left unspecified, it will
be tuned automatically.
max_pooling: Boolean. Whether to use max pooling layer in each block. If
left unspecified, it will be tuned automatically.
separable: Boolean. Whether to use separable conv layers.
If left unspecified, it will be tuned automatically.
dropout: Float or kerastuner.engine.hyperparameters.
Choice range Between 0 and 1.
The dropout rate after convolutional layers.
If left unspecified, it will be tuned automatically.
"""
def __init__(
self,
kernel_size: Optional[Union[int, hyperparameters.Choice]] = None,
num_blocks: Optional[Union[int, hyperparameters.Choice]] = None,
num_layers: Optional[Union[int, hyperparameters.Choice]] = None,
filters: Optional[Union[int, hyperparameters.Choice]] = None,
max_pooling: Optional[bool] = None,
separable: Optional[bool] = None,
dropout: Optional[Union[float, hyperparameters.Choice]] = None,
**kwargs,
):
super().__init__(**kwargs)
self.kernel_size = utils.get_hyperparameter(
kernel_size,
hyperparameters.Choice("kernel_size", [3, 5, 7], default=3),
int,
)
self.num_blocks = utils.get_hyperparameter(
num_blocks,
hyperparameters.Choice("num_blocks", [1, 2, 3], default=2),
int,
)
self.num_layers = utils.get_hyperparameter(
num_layers,
hyperparameters.Choice("num_layers", [1, 2], default=2),
int,
)
self.filters = utils.get_hyperparameter(
filters,
hyperparameters.Choice(
"filters", [16, 32, 64, 128, 256, 512], default=32
),
int,
)
self.max_pooling = max_pooling
self.separable = separable
self.dropout = utils.get_hyperparameter(
dropout,
hyperparameters.Choice("dropout", [0.0, 0.25, 0.5], default=0.0),
float,
)
def get_config(self):
config = super().get_config()
config.update(
{
"kernel_size": io_utils.serialize_block_arg(self.kernel_size),
"num_blocks": io_utils.serialize_block_arg(self.num_blocks),
"num_layers": io_utils.serialize_block_arg(self.num_layers),
"filters": io_utils.serialize_block_arg(self.filters),
"max_pooling": self.max_pooling,
"separable": self.separable,
"dropout": io_utils.serialize_block_arg(self.dropout),
}
)
return config
@classmethod
def from_config(cls, config):
config["kernel_size"] = io_utils.deserialize_block_arg(
config["kernel_size"]
)
config["num_blocks"] = io_utils.deserialize_block_arg(
config["num_blocks"]
)
config["num_layers"] = io_utils.deserialize_block_arg(
config["num_layers"]
)
config["filters"] = io_utils.deserialize_block_arg(config["filters"])
config["dropout"] = io_utils.deserialize_block_arg(config["dropout"])
return cls(**config)
def build(self, hp, inputs=None):
inputs = tree.flatten(inputs)
utils.validate_num_inputs(inputs, 1)
input_node = inputs[0]
output_node = input_node
kernel_size = utils.add_to_hp(self.kernel_size, hp)
separable = self.separable
if separable is None:
separable = hp.Boolean("separable", default=False)
if separable:
conv = layer_utils.get_sep_conv(
input_node.shape
) # pragma: no cover
else:
conv = layer_utils.get_conv(input_node.shape)
max_pooling = self.max_pooling
if max_pooling is None:
max_pooling = hp.Boolean("max_pooling", default=True)
pool = layer_utils.get_max_pooling(input_node.shape)
for i in range(utils.add_to_hp(self.num_blocks, hp)):
for j in range(utils.add_to_hp(self.num_layers, hp)):
output_node = conv(
utils.add_to_hp(
self.filters, hp, "filters_{i}_{j}".format(i=i, j=j)
),
kernel_size,
padding=self._get_padding(kernel_size, output_node),
activation="relu",
)(output_node)
if max_pooling:
output_node = pool(
kernel_size - 1,
padding=self._get_padding(kernel_size - 1, output_node),
)(output_node)
if utils.add_to_hp(self.dropout, hp) > 0:
output_node = layers.Dropout(utils.add_to_hp(self.dropout, hp))(
output_node
)
return output_node
@staticmethod
def _get_padding(kernel_size, output_node):
if all(kernel_size * 2 <= length for length in output_node.shape[1:-1]):
return "valid"
return "same"
@keras.utils.register_keras_serializable(package="autokeras")
class KerasApplicationBlock(block_module.Block):
"""Blocks extending Keras applications."""
def __init__(self, pretrained, models, min_size, **kwargs):
super().__init__(**kwargs)
self.pretrained = pretrained
self.models = models
self.min_size = min_size
def get_config(self):
config = super().get_config()
config.update({"pretrained": self.pretrained})
return config
def build(self, hp, inputs=None):
input_node = tree.flatten(inputs)[0]
pretrained = self.pretrained
if input_node.shape[3] not in [1, 3]:
if self.pretrained:
raise ValueError(
"When pretrained is set to True, expect input to "
"have 1 or 3 channels, bug got "
"{channels}.".format(channels=input_node.shape[3])
)
pretrained = False
if pretrained is None:
pretrained = hp.Boolean(PRETRAINED, default=False)
if pretrained:
with hp.conditional_scope(PRETRAINED, [True]):
trainable = hp.Boolean("trainable", default=False)
elif pretrained:
trainable = hp.Boolean("trainable", default=False)
if len(self.models) > 1:
version = hp.Choice("version", list(self.models.keys()))
else:
version = list(self.models.keys())[0]
min_size = self.min_size
if hp.Boolean("imagenet_size", default=False):
min_size = 224
if input_node.shape[1] < min_size or input_node.shape[2] < min_size:
input_node = layers.Resizing(
max(min_size, input_node.shape[1]),
max(min_size, input_node.shape[2]),
)(input_node)
if input_node.shape[3] == 1:
input_node = layers.Concatenate()([input_node] * 3)
if input_node.shape[3] != 3:
input_node = layers.Conv2D(
filters=3, kernel_size=1, padding="same"
)(input_node)
if pretrained:
model = self.models[version](weights="imagenet", include_top=False)
model.trainable = trainable
else:
model = self.models[version](
weights=None,
include_top=False,
input_shape=input_node.shape[1:],
)
return model(input_node)
@keras.utils.register_keras_serializable(package="autokeras")
class ResNetBlock(KerasApplicationBlock):
"""Block for ResNet.
# Arguments
version: String. 'v1', 'v2'. The type of ResNet to use.
If left unspecified, it will be tuned automatically.
pretrained: Boolean. Whether to use ImageNet pretrained weights.
If left unspecified, it will be tuned automatically.
"""
def __init__(
self,
version: Optional[str] = None,
pretrained: Optional[bool] = None,
**kwargs,
):
if version is None:
models = {**RESNET_V1, **RESNET_V2}
elif version == "v1":
models = RESNET_V1
elif version == "v2":
models = RESNET_V2
else:
raise ValueError(
'Expect version to be "v1", or "v2", but got '
"{version}.".format(version=version)
)
super().__init__(
pretrained=pretrained, models=models, min_size=32, **kwargs
)
self.version = version
def get_config(self):
config = super().get_config()
config.update({"version": self.version})
return config
@keras.utils.register_keras_serializable(package="autokeras")
class XceptionBlock(KerasApplicationBlock):
"""Block for XceptionNet.
An Xception structure, used for specifying your model with specific
datasets.
The original Xception architecture is from
[https://arxiv.org/abs/1610.02357](https://arxiv.org/abs/1610.02357).
The data first goes through the entry flow, then through the middle flow
which is repeated eight times, and finally through the exit flow.
This XceptionBlock returns a similar architecture as Xception except without
the last (optional) fully connected layer(s) and logistic regression.
The size of this architecture could be decided by `HyperParameters`, to get
an architecture with a half, an identical, or a double size of the original
one.
# Arguments
pretrained: Boolean. Whether to use ImageNet pretrained weights.
If left unspecified, it will be tuned automatically.
"""
def __init__(self, pretrained: Optional[bool] = None, **kwargs):
super().__init__(
pretrained=pretrained,
models={"xception": applications.Xception},
min_size=71,
**kwargs,
)
@keras.utils.register_keras_serializable(package="autokeras")
class EfficientNetBlock(KerasApplicationBlock):
"""Block for EfficientNet.
# Arguments
version: String. The value should be one of 'b0', 'b1', ..., 'b7'. The
type of EfficientNet to use. If left unspecified, it will be tuned
automatically.
pretrained: Boolean. Whether to use ImageNet pretrained weights.
If left unspecified, it will be tuned automatically.
"""
def __init__(
self,
version: Optional[str] = None,
pretrained: Optional[bool] = None,
**kwargs,
):
if version is None:
models = EFFICIENT_VERSIONS
elif version in EFFICIENT_VERSIONS.keys():
models = {version: EFFICIENT_VERSIONS[version]}
else:
raise ValueError(
"Expect version to be in {expect}, but got "
"{version}.".format(
expect=list(EFFICIENT_VERSIONS.keys()), version=version
)
)
super().__init__(
pretrained=pretrained,
models=models,
min_size=32,
**kwargs,
)
self.version = version
@keras.utils.register_keras_serializable(package="autokeras")
class Embedding(block_module.Block):
"""Word embedding block for sequences.
The input should be tokenized sequences with the same length, where each
element of a sequence should be the index of the word.
# Arguments
max_features: Int. Size of the vocabulary. Must be set if not using
TextToIntSequence before this block. Defaults to 20001.
embedding_dim: Int or keras_tuner.engine.hyperparameters.Choice.
Output dimension of the Attention block.
If left unspecified, it will be tuned automatically.
dropout: Float or keras_tuner.engine.hyperparameters.Choice.
The dropout rate for the layers.
If left unspecified, it will be tuned automatically.
"""
def __init__(
self,
max_features: int = 20001,
embedding_dim: Optional[Union[int, hyperparameters.Choice]] = None,
dropout: Optional[Union[float, hyperparameters.Choice]] = None,
**kwargs,
):
super().__init__(**kwargs)
self.max_features = max_features
self.embedding_dim = utils.get_hyperparameter(
embedding_dim,
hyperparameters.Choice(
"embedding_dim", [32, 64, 128, 256, 512], default=128
),
int,
)
self.dropout = utils.get_hyperparameter(
dropout,
hyperparameters.Choice("dropout", [0.0, 0.25, 0.5], default=0.25),
float,
)
def get_config(self):
config = super().get_config()
config.update(
{
"max_features": self.max_features,
"embedding_dim": io_utils.serialize_block_arg(
self.embedding_dim
),
"dropout": io_utils.serialize_block_arg(self.dropout),
}
)
return config
@classmethod
def from_config(cls, config):
config["dropout"] = io_utils.deserialize_block_arg(config["dropout"])
config["embedding_dim"] = io_utils.deserialize_block_arg(
config["embedding_dim"]
)
return cls(**config)
def build(self, hp, inputs=None):
input_node = tree.flatten(inputs)[0]
embedding_dim = utils.add_to_hp(self.embedding_dim, hp)
layer = layers.Embedding(
input_dim=self.max_features, output_dim=embedding_dim
)
output_node = layer(input_node)
dropout = utils.add_to_hp(self.dropout, hp)
if dropout > 0:
output_node = layers.Dropout(dropout)(output_node)
return output_node
================================================
FILE: autokeras/blocks/basic_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import keras
import keras_tuner
import pytest
import tree
from autokeras import blocks
from autokeras import test_utils
def test_resnet_build_return_tensor():
block = blocks.ResNetBlock()
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_resnet_v1_return_tensor():
block = blocks.ResNetBlock(version="v1")
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_efficientnet_b0_return_tensor():
block = blocks.EfficientNetBlock(version="b0", pretrained=False)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_resnet_pretrained_build_return_tensor():
block = blocks.ResNetBlock(pretrained=True)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_resnet_pretrained_with_one_channel_input():
block = blocks.ResNetBlock(pretrained=True)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(28, 28, 1), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_resnet_pretrained_error_with_two_channels():
block = blocks.ResNetBlock(pretrained=True)
with pytest.raises(ValueError) as info:
block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(224, 224, 2), dtype="float32"),
)
assert "When pretrained is set to True" in str(info.value)
def test_resnet_deserialize_to_resnet():
serialized_block = blocks.serialize(blocks.ResNetBlock())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.ResNetBlock)
def test_resnet_get_config_has_all_attributes():
block = blocks.ResNetBlock()
config = block.get_config()
assert test_utils.get_func_args(blocks.ResNetBlock.__init__).issubset(
config.keys()
)
def test_resnet_wrong_version_error():
with pytest.raises(ValueError) as info:
blocks.ResNetBlock(version="abc")
assert "Expect version to be" in str(info.value)
def test_efficientnet_wrong_version_error():
with pytest.raises(ValueError) as info:
blocks.EfficientNetBlock(version="abc")
assert "Expect version to be" in str(info.value)
def test_xception_build_return_tensor():
block = blocks.XceptionBlock()
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 2), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_xception_pretrained_build_return_tensor():
block = blocks.XceptionBlock(pretrained=True)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_xception_pretrained_with_one_channel_input():
block = blocks.XceptionBlock(pretrained=True)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(224, 224, 1), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_xception_pretrained_error_with_two_channels():
block = blocks.XceptionBlock(pretrained=True)
with pytest.raises(ValueError) as info:
block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(224, 224, 2), dtype="float32"),
)
assert "When pretrained is set to True" in str(info.value)
def test_xception_deserialize_to_xception():
serialized_block = blocks.serialize(blocks.XceptionBlock())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.XceptionBlock)
def test_xception_get_config_has_all_attributes():
block = blocks.XceptionBlock()
config = block.get_config()
assert test_utils.get_func_args(blocks.XceptionBlock.__init__).issubset(
config.keys()
)
def test_conv_build_return_tensor():
block = blocks.ConvBlock()
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_conv_with_small_image_size_return_tensor():
block = blocks.ConvBlock()
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(10, 10, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_conv_build_with_dropout_return_tensor():
block = blocks.ConvBlock(dropout=0.5)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_conv_deserialize_to_conv():
serialized_block = blocks.serialize(blocks.ConvBlock())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.ConvBlock)
def test_conv_get_config_has_all_attributes():
block = blocks.ConvBlock()
config = block.get_config()
assert test_utils.get_func_args(blocks.ConvBlock.__init__).issubset(
config.keys()
)
def test_rnn_build_return_tensor():
block = blocks.RNNBlock(bidirectional=False)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 10), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_rnn_input_shape_one_dim_error():
block = blocks.RNNBlock()
with pytest.raises(ValueError) as info:
block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32,), dtype="float32"),
)
assert "Expect the input tensor of RNNBlock" in str(info.value)
def test_rnn_deserialize_to_rnn():
serialized_block = blocks.serialize(blocks.RNNBlock())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.RNNBlock)
def test_rnn_get_config_has_all_attributes():
block = blocks.RNNBlock()
config = block.get_config()
assert test_utils.get_func_args(blocks.RNNBlock.__init__).issubset(
config.keys()
)
def test_dense_build_return_tensor():
block = blocks.DenseBlock(
num_units=keras_tuner.engine.hyperparameters.Choice(
"num_units", [10, 20]
)
)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32,), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_dense_build_with_dropout_return_tensor():
block = blocks.DenseBlock(dropout=0.5)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32,), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_dense_build_with_bn_return_tensor():
block = blocks.DenseBlock(use_batchnorm=True)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32,), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_dense_deserialize_to_dense():
serialized_block = blocks.serialize(blocks.DenseBlock())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.DenseBlock)
def test_dense_get_config_has_all_attributes():
block = blocks.DenseBlock()
config = block.get_config()
assert test_utils.get_func_args(blocks.DenseBlock.__init__).issubset(
config.keys()
)
def test_embed_build_return_tensor():
block = blocks.Embedding()
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32,), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_embed_deserialize_to_embed():
serialized_block = blocks.serialize(blocks.Embedding())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.Embedding)
def test_embed_get_config_has_all_attributes():
block = blocks.Embedding()
config = block.get_config()
assert test_utils.get_func_args(blocks.Embedding.__init__).issubset(
config.keys()
)
================================================
FILE: autokeras/blocks/heads.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional
import keras
import tree
from keras import activations
from keras import layers
from keras import losses
from autokeras import adapters
from autokeras import analysers
from autokeras import hyper_preprocessors as hpps_module
from autokeras import preprocessors
from autokeras.blocks import reduction
from autokeras.engine import head as head_module
from autokeras.utils import types
from autokeras.utils import utils
@keras.utils.register_keras_serializable(package="autokeras")
class ClassificationHead(head_module.Head):
"""Classification Dense layers.
Use sigmoid and binary crossentropy for binary classification and
multi-label classification. Use softmax and categorical crossentropy for
multi-class (more than 2) classification. Use Accuracy as metrics by
default.
The targets passing to the head would have to be np.ndarray. It can be raw
labels, one-hot encoded if more than two classes, or binary encoded for
binary classification.
The raw labels will be encoded to one column if two classes were found,
or one-hot encoded if more than two classes were found.
# Arguments
num_classes: Int. Defaults to None. If None, it will be inferred from
the data.
multi_label: Boolean. Defaults to False.
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'.
dropout: Float. The dropout rate for the layers.
If left unspecified, it will be tuned automatically.
"""
def __init__(
self,
num_classes: Optional[int] = None,
multi_label: bool = False,
loss: Optional[types.LossType] = None,
metrics: Optional[types.MetricsType] = None,
dropout: Optional[float] = None,
**kwargs
):
self.num_classes = num_classes
self.multi_label = multi_label
self.dropout = dropout
if metrics is None:
metrics = ["accuracy"]
if loss is None:
loss = self.infer_loss()
super().__init__(loss=loss, metrics=metrics, **kwargs)
# Infered from analyser.
self._encoded = None
self._encoded_for_sigmoid = None
self._encoded_for_softmax = None
self._add_one_dimension = False
self._labels = None
def infer_loss(self):
if not self.num_classes:
return None
if self.num_classes == 2 or self.multi_label:
return losses.BinaryCrossentropy()
return losses.CategoricalCrossentropy()
def get_config(self):
config = super().get_config()
config.update(
{
"num_classes": self.num_classes,
"multi_label": self.multi_label,
"dropout": self.dropout,
}
)
return config
def build(self, hp, inputs=None):
inputs = tree.flatten(inputs)
utils.validate_num_inputs(inputs, 1)
input_node = inputs[0]
output_node = input_node
# Reduce the tensor to a vector.
if len(output_node.shape) > 2:
output_node = reduction.SpatialReduction().build(hp, output_node)
if self.dropout is not None:
dropout = self.dropout
else:
dropout = hp.Choice("dropout", [0.0, 0.25, 0.5], default=0)
if dropout > 0:
output_node = layers.Dropout(dropout)(output_node)
output_node = layers.Dense(self.shape[-1])(output_node)
if isinstance(self.loss, keras.losses.BinaryCrossentropy):
output_node = layers.Activation(
activations.sigmoid, name=self.name
)(output_node)
else:
output_node = layers.Softmax(name=self.name)(output_node)
return output_node
def get_adapter(self):
return adapters.ClassificationAdapter(name=self.name)
def get_analyser(self):
return analysers.ClassificationAnalyser(
name=self.name, multi_label=self.multi_label
)
def config_from_analyser(self, analyser):
super().config_from_analyser(analyser)
self.num_classes = analyser.num_classes
self.loss = self.infer_loss()
self._encoded = analyser.encoded
self._encoded_for_sigmoid = analyser.encoded_for_sigmoid
self._encoded_for_softmax = analyser.encoded_for_softmax
self._add_one_dimension = len(analyser.shape) == 1
self._labels = analyser.labels
def get_hyper_preprocessors(self):
hyper_preprocessors = []
if self._add_one_dimension:
hyper_preprocessors.append(
hpps_module.DefaultHyperPreprocessor(
preprocessors.AddOneDimension()
)
)
if self.dtype in ["uint8", "uint16", "uint32", "uint64"]:
hyper_preprocessors.append(
hpps_module.DefaultHyperPreprocessor(
preprocessors.CastToInt32()
)
)
if not self._encoded and self.dtype != "string":
hyper_preprocessors.append(
hpps_module.DefaultHyperPreprocessor(
preprocessors.CastToString()
)
)
if self._encoded_for_sigmoid:
hyper_preprocessors.append(
hpps_module.DefaultHyperPreprocessor(
preprocessors.SigmoidPostprocessor()
)
)
elif self._encoded_for_softmax:
hyper_preprocessors.append(
hpps_module.DefaultHyperPreprocessor(
preprocessors.SoftmaxPostprocessor()
)
)
elif self.num_classes == 2:
hyper_preprocessors.append(
hpps_module.DefaultHyperPreprocessor(
preprocessors.LabelEncoder(self._labels)
)
)
else:
hyper_preprocessors.append(
hpps_module.DefaultHyperPreprocessor(
preprocessors.OneHotEncoder(self._labels)
)
)
return hyper_preprocessors
@keras.utils.register_keras_serializable(package="autokeras")
class RegressionHead(head_module.Head):
"""Regression Dense layers.
The targets passing to the head would have to be np.ndarray. It can be
single-column or multi-column. The values should all be numerical.
# Arguments
output_dim: Int. The number of output dimensions. Defaults to None.
If None, it will be inferred from the data.
multi_label: Boolean. Defaults to False.
loss: A Keras loss function. Defaults to use `mean_squared_error`.
metrics: A list of Keras metrics. Defaults to use `mean_squared_error`.
dropout: Float. The dropout rate for the layers.
If left unspecified, it will be tuned automatically.
"""
def __init__(
self,
output_dim: Optional[int] = None,
loss: types.LossType = "mean_squared_error",
metrics: Optional[types.MetricsType] = None,
dropout: Optional[float] = None,
**kwargs
):
if metrics is None:
metrics = ["mean_squared_error"]
super().__init__(loss=loss, metrics=metrics, **kwargs)
self.output_dim = output_dim
self.dropout = dropout
def get_config(self):
config = super().get_config()
config.update({"output_dim": self.output_dim, "dropout": self.dropout})
return config
def build(self, hp, inputs=None):
inputs = tree.flatten(inputs)
utils.validate_num_inputs(inputs, 1)
input_node = inputs[0]
output_node = input_node
if self.dropout is not None:
dropout = self.dropout
else:
dropout = hp.Choice("dropout", [0.0, 0.25, 0.5], default=0)
if dropout > 0:
output_node = layers.Dropout(dropout)(output_node)
output_node = reduction.Flatten().build(hp, output_node)
output_node = layers.Dense(self.shape[-1], name=self.name)(output_node)
return output_node
def config_from_analyser(self, analyser):
super().config_from_analyser(analyser)
self._add_one_dimension = len(analyser.shape) == 1
def get_adapter(self):
return adapters.RegressionAdapter(name=self.name)
def get_analyser(self):
return analysers.RegressionAnalyser(
name=self.name, output_dim=self.output_dim
)
def get_hyper_preprocessors(self):
hyper_preprocessors = []
if self._add_one_dimension:
hyper_preprocessors.append( # pragma: no cover
hpps_module.DefaultHyperPreprocessor(
preprocessors.AddOneDimension()
)
)
return hyper_preprocessors
================================================
FILE: autokeras/blocks/heads_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import keras
import keras_tuner
import numpy as np
import tree
from autokeras import hyper_preprocessors
from autokeras import nodes as input_module
from autokeras import preprocessors
from autokeras import test_utils
from autokeras.blocks import heads as head_module
def test_two_classes_infer_binary_crossentropy():
dataset = np.array(["a", "a", "a", "b"])
head = head_module.ClassificationHead(name="a", shape=(1,))
adapter = head.get_adapter()
dataset = adapter.adapt(dataset)
analyser = head.get_analyser()
analyser.update(dataset)
analyser.finalize()
head.config_from_analyser(analyser)
head.build(
keras_tuner.HyperParameters(),
input_module.Input(shape=(32,)).build_node(
keras_tuner.HyperParameters()
),
)
assert head.loss.name == "binary_crossentropy"
def test_three_classes_infer_categorical_crossentropy():
dataset = np.array(["a", "a", "c", "b"])
head = head_module.ClassificationHead(name="a", shape=(1,))
adapter = head.get_adapter()
dataset = adapter.adapt(dataset)
analyser = head.get_analyser()
analyser.update(dataset)
analyser.finalize()
head.config_from_analyser(analyser)
head.build(
keras_tuner.HyperParameters(),
input_module.Input(shape=(32,)).build_node(
keras_tuner.HyperParameters()
),
)
assert head.loss.name == "categorical_crossentropy"
def test_multi_label_loss():
head = head_module.ClassificationHead(
name="a", multi_label=True, num_classes=8, shape=(8,)
)
input_node = keras.Input(shape=(5,))
output_node = head.build(keras_tuner.HyperParameters(), input_node)
model = keras.Model(input_node, output_node)
assert model.layers[-1].activation.__name__ == "sigmoid"
assert head.loss.name == "binary_crossentropy"
def test_clf_head_get_sigmoid_postprocessor():
head = head_module.ClassificationHead(name="a", multi_label=True)
head._encoded = True
head._encoded_for_sigmoid = True
assert isinstance(
head.get_hyper_preprocessors()[0].preprocessor,
preprocessors.SigmoidPostprocessor,
)
def test_clf_head_with_2_clases_get_label_encoder():
head = head_module.ClassificationHead(name="a", num_classes=2)
head._encoded = False
head._labels = ["a", "b"]
assert isinstance(
head.get_hyper_preprocessors()[-1].preprocessor,
preprocessors.LabelEncoder,
)
def test_clf_head_build_with_zero_dropout_return_tensor():
block = head_module.ClassificationHead(dropout=0, shape=(8,))
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(5,), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_clf_head_hpps_with_uint8_contain_cast_to_int32():
dataset = test_utils.generate_one_hot_labels(100, 10)
dataset = dataset.astype("uint8")
head = head_module.ClassificationHead(shape=(8,))
analyser = head.get_analyser()
for data in dataset:
analyser.update(data)
analyser.finalize()
head.config_from_analyser(analyser)
assert any(
[
isinstance(hpp, hyper_preprocessors.DefaultHyperPreprocessor)
and isinstance(hpp.preprocessor, preprocessors.CastToInt32)
for hpp in head.get_hyper_preprocessors()
]
)
def test_reg_head_build_with_zero_dropout_return_tensor():
block = head_module.RegressionHead(dropout=0, shape=(8,))
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(5,), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
================================================
FILE: autokeras/blocks/preprocessing.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Blocks for data preprocessing.
They are built into keras preprocessing layers and will be part of the Keras
model.
"""
from typing import Optional
from typing import Tuple
from typing import Union
import keras
import tree
from keras import layers
from keras_tuner.engine import hyperparameters
from autokeras.engine import block as block_module
from autokeras.utils import io_utils
from autokeras.utils import utils
class Normalization(block_module.Block):
"""Perform feature-wise normalization on data.
Refer to Normalization layer in keras preprocessing layers for more
information.
# Arguments
axis: Integer or tuple of integers, the axis or axes that should be
normalized (typically the features axis). We will normalize each
element in the specified axis. The default is '-1' (the innermost
axis); 0 (the batch axis) is not allowed.
"""
def __init__(self, axis: int = -1, **kwargs):
super().__init__(**kwargs)
self.axis = axis
def build(self, hp, inputs=None):
input_node = tree.flatten(inputs)[0]
return layers.Normalization(axis=self.axis)(input_node)
def get_config(self):
config = super().get_config()
config.update({"axis": self.axis})
return config
@keras.utils.register_keras_serializable(package="autokeras")
class ImageAugmentation(block_module.Block):
"""Collection of various image augmentation methods.
# Arguments
translation_factor: A positive float represented as fraction value, or a
tuple of 2 representing fraction for translation vertically and
horizontally, or a kerastuner.engine.hyperparameters.Choice range
of positive floats. For instance, `translation_factor=0.2` result
in a random translation factor within 20% of the width and height.
If left unspecified, it will be tuned automatically.
vertical_flip: Boolean. Whether to flip the image vertically.
If left unspecified, it will be tuned automatically.
horizontal_flip: Boolean. Whether to flip the image horizontally.
If left unspecified, it will be tuned automatically.
rotation_factor: Float or kerastuner.engine.hyperparameters.Choice range
between [0, 1]. A positive float represented as fraction of 2pi
upper bound for rotating clockwise and counter-clockwise. When
represented as a single float, lower = upper.
If left unspecified, it will be tuned automatically.
zoom_factor: A positive float represented as fraction value, or a tuple
of 2 representing fraction for zooming vertically and horizontally,
or a kerastuner.engine.hyperparameters.Choice range of positive
floats. For instance, `zoom_factor=0.2` result in a random zoom
factor from 80% to 120%. If left unspecified, it will be tuned
automatically.
contrast_factor: A positive float represented as fraction of value, or a
tuple of size 2 representing lower and upper bound, or a
kerastuner.engine.hyperparameters.Choice range of floats to find the
optimal value. When represented as a single float, lower = upper.
The contrast factor will be randomly picked
between [1.0 - lower, 1.0 + upper]. If left unspecified, it will be
tuned automatically.
"""
def __init__(
self,
translation_factor: Optional[
Union[float, Tuple[float, float], hyperparameters.Choice]
] = None,
vertical_flip: Optional[bool] = None,
horizontal_flip: Optional[bool] = None,
rotation_factor: Optional[Union[float, hyperparameters.Choice]] = None,
zoom_factor: Optional[
Union[float, Tuple[float, float], hyperparameters.Choice]
] = None,
contrast_factor: Optional[
Union[float, Tuple[float, float], hyperparameters.Choice]
] = None,
**kwargs
):
super().__init__(**kwargs)
self.translation_factor = utils.get_hyperparameter(
translation_factor,
hyperparameters.Choice("translation_factor", [0.0, 0.1]),
Union[float, Tuple[float, float]],
)
self.horizontal_flip = horizontal_flip
self.vertical_flip = vertical_flip
self.rotation_factor = utils.get_hyperparameter(
rotation_factor,
hyperparameters.Choice("rotation_factor", [0.0, 0.1]),
float,
)
self.zoom_factor = utils.get_hyperparameter(
zoom_factor,
hyperparameters.Choice("zoom_factor", [0.0, 0.1]),
Union[float, Tuple[float, float]],
)
self.contrast_factor = utils.get_hyperparameter(
contrast_factor,
hyperparameters.Choice("contrast_factor", [0.0, 0.1]),
Union[float, Tuple[float, float]],
)
@staticmethod
def _get_fraction_value(value):
if isinstance(value, tuple):
return value
return value, value
def build(self, hp, inputs=None):
input_node = tree.flatten(inputs)[0]
output_node = input_node
# Translate
translation_factor = utils.add_to_hp(self.translation_factor, hp)
if translation_factor not in [0, (0, 0)]:
height_factor, width_factor = self._get_fraction_value(
translation_factor
)
output_node = layers.RandomTranslation(height_factor, width_factor)(
output_node
)
# Flip
horizontal_flip = self.horizontal_flip
if horizontal_flip is None:
horizontal_flip = hp.Boolean("horizontal_flip", default=True)
vertical_flip = self.vertical_flip
if self.vertical_flip is None:
vertical_flip = hp.Boolean("vertical_flip", default=True)
if not horizontal_flip and not vertical_flip:
flip_mode = ""
elif horizontal_flip and vertical_flip:
flip_mode = "horizontal_and_vertical"
elif horizontal_flip and not vertical_flip:
flip_mode = "horizontal"
elif not horizontal_flip and vertical_flip:
flip_mode = "vertical"
if flip_mode != "":
output_node = layers.RandomFlip(mode=flip_mode)(output_node)
# Rotate
rotation_factor = utils.add_to_hp(self.rotation_factor, hp)
if rotation_factor != 0:
output_node = layers.RandomRotation(rotation_factor)(output_node)
# Zoom
zoom_factor = utils.add_to_hp(self.zoom_factor, hp)
if zoom_factor not in [0, (0, 0)]:
height_factor, width_factor = self._get_fraction_value(zoom_factor)
# TODO: Add back RandomZoom when it is ready.
# output_node = layers.RandomZoom(
# height_factor, width_factor)(output_node)
# Contrast
contrast_factor = utils.add_to_hp(self.contrast_factor, hp)
if contrast_factor not in [0, (0, 0)]:
output_node = layers.RandomContrast(contrast_factor)(output_node)
return output_node
def get_config(self):
config = super().get_config()
config.update(
{
"translation_factor": io_utils.serialize_block_arg(
self.translation_factor
),
"horizontal_flip": self.horizontal_flip,
"vertical_flip": self.vertical_flip,
"rotation_factor": io_utils.serialize_block_arg(
self.rotation_factor
),
"zoom_factor": io_utils.serialize_block_arg(self.zoom_factor),
"contrast_factor": io_utils.serialize_block_arg(
self.contrast_factor
),
}
)
return config
@classmethod
def from_config(cls, config):
config["translation_factor"] = io_utils.deserialize_block_arg(
config["translation_factor"]
)
config["rotation_factor"] = io_utils.deserialize_block_arg(
config["rotation_factor"]
)
config["zoom_factor"] = io_utils.deserialize_block_arg(
config["zoom_factor"]
)
config["contrast_factor"] = io_utils.deserialize_block_arg(
config["contrast_factor"]
)
return cls(**config)
================================================
FILE: autokeras/blocks/preprocessing_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import keras
import keras_tuner
import tree
from keras_tuner.engine import hyperparameters
from autokeras import blocks
from autokeras import test_utils
def test_augment_build_return_tensor():
block = blocks.ImageAugmentation(rotation_factor=0.2)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_augment_build_with_translation_factor_range_return_tensor():
block = blocks.ImageAugmentation(translation_factor=(0, 0.1))
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_augment_build_with_no_flip_return_tensor():
block = blocks.ImageAugmentation(vertical_flip=False, horizontal_flip=False)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_augment_build_with_vflip_only_return_tensor():
block = blocks.ImageAugmentation(vertical_flip=True, horizontal_flip=False)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_augment_build_with_zoom_factor_return_tensor():
block = blocks.ImageAugmentation(zoom_factor=0.1)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_augment_build_with_contrast_factor_return_tensor():
block = blocks.ImageAugmentation(contrast_factor=0.1)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_augment_deserialize_to_augment():
serialized_block = blocks.serialize(
blocks.ImageAugmentation(
zoom_factor=0.1,
contrast_factor=hyperparameters.Float("contrast_factor", 0.1, 0.5),
)
)
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.ImageAugmentation)
assert block.zoom_factor == 0.1
assert isinstance(block.contrast_factor, hyperparameters.Float)
def test_augment_get_config_has_all_attributes():
block = blocks.ImageAugmentation()
config = block.get_config()
assert test_utils.get_func_args(blocks.ImageAugmentation.__init__).issubset(
config.keys()
)
================================================
FILE: autokeras/blocks/reduction.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional
import keras
import tree
from keras import layers
from keras import ops
from autokeras.engine import block as block_module
from autokeras.utils import layer_utils
from autokeras.utils import utils
REDUCTION_TYPE = "reduction_type"
FLATTEN = "flatten"
GLOBAL_MAX = "global_max"
GLOBAL_AVG = "global_avg"
def shape_compatible(shape1, shape2):
if len(shape1) != len(shape2):
return False
# TODO: If they can be the same after passing through any layer,
# they are compatible. e.g. (32, 32, 3), (16, 16, 2) are compatible
return shape1[:-1] == shape2[:-1]
@keras.utils.register_keras_serializable(package="autokeras")
class Merge(block_module.Block):
"""Merge block to merge multiple nodes into one.
# Arguments
merge_type: String. 'add' or 'concatenate'. If left unspecified, it will
be tuned automatically.
"""
def __init__(self, merge_type: Optional[str] = None, **kwargs):
super().__init__(**kwargs)
self.merge_type = merge_type
def get_config(self):
config = super().get_config()
config.update({"merge_type": self.merge_type})
return config
def build(self, hp, inputs=None):
inputs = tree.flatten(inputs)
if len(inputs) == 1:
return inputs
if not all(
[
shape_compatible(input_node.shape, inputs[0].shape)
for input_node in inputs
]
):
inputs = [Flatten().build(hp, input_node) for input_node in inputs]
# TODO: Even inputs have different shape[-1], they can still be Add(
# ) after another layer. Check if the inputs are all of the same
# shape
if self._inputs_same_shape(inputs):
merge_type = self.merge_type or hp.Choice(
"merge_type", ["add", "concatenate"], default="add"
)
if merge_type == "add":
return layers.Add()(inputs)
return layers.Concatenate()(inputs)
def _inputs_same_shape(self, inputs):
return all(input_node.shape == inputs[0].shape for input_node in inputs)
@keras.utils.register_keras_serializable(package="autokeras")
class Flatten(block_module.Block):
"""Flatten the input tensor with Keras Flatten layer."""
def build(self, hp, inputs=None):
inputs = tree.flatten(inputs)
utils.validate_num_inputs(inputs, 1)
input_node = inputs[0]
if len(input_node.shape) > 2:
return layers.Flatten()(input_node)
return input_node
@keras.utils.register_keras_serializable(package="autokeras")
class Reduction(block_module.Block):
def __init__(self, reduction_type: Optional[str] = None, **kwargs):
super().__init__(**kwargs)
self.reduction_type = reduction_type
def get_config(self):
config = super().get_config()
config.update({REDUCTION_TYPE: self.reduction_type})
return config
def global_max(self, input_node):
raise NotImplementedError
def global_avg(self, input_node):
raise NotImplementedError
def build(self, hp, inputs=None):
inputs = tree.flatten(inputs)
utils.validate_num_inputs(inputs, 1)
input_node = inputs[0]
output_node = input_node
# No need to reduce.
if len(output_node.shape) <= 2:
return output_node
if self.reduction_type is not None:
return self._build_block(hp, output_node, self.reduction_type)
reduction_type = hp.Choice(
REDUCTION_TYPE, [FLATTEN, GLOBAL_MAX, GLOBAL_AVG]
)
with hp.conditional_scope(REDUCTION_TYPE, [reduction_type]):
return self._build_block(hp, output_node, reduction_type)
def _build_block(self, hp, output_node, reduction_type):
if reduction_type == FLATTEN:
output_node = Flatten().build(hp, output_node)
elif reduction_type == GLOBAL_MAX:
output_node = self.global_max(output_node)
elif reduction_type == GLOBAL_AVG:
output_node = self.global_avg(output_node)
return output_node
@keras.utils.register_keras_serializable(package="autokeras")
class SpatialReduction(Reduction):
"""Reduce the dimension of a spatial tensor, e.g. image, to a vector.
# Arguments
reduction_type: String. 'flatten', 'global_max' or 'global_avg'.
If left unspecified, it will be tuned automatically.
"""
def __init__(self, reduction_type: Optional[str] = None, **kwargs):
super().__init__(reduction_type, **kwargs)
def global_max(self, input_node):
return layer_utils.get_global_max_pooling(input_node.shape)()(
input_node
)
def global_avg(self, input_node):
return layer_utils.get_global_average_pooling(input_node.shape)()(
input_node
)
@keras.utils.register_keras_serializable(package="autokeras")
class TemporalReduction(Reduction):
"""Reduce the dim of a temporal tensor, e.g. output of RNN, to a vector.
# Arguments
reduction_type: String. 'flatten', 'global_max' or 'global_avg'. If left
unspecified, it will be tuned automatically.
"""
def __init__(self, reduction_type: Optional[str] = None, **kwargs):
super().__init__(reduction_type, **kwargs)
def global_max(self, input_node):
return ops.max(input_node, axis=-2)
def global_avg(self, input_node):
return ops.mean(input_node, axis=-2)
================================================
FILE: autokeras/blocks/reduction_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import keras
import keras_tuner
import tree
from autokeras import blocks
from autokeras import test_utils
def test_merge_build_return_tensor():
block = blocks.Merge()
outputs = block.build(
keras_tuner.HyperParameters(),
[
keras.Input(shape=(32,), dtype="float32"),
keras.Input(shape=(4, 8), dtype="float32"),
],
)
assert len(tree.flatten(outputs)) == 1
def test_merge_single_input_return_tensor():
block = blocks.Merge()
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32,), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_merge_inputs_with_same_shape_return_tensor():
block = blocks.Merge()
outputs = block.build(
keras_tuner.HyperParameters(),
[
keras.Input(shape=(32,), dtype="float32"),
keras.Input(shape=(32,), dtype="float32"),
],
)
assert len(tree.flatten(outputs)) == 1
def test_merge_deserialize_to_merge():
serialized_block = blocks.serialize(blocks.Merge())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.Merge)
def test_merge_get_config_has_all_attributes():
block = blocks.Merge()
config = block.get_config()
assert test_utils.get_func_args(blocks.Merge.__init__).issubset(
config.keys()
)
def test_temporal_build_return_tensor():
block = blocks.TemporalReduction()
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 10), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_temporal_global_max_return_tensor():
block = blocks.TemporalReduction(reduction_type="global_max")
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 10), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_temporal_global_avg_return_tensor():
block = blocks.TemporalReduction(reduction_type="global_avg")
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 10), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_reduction_2d_tensor_return_input_node():
block = blocks.TemporalReduction()
input_node = keras.Input(shape=(32,), dtype="float32")
outputs = block.build(
keras_tuner.HyperParameters(),
input_node,
)
assert len(tree.flatten(outputs)) == 1
assert tree.flatten(outputs)[0] is input_node
def test_temporal_deserialize_to_temporal():
serialized_block = blocks.serialize(blocks.TemporalReduction())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.TemporalReduction)
def test_temporal_get_config_has_all_attributes():
block = blocks.TemporalReduction()
config = block.get_config()
assert test_utils.get_func_args(blocks.TemporalReduction.__init__).issubset(
config.keys()
)
def test_spatial_build_return_tensor():
block = blocks.SpatialReduction()
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_spatial_deserialize_to_spatial():
serialized_block = blocks.serialize(blocks.SpatialReduction())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.SpatialReduction)
def test_spatial_get_config_has_all_attributes():
block = blocks.SpatialReduction()
config = block.get_config()
assert test_utils.get_func_args(blocks.SpatialReduction.__init__).issubset(
config.keys()
)
================================================
FILE: autokeras/blocks/wrapper.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional
import keras
import tree
from autokeras.blocks import basic
from autokeras.blocks import preprocessing
from autokeras.blocks import reduction
from autokeras.engine import block as block_module
from autokeras.utils import utils
BLOCK_TYPE = "block_type"
RESNET = "resnet"
XCEPTION = "xception"
VANILLA = "vanilla"
EFFICIENT = "efficient"
NORMALIZE = "normalize"
AUGMENT = "augment"
MAX_TOKENS = "max_tokens"
@keras.utils.register_keras_serializable(package="autokeras")
class ImageBlock(block_module.Block):
"""Block for image data.
The image blocks is a block choosing from ResNetBlock, XceptionBlock,
ConvBlock, which is controlled by a hyperparameter, 'block_type'.
# Arguments
block_type: String. 'resnet', 'xception', 'vanilla'. The type of Block
to use. If unspecified, it will be tuned automatically.
normalize: Boolean. Whether to channel-wise normalize the images.
If unspecified, it will be tuned automatically.
augment: Boolean. Whether to do image augmentation. If unspecified,
it will be tuned automatically.
"""
def __init__(
self,
block_type: Optional[str] = None,
normalize: Optional[bool] = None,
augment: Optional[bool] = None,
**kwargs
):
super().__init__(**kwargs)
self.block_type = block_type
self.normalize = normalize
self.augment = augment
def get_config(self):
config = super().get_config()
config.update(
{
BLOCK_TYPE: self.block_type,
NORMALIZE: self.normalize,
AUGMENT: self.augment,
}
)
return config
def _build_block(self, hp, output_node, block_type):
if block_type == RESNET:
return basic.ResNetBlock().build(hp, output_node)
elif block_type == XCEPTION:
return basic.XceptionBlock().build(hp, output_node)
elif block_type == VANILLA:
return basic.ConvBlock().build(hp, output_node)
elif block_type == EFFICIENT:
return basic.EfficientNetBlock().build(hp, output_node)
def build(self, hp, inputs=None):
input_node = tree.flatten(inputs)[0]
output_node = input_node
if self.normalize is None and hp.Boolean(NORMALIZE):
with hp.conditional_scope(NORMALIZE, [True]):
output_node = preprocessing.Normalization().build(
hp, output_node
)
elif self.normalize:
output_node = preprocessing.Normalization().build(hp, output_node)
if self.augment is None and hp.Boolean(AUGMENT):
with hp.conditional_scope(AUGMENT, [True]):
output_node = preprocessing.ImageAugmentation().build(
hp, output_node
)
elif self.augment:
output_node = preprocessing.ImageAugmentation().build(
hp, output_node
)
if self.block_type is None:
block_type = hp.Choice(
BLOCK_TYPE, [RESNET, XCEPTION, VANILLA, EFFICIENT]
)
with hp.conditional_scope(BLOCK_TYPE, [block_type]):
output_node = self._build_block(hp, output_node, block_type)
else:
output_node = self._build_block(hp, output_node, self.block_type)
return output_node
@keras.utils.register_keras_serializable(package="autokeras")
class TextBlock(block_module.Block):
"""Block for text data.
# Arguments
max_tokens: Int. The maximum size of the vocabulary.
If left unspecified, it will be tuned automatically.
"""
def __init__(self, max_tokens=None, **kwargs):
super().__init__(**kwargs)
self.max_tokens = max_tokens
def build(self, hp, inputs=None):
input_node = tree.flatten(inputs)[0]
output_node = input_node
output_node = self._build_block(hp, output_node)
return output_node
def get_config(self):
config = super().get_config()
config.update({"max_tokens": self.max_tokens})
return config
def _build_block(self, hp, output_node):
# Use Embedding and dense layers for tokenized text
max_tokens = self.max_tokens or hp.Choice(
MAX_TOKENS, [500, 5000, 20000], default=5000
)
output_node = basic.Embedding(
max_features=max_tokens + 1,
).build(hp, output_node)
output_node = basic.ConvBlock().build(hp, output_node)
output_node = reduction.SpatialReduction().build(hp, output_node)
output_node = basic.DenseBlock().build(hp, output_node)
return output_node
@keras.utils.register_keras_serializable(package="autokeras")
class GeneralBlock(block_module.Block):
"""A general neural network block when the input type is unknown.
When the input type is unknown. The GeneralBlock would search in a large
space for a good model.
# Arguments
name: String.
"""
def build(self, hp, inputs=None):
inputs = tree.flatten(inputs)
utils.validate_num_inputs(inputs, 1)
input_node = inputs[0]
output_node = input_node
output_node = reduction.Flatten().build(hp, output_node)
output_node = basic.DenseBlock().build(hp, output_node)
return output_node
@keras.utils.register_keras_serializable(package="autokeras")
class StructuredDataBlock(block_module.Block):
"""Block for structured data.
# Arguments
categorical_encoding: Boolean. Whether to use the CategoricalToNumerical
to encode the categorical features to numerical features. Defaults
to True.
normalize: Boolean. Whether to normalize the features.
If unspecified, it will be tuned automatically.
"""
def __init__(self, normalize: Optional[bool] = None, **kwargs):
super().__init__(**kwargs)
self.normalize = normalize
def get_config(self):
config = super().get_config()
config.update(
{
"normalize": self.normalize,
}
)
return config
def build(self, hp, inputs=None):
input_node = tree.flatten(inputs)[0]
output_node = input_node
if self.normalize is None and hp.Boolean(NORMALIZE):
with hp.conditional_scope(NORMALIZE, [True]):
output_node = preprocessing.Normalization().build(
hp, output_node
)
elif self.normalize:
output_node = preprocessing.Normalization().build(hp, output_node)
output_node = basic.DenseBlock().build(hp, output_node)
return output_node
================================================
FILE: autokeras/blocks/wrapper_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import keras
import keras_tuner
import tree
from autokeras import analysers
from autokeras import blocks
from autokeras import test_utils
def test_image_build_return_tensor():
block = blocks.ImageBlock()
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_general_build_return_tensor():
block = blocks.GeneralBlock()
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_image_block_xception_return_tensor():
block = blocks.ImageBlock(block_type="xception")
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_image_block_normalize_return_tensor():
block = blocks.ImageBlock(normalize=True)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_image_block_augment_return_tensor():
block = blocks.ImageBlock(augment=True)
outputs = block.build(
keras_tuner.HyperParameters(),
keras.Input(shape=(32, 32, 3), dtype="float32"),
)
assert len(tree.flatten(outputs)) == 1
def test_image_deserialize_to_image():
serialized_block = blocks.serialize(blocks.ImageBlock())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.ImageBlock)
def test_image_get_config_has_all_attributes():
block = blocks.ImageBlock()
config = block.get_config()
assert test_utils.get_func_args(blocks.ImageBlock.__init__).issubset(
config.keys()
)
def test_text_build_return_tensor():
block = blocks.TextBlock()
outputs = block.build(
keras_tuner.HyperParameters(), keras.Input(shape=(1,), dtype="string")
)
assert len(tree.flatten(outputs)) == 1
def test_text_deserialize_to_text():
serialized_block = blocks.serialize(blocks.TextBlock())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.TextBlock)
def test_text_get_config_has_all_attributes():
block = blocks.TextBlock()
config = block.get_config()
assert test_utils.get_func_args(blocks.TextBlock.__init__).issubset(
config.keys()
)
def test_structured_build_return_tensor():
block = blocks.StructuredDataBlock()
block.column_names = ["0", "1"]
block.column_types = {"0": analysers.NUMERICAL, "1": analysers.NUMERICAL}
outputs = block.build(
keras_tuner.HyperParameters(), keras.Input(shape=(2,), dtype="string")
)
assert len(tree.flatten(outputs)) == 1
def test_structured_block_normalize_return_tensor():
block = blocks.StructuredDataBlock(normalize=True)
block.column_names = ["0", "1"]
block.column_types = {"0": analysers.NUMERICAL, "1": analysers.NUMERICAL}
outputs = block.build(
keras_tuner.HyperParameters(), keras.Input(shape=(2,), dtype="string")
)
assert len(tree.flatten(outputs)) == 1
def test_structured_block_search_normalize_return_tensor():
block = blocks.StructuredDataBlock(name="a")
block.column_names = ["0", "1"]
block.column_types = {"0": analysers.NUMERICAL, "1": analysers.NUMERICAL}
hp = keras_tuner.HyperParameters()
hp.values["a/" + blocks.wrapper.NORMALIZE] = True
outputs = block.build(hp, keras.Input(shape=(2,), dtype="string"))
assert len(tree.flatten(outputs)) == 1
def test_structured_deserialize_to_structured():
serialized_block = blocks.serialize(blocks.StructuredDataBlock())
block = blocks.deserialize(serialized_block)
assert isinstance(block, blocks.StructuredDataBlock)
def test_structured_get_config_has_all_attributes():
block = blocks.StructuredDataBlock()
config = block.get_config()
assert test_utils.get_func_args(
blocks.StructuredDataBlock.__init__
).issubset(config.keys())
================================================
FILE: autokeras/conftest.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import shutil
import keras
import pytest
@pytest.fixture(autouse=True)
def clear_session():
keras.backend.clear_session()
yield
keras.backend.clear_session()
@pytest.fixture(autouse=True)
def remove_tmp_path(tmp_path):
yield
shutil.rmtree(tmp_path)
@pytest.fixture(autouse=True)
def disable_traceback_filtering():
keras.config.disable_traceback_filtering()
yield
================================================
FILE: autokeras/engine/__init__.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
================================================
FILE: autokeras/engine/adapter.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class Adapter(object):
"""Adpat the input and output format for Keras Model.
Adapter is used by the input nodes and the heads of the hypermodel. It do
some type checking for the data and converts it to compatible format.
"""
def check(self, dataset):
"""Check if the dataset is valid for the input node.
# Arguments
dataset: numpy.ndarray. The dataset to be checked.
# Returns
Boolean. Whether the dataset is in compatible format.
"""
return True
def adapt(self, dataset):
"""Check, convert and batch the dataset.
# Arguments
dataset: Usually numpy.ndarray. The dataset to be converted.
# Returns
numpy.ndarray. The converted dataset.
"""
self.check(dataset)
return dataset
================================================
FILE: autokeras/engine/adapter_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from autokeras.engine import adapter as adapter_module
def test_adapter_check_return_true():
adapter = adapter_module.Adapter()
assert adapter.check(None)
================================================
FILE: autokeras/engine/analyser.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
class Analyser(object):
"""Analyze the dataset for useful information.
Analyser is used by the input nodes and the heads of the hypermodel. It
analyzes the dataset to get useful information, e.g., the shape of the
data, the data type of the dataset. The information will be used by the
input nodes and heads to construct the data pipeline and to build the Keras
Model.
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
# Shape is a list of integers
self.shape = None
self.dtype = None
self.num_samples = 0
self.batch_size = None
def update(self, data):
"""Update the statistics with a batch of data.
# Arguments
data: np.ndarray. The entire dataset.
"""
if self.dtype is None:
if np.issubdtype(data.dtype, np.str_) or np.issubdtype(
data.dtype, np.bytes_
):
self.dtype = "string"
else:
self.dtype = str(data.dtype)
if self.shape is None:
self.shape = list(data.shape)
if self.batch_size is None:
self.batch_size = data.shape[0]
self.num_samples += data.shape[0]
def finalize(self):
"""Process recorded information after all updates."""
raise NotImplementedError
================================================
FILE: autokeras/engine/analyser_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import pytest
from autokeras.engine.analyser import Analyser
def test_analyser_update_unicode_string_dtype():
analyser = Analyser()
data = np.array(["hello", "world"], dtype="U10")
analyser.update(data)
assert analyser.dtype == "string"
assert analyser.shape == [2]
assert analyser.batch_size == 2
assert analyser.num_samples == 2
def test_analyser_update_byte_string_dtype():
analyser = Analyser()
data = np.array([b"hello", b"world"], dtype="S10")
analyser.update(data)
assert analyser.dtype == "string"
assert analyser.shape == [2]
assert analyser.batch_size == 2
assert analyser.num_samples == 2
def test_analyser_update_numeric_dtype():
analyser = Analyser()
data = np.array([1, 2, 3], dtype=np.int32)
analyser.update(data)
assert analyser.dtype == "int32"
assert analyser.shape == [3]
assert analyser.batch_size == 3
assert analyser.num_samples == 3
def test_analyser_update_float_dtype():
analyser = Analyser()
data = np.array([1.0, 2.0, 3.0], dtype=np.float64)
analyser.update(data)
assert analyser.dtype == "float64"
assert analyser.shape == [3]
assert analyser.batch_size == 3
assert analyser.num_samples == 3
def test_analyser_finalize_not_implemented():
analyser = Analyser()
with pytest.raises(NotImplementedError):
analyser.finalize()
================================================
FILE: autokeras/engine/block.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import tree
from autokeras.engine import named_hypermodel
from autokeras.engine import node as node_module
class Block(named_hypermodel.NamedHyperModel):
"""The base class for different Block.
The Block can be connected together to build the search space for an
AutoModel. Notably, many args in the __init__ function are defaults to be a
tunable variable when not specified by the user.
"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.inputs = None
self.outputs = None
self._num_output_node = 1
def _build_wrapper(self, hp, *args, **kwargs):
with hp.name_scope(self.name):
return super()._build_wrapper(hp, *args, **kwargs)
def __call__(self, inputs):
"""Functional API.
# Arguments
inputs: A list of input node(s) or a single input node for the
block.
# Returns
list: A list of output node(s) of the Block.
"""
self.inputs = tree.flatten(inputs)
for input_node in self.inputs:
if not isinstance(input_node, node_module.Node):
raise TypeError(
"Expect the inputs to block {name} to be "
"a Node, but got {type}.".format(
name=self.name, type=type(input_node)
)
)
input_node.add_out_block(self)
self.outputs = []
for _ in range(self._num_output_node):
output_node = node_module.Node()
output_node.add_in_block(self)
self.outputs.append(output_node)
return self.outputs
def build(self, hp, inputs=None):
"""Build the Block into a real Keras Model.
The subclasses should override this function and return the output node.
# Arguments
hp: HyperParameters. The hyperparameters for building the model.
inputs: A list of input node(s).
"""
raise NotImplementedError
================================================
FILE: autokeras/engine/block_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest
from autokeras.engine import block as block_module
def test_block_call_raise_inputs_type_error():
block = block_module.Block()
with pytest.raises(TypeError) as info:
block(None)
assert "Expect the inputs to block" in str(info.value)
================================================
FILE: autokeras/engine/head.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional
import keras
from autokeras.engine import io_hypermodel
from autokeras.utils import types
def serialize_metrics(metrics):
serialized = []
for metric in metrics:
if isinstance(metric, str):
serialized.append([metric])
else:
serialized.append(keras.metrics.serialize(metric))
return serialized
def deserialize_metrics(metrics):
deserialized = []
for metric in metrics:
if isinstance(metric, list):
deserialized.append(metric[0])
else:
deserialized.append(keras.metrics.deserialize(metric))
return deserialized
def serialize_loss(loss):
if isinstance(loss, str):
return [loss]
return keras.losses.serialize(loss)
def deserialize_loss(loss):
if isinstance(loss, list):
return loss[0]
return keras.losses.deserialize(loss)
class Head(io_hypermodel.IOHyperModel):
"""Base class for the heads, e.g. classification, regression.
# Arguments
loss: A Keras loss function. Defaults to None. If None, the loss will be
inferred from the AutoModel.
metrics: A list of Keras metrics. Defaults to None. If None, the metrics
will be inferred from the AutoModel.
"""
def __init__(
self,
loss: Optional[types.LossType] = None,
metrics: Optional[types.MetricsType] = None,
**kwargs
):
super().__init__(**kwargs)
self.loss = loss
if metrics is None:
metrics = []
self.metrics = metrics
# Mark if the head should directly output the input tensor.
def get_config(self):
config = super().get_config()
config.update(
{
"loss": serialize_loss(self.loss),
"metrics": serialize_metrics(self.metrics),
}
)
return config
@classmethod
def from_config(cls, config):
config["loss"] = deserialize_loss(config["loss"])
config["metrics"] = deserialize_metrics(config["metrics"])
return super().from_config(config)
def build(self, hp, inputs=None):
raise NotImplementedError
================================================
FILE: autokeras/engine/head_test.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from autokeras.engine import head as head_module
def test_init_head_none_metrics():
assert isinstance(head_module.Head().metrics, list)
================================================
FILE: autokeras/engine/hyper_preprocessor.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from autokeras.engine import named_hypermodel
class HyperPreprocessor(named_hypermodel.NamedHyperModel):
"""Input data preprocessor search space.
This class defines the search space for a Preprocessor.
"""
def build(self, hp, dataset):
"""Build the input preprocessor.
# Arguments
hp: `HyperParameters` instance. The hyperparameters for building the
a Preprocessor.
dataset: np.ndarray. The dataset to be preprocessed.
# Returns
an instance of Preprocessor.
"""
raise NotImplementedError
================================================
FILE: autokeras/engine/io_hypermodel.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from autokeras.engine import block as block_module
class IOHyperModel(block_module.Block):
"""A mixin class connecting the input nodes and heads with the adapters.
This class is extended by the input nodes and the heads. The AutoModel calls
the functions to get the corresponding adapters and pass the information
back to the input nodes and heads.
"""
def __init__(self, shape=None, **kwargs):
super().__init__(**kwargs)
self.shape = shape
self.data_shape = None
self.dtype = None
self.batch_size = None
self.num_samples = None
def get_analyser(self):
"""Get the corresponding Analyser.
# Returns
An instance of a subclass of autokeras.engine.Analyser.
"""
raise NotImplementedError
def get_adapter(self):
"""Get the corresponding Adapter.
# Returns
An instance of a subclass of autokeras.engine.Adapter.
"""
raise NotImplementedError
def config_from_analyser(self, analyser):
"""Load the learned information on dataset from the Analyser.
# Arguments
adapter: An instance of a subclass of autokeras.engine.Adapter.
"""
self.data_shape = analyser.shape
self.dtype = analyser.dtype
self.batch_size = analyser.batch_size
self.num_samples = analyser.num_samples
def get_hyper_preprocessors(self):
"""Construct a list of HyperPreprocessors based on learned information.
# Returns
A list of HyperPreprocessors for the corresponding data.
"""
raise NotImplementedError
def get_config(self):
config = super().get_config()
config.update({"shape": self.shape})
return config
================================================
FILE: autokeras/engine/named_hypermodel.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import keras
import keras_tuner
from autokeras.engine import serializable
from autokeras.utils import utils
class NamedHyperModel(keras_tuner.HyperModel, serializable.Serializable):
"""
# Arguments
name: String. The name of the HyperModel. If unspecified, it will be set
automatically with the class name.
"""
def __init__(self, name: str = None, **kwargs):
if not name:
prefix = self.__class__.__name__
name = prefix + "_" + str(keras.backend.get_uid(prefix))
name = utils.to_snake_case(name)
super().__init__(name=name, **kwargs)
def get_config(self):
"""Get the configuration of the preprocessor.
# Returns
A dictionary of configurations of the preprocessor.
"""
return {"name": self.name, "tunable": self.tunable}
================================================
FILE: autokeras/engine/node.py
================================================
# Copyright 2020 The AutoKeras Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT
gitextract_87bybot9/
├── .devcontainer/
│ ├── Dockerfile
│ ├── devcontainer.json
│ └── setup.sh
├── .dockerignore
├── .github/
│ ├── CODEOWNERS
│ ├── CODE_OF_CONDUCT.md
│ ├── CONTRIBUTING.md
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.md
│ │ ├── custom.md
│ │ ├── feature_request.md
│ │ └── new-task-template.md
│ ├── PULL_REQUEST_TEMPLATE.md
│ ├── dependabot.yml
│ └── workflows/
│ └── actions.yml
├── .gitignore
├── LICENSE
├── README.md
├── RELEASE.md
├── autokeras/
│ ├── __init__.py
│ ├── adapters/
│ │ ├── __init__.py
│ │ ├── input_adapters.py
│ │ ├── input_adapters_test.py
│ │ ├── output_adapters.py
│ │ └── output_adapters_test.py
│ ├── analysers/
│ │ ├── __init__.py
│ │ ├── input_analysers.py
│ │ ├── input_analysers_test.py
│ │ ├── output_analysers.py
│ │ └── output_analysers_test.py
│ ├── auto_model.py
│ ├── auto_model_test.py
│ ├── blocks/
│ │ ├── __init__.py
│ │ ├── basic.py
│ │ ├── basic_test.py
│ │ ├── heads.py
│ │ ├── heads_test.py
│ │ ├── preprocessing.py
│ │ ├── preprocessing_test.py
│ │ ├── reduction.py
│ │ ├── reduction_test.py
│ │ ├── wrapper.py
│ │ └── wrapper_test.py
│ ├── conftest.py
│ ├── engine/
│ │ ├── __init__.py
│ │ ├── adapter.py
│ │ ├── adapter_test.py
│ │ ├── analyser.py
│ │ ├── analyser_test.py
│ │ ├── block.py
│ │ ├── block_test.py
│ │ ├── head.py
│ │ ├── head_test.py
│ │ ├── hyper_preprocessor.py
│ │ ├── io_hypermodel.py
│ │ ├── named_hypermodel.py
│ │ ├── node.py
│ │ ├── node_test.py
│ │ ├── preprocessor.py
│ │ ├── serializable.py
│ │ ├── tuner.py
│ │ └── tuner_test.py
│ ├── graph.py
│ ├── graph_test.py
│ ├── hyper_preprocessors.py
│ ├── hyper_preprocessors_test.py
│ ├── integration_tests/
│ │ ├── __init__.py
│ │ ├── functional_api_test.py
│ │ ├── io_api_test.py
│ │ └── task_api_test.py
│ ├── keras_layers.py
│ ├── keras_layers_test.py
│ ├── nodes.py
│ ├── nodes_test.py
│ ├── pipeline.py
│ ├── pipeline_test.py
│ ├── preprocessors/
│ │ ├── __init__.py
│ │ ├── common.py
│ │ ├── common_test.py
│ │ ├── encoders.py
│ │ ├── encoders_test.py
│ │ ├── postprocessors.py
│ │ └── postprocessors_test.py
│ ├── tasks/
│ │ ├── __init__.py
│ │ ├── image.py
│ │ ├── image_test.py
│ │ ├── structured_data.py
│ │ ├── structured_data_test.py
│ │ ├── text.py
│ │ └── text_test.py
│ ├── test_utils.py
│ ├── tuners/
│ │ ├── __init__.py
│ │ ├── bayesian_optimization.py
│ │ ├── greedy.py
│ │ ├── greedy_test.py
│ │ ├── hyperband.py
│ │ ├── hyperband_test.py
│ │ ├── random_search.py
│ │ ├── random_search_test.py
│ │ ├── task_specific.py
│ │ └── task_specific_test.py
│ └── utils/
│ ├── __init__.py
│ ├── data_utils.py
│ ├── data_utils_test.py
│ ├── io_utils.py
│ ├── layer_utils.py
│ ├── types.py
│ ├── utils.py
│ └── utils_test.py
├── benchmark/
│ ├── README.md
│ ├── __init__.py
│ ├── datasets/
│ │ ├── titanic_test.csv
│ │ └── titanic_train.csv
│ ├── experiments/
│ │ ├── __init__.py
│ │ ├── experiment.py
│ │ ├── image.py
│ │ ├── structured_data.py
│ │ └── text.py
│ ├── performance.py
│ └── run.py
├── codecov.yml
├── docker/
│ ├── Dockerfile
│ ├── Makefile
│ ├── README.md
│ ├── devel.Dockerfile
│ ├── pre-commit.Dockerfile
│ └── pre_commit.py
├── docs/
│ ├── README.md
│ ├── autogen.py
│ ├── ipynb/
│ │ ├── customized.ipynb
│ │ ├── export.ipynb
│ │ ├── image_classification.ipynb
│ │ ├── image_regression.ipynb
│ │ ├── multi.ipynb
│ │ ├── structured_data_classification.ipynb
│ │ ├── structured_data_regression.ipynb
│ │ ├── text_classification.ipynb
│ │ └── text_regression.ipynb
│ ├── keras_autodoc/
│ │ ├── __init__.py
│ │ ├── autogen.py
│ │ ├── docstring.py
│ │ ├── examples.py
│ │ ├── gathering_members.py
│ │ ├── get_signatures.py
│ │ └── utils.py
│ ├── mkdocs.yml
│ ├── py/
│ │ ├── customized.py
│ │ ├── export.py
│ │ ├── image_classification.py
│ │ ├── image_regression.py
│ │ ├── multi.py
│ │ ├── structured_data_classification.py
│ │ ├── structured_data_regression.py
│ │ ├── text_classification.py
│ │ └── text_regression.py
│ ├── requirements.txt
│ ├── run_py_files.sh
│ ├── templates/
│ │ ├── about.md
│ │ ├── index.md
│ │ ├── install.md
│ │ ├── stylesheets/
│ │ │ └── extra.css
│ │ └── tutorial/
│ │ ├── faq.md
│ │ └── overview.md
│ └── tutobooks.py
├── examples/
│ ├── automodel_with_cnn.py
│ ├── celeb_age.py
│ ├── cifar10.py
│ ├── imdb.py
│ ├── mnist.py
│ ├── new_pop.py
│ └── reuters.py
├── pyproject.toml
├── setup.cfg
└── shell/
├── contributors.py
├── contributors.sh
├── copyright.txt
├── cov.sh
├── coverage.sh
├── docs.sh
├── format.sh
├── generate_json.js
├── lint.sh
├── perf.sh
├── pre-commit.sh
└── pypi.sh
SYMBOL INDEX (769 symbols across 99 files)
FILE: autokeras/adapters/input_adapters.py
class InputAdapter (line 20) | class InputAdapter(adapter_module.Adapter):
method check (line 21) | def check(self, x):
class ImageAdapter (line 35) | class ImageAdapter(adapter_module.Adapter):
method check (line 36) | def check(self, x):
class TextAdapter (line 50) | class TextAdapter(adapter_module.Adapter):
method check (line 51) | def check(self, x):
class StructuredDataAdapter (line 60) | class StructuredDataAdapter(adapter_module.Adapter):
method check (line 61) | def check(self, x):
FILE: autokeras/adapters/input_adapters_test.py
function test_image_input_adapter_transform_to_dataset (line 25) | def test_image_input_adapter_transform_to_dataset():
function test_image_input_unsupported_type (line 31) | def test_image_input_unsupported_type():
function test_image_input_numerical (line 39) | def test_image_input_numerical():
function test_input_type_error (line 47) | def test_input_type_error():
function test_input_numerical (line 55) | def test_input_numerical():
function test_text_adapt_np (line 63) | def test_text_adapt_np():
function test_text_input_type_error (line 72) | def test_text_input_type_error():
function test_structured_data_input_unsupported_type_error (line 80) | def test_structured_data_input_unsupported_type_error():
function test_structured_data_input_transform_to_dataset (line 88) | def test_structured_data_input_transform_to_dataset():
FILE: autokeras/adapters/output_adapters.py
class HeadAdapter (line 20) | class HeadAdapter(adapter_module.Adapter):
method __init__ (line 21) | def __init__(self, name, **kwargs):
method check (line 25) | def check(self, dataset):
class ClassificationAdapter (line 33) | class ClassificationAdapter(HeadAdapter):
class RegressionAdapter (line 37) | class RegressionAdapter(HeadAdapter):
FILE: autokeras/adapters/output_adapters_test.py
function test_unsupported_types_error (line 21) | def test_unsupported_types_error():
function test_reg_head_transform_1d_np (line 30) | def test_reg_head_transform_1d_np():
FILE: autokeras/analysers/input_analysers.py
class InputAnalyser (line 22) | class InputAnalyser(analyser.Analyser):
method finalize (line 23) | def finalize(self):
class ImageAnalyser (line 27) | class ImageAnalyser(InputAnalyser):
method __init__ (line 28) | def __init__(self, **kwargs):
method finalize (line 31) | def finalize(self):
class TextAnalyser (line 42) | class TextAnalyser(InputAnalyser):
method correct_shape (line 43) | def correct_shape(self):
method finalize (line 48) | def finalize(self):
class StructuredDataAnalyser (line 62) | class StructuredDataAnalyser(InputAnalyser):
method __init__ (line 63) | def __init__(self, column_names=None, column_types=None, **kwargs):
method update (line 73) | def update(self, data):
method _update_column (line 90) | def _update_column(self, column_data, i):
method finalize (line 119) | def finalize(self):
method get_input_name (line 123) | def get_input_name(self):
method check (line 126) | def check(self):
method infer_column_types (line 154) | def infer_column_types(self):
FILE: autokeras/analysers/input_analysers_test.py
function test_structured_data_input_less_col_name_error (line 26) | def test_structured_data_input_less_col_name_error():
function test_structured_data_infer_col_types (line 39) | def test_structured_data_infer_col_types():
function test_dont_infer_specified_column_types (line 54) | def test_dont_infer_specified_column_types():
function test_structured_data_input_with_illegal_dim (line 73) | def test_structured_data_input_with_illegal_dim():
function test_image_input_analyser_shape_is_list_of_int (line 88) | def test_image_input_analyser_shape_is_list_of_int():
function test_image_input_with_three_dim (line 99) | def test_image_input_with_three_dim():
function test_image_input_with_illegal_dim (line 109) | def test_image_input_with_illegal_dim():
function test_text_input_with_illegal_dim (line 120) | def test_text_input_with_illegal_dim():
function test_text_analyzer_with_one_dim_doesnt_crash (line 131) | def test_text_analyzer_with_one_dim_doesnt_crash():
function test_text_illegal_type_error (line 139) | def test_text_illegal_type_error():
FILE: autokeras/analysers/output_analysers.py
class TargetAnalyser (line 19) | class TargetAnalyser(analyser.Analyser):
method __init__ (line 20) | def __init__(self, name=None, **kwargs):
class ClassificationAnalyser (line 25) | class ClassificationAnalyser(TargetAnalyser):
method __init__ (line 26) | def __init__(self, num_classes=None, multi_label=False, **kwargs):
method update (line 33) | def update(self, data):
method finalize (line 45) | def finalize(self):
method get_expected_shape (line 81) | def get_expected_shape(self):
method encoded (line 88) | def encoded(self):
method encoded_for_sigmoid (line 92) | def encoded_for_sigmoid(self):
method encoded_for_softmax (line 98) | def encoded_for_softmax(self):
class RegressionAnalyser (line 102) | class RegressionAnalyser(TargetAnalyser):
method __init__ (line 103) | def __init__(self, output_dim=None, **kwargs):
method finalize (line 107) | def finalize(self):
method expected_dim (line 117) | def expected_dim(self):
FILE: autokeras/analysers/output_analysers_test.py
function test_clf_head_one_hot_shape_error (line 22) | def test_clf_head_one_hot_shape_error():
function test_clf_head_more_dim_error (line 33) | def test_clf_head_more_dim_error():
function test_wrong_num_classes_error (line 44) | def test_wrong_num_classes_error():
function test_one_class_error (line 55) | def test_one_class_error():
function test_infer_ten_classes (line 68) | def test_infer_ten_classes():
function test_infer_single_column_two_classes (line 78) | def test_infer_single_column_two_classes():
function test_specify_five_classes (line 88) | def test_specify_five_classes():
function test_specify_two_classes_fit_single_column (line 98) | def test_specify_two_classes_fit_single_column():
function test_multi_label_two_classes_has_two_columns (line 108) | def test_multi_label_two_classes_has_two_columns():
function test_reg_with_specified_output_dim_error (line 120) | def test_reg_with_specified_output_dim_error():
function test_reg_with_specified_output_dim_and_single_column_doesnt_crash (line 131) | def test_reg_with_specified_output_dim_and_single_column_doesnt_crash():
function test_regression_analyser_expected_dim_1d (line 139) | def test_regression_analyser_expected_dim_1d():
function test_regression_analyser_expected_dim_2d (line 145) | def test_regression_analyser_expected_dim_2d():
FILE: autokeras/auto_model.py
function get_tuner_class (line 44) | def get_tuner_class(tuner):
class AutoModel (line 55) | class AutoModel(object):
method __init__ (line 121) | def __init__(
method objective (line 160) | def objective(self):
method max_trials (line 164) | def max_trials(self):
method directory (line 168) | def directory(self):
method project_name (line 172) | def project_name(self):
method _assemble (line 175) | def _assemble(self):
method _build_graph (line 195) | def _build_graph(self):
method fit (line 217) | def fit(
method _adapt (line 317) | def _adapt(self, dataset, hms):
method _check_numpy_arrays (line 327) | def _check_numpy_arrays(self, data, name, in_val=""):
method _check_array_count (line 339) | def _check_array_count(self, actual, expected, name, in_val):
method _check_data_format (line 352) | def _check_data_format(self, x, y, validation=False, predict=False):
method _analyze_data (line 372) | def _analyze_data(self, dataset):
method _build_hyper_pipeline (line 386) | def _build_hyper_pipeline(self):
method _check_and_adapt (line 393) | def _check_and_adapt(self, x, y, validation_data):
method predict (line 409) | def predict(self, x, batch_size=32, verbose=1, **kwargs):
method evaluate (line 439) | def evaluate(self, x, y=None, batch_size=32, verbose=1, **kwargs):
method export_model (line 474) | def export_model(self):
FILE: autokeras/auto_model_test.py
function get_tuner_class (line 25) | def get_tuner_class(*args, **kwargs):
function test_auto_model_objective_is_kt_objective (line 35) | def test_auto_model_objective_is_kt_objective(tmp_path):
function test_auto_model_max_trial_field_as_specified (line 43) | def test_auto_model_max_trial_field_as_specified(tmp_path):
function test_auto_model_directory_field_as_specified (line 51) | def test_auto_model_directory_field_as_specified(tmp_path):
function test_auto_model_project_name_field_as_specified (line 59) | def test_auto_model_project_name_field_as_specified(tmp_path):
function test_evaluate (line 71) | def test_evaluate(tuner_fn, tmp_path):
function get_single_io_auto_model (line 92) | def get_single_io_auto_model(tmp_path):
function test_auto_model_predict (line 99) | def test_auto_model_predict(tuner_fn, tmp_path):
function test_final_fit_concat (line 110) | def test_final_fit_concat(tuner_fn, tmp_path):
function test_final_fit_not_concat (line 122) | def test_final_fit_not_concat(tuner_fn, tmp_path):
function test_overwrite (line 136) | def test_overwrite(tuner_fn, tmp_path):
function test_export_model (line 150) | def test_export_model(tuner_fn, tmp_path):
function get_multi_io_auto_model (line 165) | def get_multi_io_auto_model(tmp_path):
function dataset_error (line 175) | def dataset_error(x, y, validation_data, message, tmp_path):
function test_multi_input_predict (line 183) | def test_multi_input_predict(tuner_fn, tmp_path):
function test_multi_input_predict2 (line 194) | def test_multi_input_predict2(tuner_fn, tmp_path):
function test_invalid_tuner_name_error (line 204) | def test_invalid_tuner_name_error(tmp_path):
function test_no_validation_data_nor_split_error (line 216) | def test_no_validation_data_nor_split_error(tmp_path):
function test_predict_tuple_x_and_tuple_y_predict_doesnt_crash (line 231) | def test_predict_tuple_x_and_tuple_y_predict_doesnt_crash(tuner_fn, tmp_...
function test_fit_with_non_numpy_data_raises_error (line 240) | def test_fit_with_non_numpy_data_raises_error(tmp_path):
function test_fit_with_wrong_array_count_raises_error (line 251) | def test_fit_with_wrong_array_count_raises_error(tmp_path):
FILE: autokeras/blocks/__init__.py
function serialize (line 39) | def serialize(obj):
function deserialize (line 43) | def deserialize(config, custom_objects=None):
FILE: autokeras/blocks/basic.py
class DenseBlock (line 57) | class DenseBlock(block_module.Block):
method __init__ (line 74) | def __init__(
method get_config (line 102) | def get_config(self):
method from_config (line 115) | def from_config(cls, config):
method build (line 125) | def build(self, hp, inputs=None):
class RNNBlock (line 150) | class RNNBlock(block_module.Block):
method __init__ (line 167) | def __init__(
method get_config (line 195) | def get_config(self):
method from_config (line 210) | def from_config(cls, config):
method build (line 222) | def build(self, hp, inputs=None):
class ConvBlock (line 258) | class ConvBlock(block_module.Block):
method __init__ (line 285) | def __init__(
method get_config (line 327) | def get_config(self):
method from_config (line 343) | def from_config(cls, config):
method build (line 357) | def build(self, hp, inputs=None):
method _get_padding (line 403) | def _get_padding(kernel_size, output_node):
class KerasApplicationBlock (line 410) | class KerasApplicationBlock(block_module.Block):
method __init__ (line 413) | def __init__(self, pretrained, models, min_size, **kwargs):
method get_config (line 419) | def get_config(self):
method build (line 424) | def build(self, hp, inputs=None):
class ResNetBlock (line 478) | class ResNetBlock(KerasApplicationBlock):
method __init__ (line 488) | def __init__(
method get_config (line 510) | def get_config(self):
class XceptionBlock (line 517) | class XceptionBlock(KerasApplicationBlock):
method __init__ (line 539) | def __init__(self, pretrained: Optional[bool] = None, **kwargs):
class EfficientNetBlock (line 549) | class EfficientNetBlock(KerasApplicationBlock):
method __init__ (line 560) | def __init__(
class Embedding (line 587) | class Embedding(block_module.Block):
method __init__ (line 604) | def __init__(
method get_config (line 626) | def get_config(self):
method from_config (line 640) | def from_config(cls, config):
method build (line 647) | def build(self, hp, inputs=None):
FILE: autokeras/blocks/basic_test.py
function test_resnet_build_return_tensor (line 24) | def test_resnet_build_return_tensor():
function test_resnet_v1_return_tensor (line 35) | def test_resnet_v1_return_tensor():
function test_efficientnet_b0_return_tensor (line 46) | def test_efficientnet_b0_return_tensor():
function test_resnet_pretrained_build_return_tensor (line 57) | def test_resnet_pretrained_build_return_tensor():
function test_resnet_pretrained_with_one_channel_input (line 68) | def test_resnet_pretrained_with_one_channel_input():
function test_resnet_pretrained_error_with_two_channels (line 79) | def test_resnet_pretrained_error_with_two_channels():
function test_resnet_deserialize_to_resnet (line 91) | def test_resnet_deserialize_to_resnet():
function test_resnet_get_config_has_all_attributes (line 99) | def test_resnet_get_config_has_all_attributes():
function test_resnet_wrong_version_error (line 109) | def test_resnet_wrong_version_error():
function test_efficientnet_wrong_version_error (line 116) | def test_efficientnet_wrong_version_error():
function test_xception_build_return_tensor (line 123) | def test_xception_build_return_tensor():
function test_xception_pretrained_build_return_tensor (line 134) | def test_xception_pretrained_build_return_tensor():
function test_xception_pretrained_with_one_channel_input (line 145) | def test_xception_pretrained_with_one_channel_input():
function test_xception_pretrained_error_with_two_channels (line 156) | def test_xception_pretrained_error_with_two_channels():
function test_xception_deserialize_to_xception (line 168) | def test_xception_deserialize_to_xception():
function test_xception_get_config_has_all_attributes (line 176) | def test_xception_get_config_has_all_attributes():
function test_conv_build_return_tensor (line 186) | def test_conv_build_return_tensor():
function test_conv_with_small_image_size_return_tensor (line 197) | def test_conv_with_small_image_size_return_tensor():
function test_conv_build_with_dropout_return_tensor (line 208) | def test_conv_build_with_dropout_return_tensor():
function test_conv_deserialize_to_conv (line 219) | def test_conv_deserialize_to_conv():
function test_conv_get_config_has_all_attributes (line 227) | def test_conv_get_config_has_all_attributes():
function test_rnn_build_return_tensor (line 237) | def test_rnn_build_return_tensor():
function test_rnn_input_shape_one_dim_error (line 248) | def test_rnn_input_shape_one_dim_error():
function test_rnn_deserialize_to_rnn (line 260) | def test_rnn_deserialize_to_rnn():
function test_rnn_get_config_has_all_attributes (line 268) | def test_rnn_get_config_has_all_attributes():
function test_dense_build_return_tensor (line 278) | def test_dense_build_return_tensor():
function test_dense_build_with_dropout_return_tensor (line 293) | def test_dense_build_with_dropout_return_tensor():
function test_dense_build_with_bn_return_tensor (line 304) | def test_dense_build_with_bn_return_tensor():
function test_dense_deserialize_to_dense (line 315) | def test_dense_deserialize_to_dense():
function test_dense_get_config_has_all_attributes (line 323) | def test_dense_get_config_has_all_attributes():
function test_embed_build_return_tensor (line 333) | def test_embed_build_return_tensor():
function test_embed_deserialize_to_embed (line 344) | def test_embed_deserialize_to_embed():
function test_embed_get_config_has_all_attributes (line 352) | def test_embed_get_config_has_all_attributes():
FILE: autokeras/blocks/heads.py
class ClassificationHead (line 34) | class ClassificationHead(head_module.Head):
method __init__ (line 60) | def __init__(
method infer_loss (line 84) | def infer_loss(self):
method get_config (line 91) | def get_config(self):
method build (line 102) | def build(self, hp, inputs=None):
method get_adapter (line 128) | def get_adapter(self):
method get_analyser (line 131) | def get_analyser(self):
method config_from_analyser (line 136) | def config_from_analyser(self, analyser):
method get_hyper_preprocessors (line 146) | def get_hyper_preprocessors(self):
class RegressionHead (line 198) | class RegressionHead(head_module.Head):
method __init__ (line 214) | def __init__(
method get_config (line 228) | def get_config(self):
method build (line 233) | def build(self, hp, inputs=None):
method config_from_analyser (line 250) | def config_from_analyser(self, analyser):
method get_adapter (line 254) | def get_adapter(self):
method get_analyser (line 257) | def get_analyser(self):
method get_hyper_preprocessors (line 262) | def get_hyper_preprocessors(self):
FILE: autokeras/blocks/heads_test.py
function test_two_classes_infer_binary_crossentropy (line 27) | def test_two_classes_infer_binary_crossentropy():
function test_three_classes_infer_categorical_crossentropy (line 45) | def test_three_classes_infer_categorical_crossentropy():
function test_multi_label_loss (line 63) | def test_multi_label_loss():
function test_clf_head_get_sigmoid_postprocessor (line 74) | def test_clf_head_get_sigmoid_postprocessor():
function test_clf_head_with_2_clases_get_label_encoder (line 84) | def test_clf_head_with_2_clases_get_label_encoder():
function test_clf_head_build_with_zero_dropout_return_tensor (line 94) | def test_clf_head_build_with_zero_dropout_return_tensor():
function test_clf_head_hpps_with_uint8_contain_cast_to_int32 (line 105) | def test_clf_head_hpps_with_uint8_contain_cast_to_int32():
function test_reg_head_build_with_zero_dropout_return_tensor (line 124) | def test_reg_head_build_with_zero_dropout_return_tensor():
FILE: autokeras/blocks/preprocessing.py
class Normalization (line 35) | class Normalization(block_module.Block):
method __init__ (line 48) | def __init__(self, axis: int = -1, **kwargs):
method build (line 52) | def build(self, hp, inputs=None):
method get_config (line 56) | def get_config(self):
class ImageAugmentation (line 63) | class ImageAugmentation(block_module.Block):
method __init__ (line 97) | def __init__(
method _get_fraction_value (line 138) | def _get_fraction_value(value):
method build (line 143) | def build(self, hp, inputs=None):
method get_config (line 195) | def get_config(self):
method from_config (line 216) | def from_config(cls, config):
FILE: autokeras/blocks/preprocessing_test.py
function test_augment_build_return_tensor (line 24) | def test_augment_build_return_tensor():
function test_augment_build_with_translation_factor_range_return_tensor (line 35) | def test_augment_build_with_translation_factor_range_return_tensor():
function test_augment_build_with_no_flip_return_tensor (line 46) | def test_augment_build_with_no_flip_return_tensor():
function test_augment_build_with_vflip_only_return_tensor (line 57) | def test_augment_build_with_vflip_only_return_tensor():
function test_augment_build_with_zoom_factor_return_tensor (line 68) | def test_augment_build_with_zoom_factor_return_tensor():
function test_augment_build_with_contrast_factor_return_tensor (line 79) | def test_augment_build_with_contrast_factor_return_tensor():
function test_augment_deserialize_to_augment (line 90) | def test_augment_deserialize_to_augment():
function test_augment_get_config_has_all_attributes (line 105) | def test_augment_get_config_has_all_attributes():
FILE: autokeras/blocks/reduction.py
function shape_compatible (line 32) | def shape_compatible(shape1, shape2):
class Merge (line 41) | class Merge(block_module.Block):
method __init__ (line 49) | def __init__(self, merge_type: Optional[str] = None, **kwargs):
method get_config (line 53) | def get_config(self):
method build (line 58) | def build(self, hp, inputs=None):
method _inputs_same_shape (line 83) | def _inputs_same_shape(self, inputs):
class Flatten (line 88) | class Flatten(block_module.Block):
method build (line 91) | def build(self, hp, inputs=None):
class Reduction (line 101) | class Reduction(block_module.Block):
method __init__ (line 102) | def __init__(self, reduction_type: Optional[str] = None, **kwargs):
method get_config (line 106) | def get_config(self):
method global_max (line 111) | def global_max(self, input_node):
method global_avg (line 114) | def global_avg(self, input_node):
method build (line 117) | def build(self, hp, inputs=None):
method _build_block (line 136) | def _build_block(self, hp, output_node, reduction_type):
class SpatialReduction (line 147) | class SpatialReduction(Reduction):
method __init__ (line 155) | def __init__(self, reduction_type: Optional[str] = None, **kwargs):
method global_max (line 158) | def global_max(self, input_node):
method global_avg (line 163) | def global_avg(self, input_node):
class TemporalReduction (line 170) | class TemporalReduction(Reduction):
method __init__ (line 178) | def __init__(self, reduction_type: Optional[str] = None, **kwargs):
method global_max (line 181) | def global_max(self, input_node):
method global_avg (line 184) | def global_avg(self, input_node):
FILE: autokeras/blocks/reduction_test.py
function test_merge_build_return_tensor (line 23) | def test_merge_build_return_tensor():
function test_merge_single_input_return_tensor (line 37) | def test_merge_single_input_return_tensor():
function test_merge_inputs_with_same_shape_return_tensor (line 48) | def test_merge_inputs_with_same_shape_return_tensor():
function test_merge_deserialize_to_merge (line 62) | def test_merge_deserialize_to_merge():
function test_merge_get_config_has_all_attributes (line 70) | def test_merge_get_config_has_all_attributes():
function test_temporal_build_return_tensor (line 80) | def test_temporal_build_return_tensor():
function test_temporal_global_max_return_tensor (line 91) | def test_temporal_global_max_return_tensor():
function test_temporal_global_avg_return_tensor (line 102) | def test_temporal_global_avg_return_tensor():
function test_reduction_2d_tensor_return_input_node (line 113) | def test_reduction_2d_tensor_return_input_node():
function test_temporal_deserialize_to_temporal (line 126) | def test_temporal_deserialize_to_temporal():
function test_temporal_get_config_has_all_attributes (line 134) | def test_temporal_get_config_has_all_attributes():
function test_spatial_build_return_tensor (line 144) | def test_spatial_build_return_tensor():
function test_spatial_deserialize_to_spatial (line 155) | def test_spatial_deserialize_to_spatial():
function test_spatial_get_config_has_all_attributes (line 163) | def test_spatial_get_config_has_all_attributes():
FILE: autokeras/blocks/wrapper.py
class ImageBlock (line 37) | class ImageBlock(block_module.Block):
method __init__ (line 52) | def __init__(
method get_config (line 64) | def get_config(self):
method _build_block (line 75) | def _build_block(self, hp, output_node, block_type):
method build (line 85) | def build(self, hp, inputs=None):
class TextBlock (line 120) | class TextBlock(block_module.Block):
method __init__ (line 128) | def __init__(self, max_tokens=None, **kwargs):
method build (line 132) | def build(self, hp, inputs=None):
method get_config (line 138) | def get_config(self):
method _build_block (line 143) | def _build_block(self, hp, output_node):
class GeneralBlock (line 158) | class GeneralBlock(block_module.Block):
method build (line 168) | def build(self, hp, inputs=None):
class StructuredDataBlock (line 180) | class StructuredDataBlock(block_module.Block):
method __init__ (line 191) | def __init__(self, normalize: Optional[bool] = None, **kwargs):
method get_config (line 195) | def get_config(self):
method build (line 204) | def build(self, hp, inputs=None):
FILE: autokeras/blocks/wrapper_test.py
function test_image_build_return_tensor (line 24) | def test_image_build_return_tensor():
function test_general_build_return_tensor (line 35) | def test_general_build_return_tensor():
function test_image_block_xception_return_tensor (line 46) | def test_image_block_xception_return_tensor():
function test_image_block_normalize_return_tensor (line 57) | def test_image_block_normalize_return_tensor():
function test_image_block_augment_return_tensor (line 68) | def test_image_block_augment_return_tensor():
function test_image_deserialize_to_image (line 79) | def test_image_deserialize_to_image():
function test_image_get_config_has_all_attributes (line 87) | def test_image_get_config_has_all_attributes():
function test_text_build_return_tensor (line 97) | def test_text_build_return_tensor():
function test_text_deserialize_to_text (line 107) | def test_text_deserialize_to_text():
function test_text_get_config_has_all_attributes (line 115) | def test_text_get_config_has_all_attributes():
function test_structured_build_return_tensor (line 125) | def test_structured_build_return_tensor():
function test_structured_block_normalize_return_tensor (line 137) | def test_structured_block_normalize_return_tensor():
function test_structured_block_search_normalize_return_tensor (line 149) | def test_structured_block_search_normalize_return_tensor():
function test_structured_deserialize_to_structured (line 161) | def test_structured_deserialize_to_structured():
function test_structured_get_config_has_all_attributes (line 169) | def test_structured_get_config_has_all_attributes():
FILE: autokeras/conftest.py
function clear_session (line 22) | def clear_session():
function remove_tmp_path (line 29) | def remove_tmp_path(tmp_path):
function disable_traceback_filtering (line 35) | def disable_traceback_filtering():
FILE: autokeras/engine/adapter.py
class Adapter (line 16) | class Adapter(object):
method check (line 23) | def check(self, dataset):
method adapt (line 34) | def adapt(self, dataset):
FILE: autokeras/engine/adapter_test.py
function test_adapter_check_return_true (line 18) | def test_adapter_check_return_true():
FILE: autokeras/engine/analyser.py
class Analyser (line 19) | class Analyser(object):
method __init__ (line 29) | def __init__(self, **kwargs):
method update (line 37) | def update(self, data):
method finalize (line 56) | def finalize(self):
FILE: autokeras/engine/analyser_test.py
function test_analyser_update_unicode_string_dtype (line 21) | def test_analyser_update_unicode_string_dtype():
function test_analyser_update_byte_string_dtype (line 33) | def test_analyser_update_byte_string_dtype():
function test_analyser_update_numeric_dtype (line 45) | def test_analyser_update_numeric_dtype():
function test_analyser_update_float_dtype (line 57) | def test_analyser_update_float_dtype():
function test_analyser_finalize_not_implemented (line 69) | def test_analyser_finalize_not_implemented():
FILE: autokeras/engine/block.py
class Block (line 21) | class Block(named_hypermodel.NamedHyperModel):
method __init__ (line 30) | def __init__(self, **kwargs):
method _build_wrapper (line 36) | def _build_wrapper(self, hp, *args, **kwargs):
method __call__ (line 40) | def __call__(self, inputs):
method build (line 67) | def build(self, hp, inputs=None):
FILE: autokeras/engine/block_test.py
function test_block_call_raise_inputs_type_error (line 20) | def test_block_call_raise_inputs_type_error():
FILE: autokeras/engine/head.py
function serialize_metrics (line 22) | def serialize_metrics(metrics):
function deserialize_metrics (line 32) | def deserialize_metrics(metrics):
function serialize_loss (line 42) | def serialize_loss(loss):
function deserialize_loss (line 48) | def deserialize_loss(loss):
class Head (line 54) | class Head(io_hypermodel.IOHyperModel):
method __init__ (line 64) | def __init__(
method get_config (line 77) | def get_config(self):
method from_config (line 88) | def from_config(cls, config):
method build (line 93) | def build(self, hp, inputs=None):
FILE: autokeras/engine/head_test.py
function test_init_head_none_metrics (line 18) | def test_init_head_none_metrics():
FILE: autokeras/engine/hyper_preprocessor.py
class HyperPreprocessor (line 18) | class HyperPreprocessor(named_hypermodel.NamedHyperModel):
method build (line 24) | def build(self, hp, dataset):
FILE: autokeras/engine/io_hypermodel.py
class IOHyperModel (line 18) | class IOHyperModel(block_module.Block):
method __init__ (line 26) | def __init__(self, shape=None, **kwargs):
method get_analyser (line 34) | def get_analyser(self):
method get_adapter (line 42) | def get_adapter(self):
method config_from_analyser (line 50) | def config_from_analyser(self, analyser):
method get_hyper_preprocessors (line 61) | def get_hyper_preprocessors(self):
method get_config (line 69) | def get_config(self):
FILE: autokeras/engine/named_hypermodel.py
class NamedHyperModel (line 22) | class NamedHyperModel(keras_tuner.HyperModel, serializable.Serializable):
method __init__ (line 30) | def __init__(self, name: str = None, **kwargs):
method get_config (line 37) | def get_config(self):
FILE: autokeras/engine/node.py
class Node (line 16) | class Node(object):
method __init__ (line 19) | def __init__(self, **kwargs):
method add_in_block (line 24) | def add_in_block(self, hypermodel):
method add_out_block (line 27) | def add_out_block(self, hypermodel):
FILE: autokeras/engine/preprocessor.py
class Preprocessor (line 18) | class Preprocessor(serializable.Serializable):
method fit (line 24) | def fit(self, dataset):
method transform (line 35) | def transform(self, dataset):
method get_config (line 46) | def get_config(self):
class TargetPreprocessor (line 50) | class TargetPreprocessor(Preprocessor):
method postprocess (line 53) | def postprocess(self, dataset):
FILE: autokeras/engine/serializable.py
class Serializable (line 16) | class Serializable(object):
method get_config (line 19) | def get_config(self):
method from_config (line 28) | def from_config(cls, config):
FILE: autokeras/engine/tuner.py
class AutoTuner (line 31) | class AutoTuner(keras_tuner.engine.tuner.Tuner):
method __init__ (line 52) | def __init__(self, oracle, hypermodel, **kwargs):
method _populate_initial_space (line 60) | def _populate_initial_space(self):
method get_best_model (line 65) | def get_best_model(self):
method get_best_pipeline (line 68) | def get_best_pipeline(self):
method _pipeline_path (line 71) | def _pipeline_path(self, trial_id):
method _prepare_model_build (line 74) | def _prepare_model_build(self, hp, **kwargs):
method _build_and_fit_model (line 93) | def _build_and_fit_model(self, trial, *args, **kwargs):
method adapt (line 112) | def adapt(model, dataset):
method search (line 151) | def search(
method get_state (line 261) | def get_state(self):
method set_state (line 266) | def set_state(self, state):
method _remove_early_stopping (line 271) | def _remove_early_stopping(callbacks):
method _get_best_trial_epochs (line 278) | def _get_best_trial_epochs(self):
method _build_best_model (line 283) | def _build_best_model(self):
method final_fit (line 288) | def final_fit(self, **kwargs):
method best_model_path (line 303) | def best_model_path(self):
method best_pipeline_path (line 307) | def best_pipeline_path(self):
method objective (line 311) | def objective(self):
method max_trials (line 315) | def max_trials(self):
FILE: autokeras/engine/tuner_test.py
function called_with_early_stopping (line 26) | def called_with_early_stopping(func):
function test_final_fit_with_specified_epochs (line 39) | def test_final_fit_with_specified_epochs(_, final_fit, super_search, tmp...
function test_tuner_call_super_with_early_stopping (line 53) | def test_tuner_call_super_with_early_stopping(
function test_no_final_fit_without_epochs_and_fov (line 75) | def test_no_final_fit_without_epochs_and_fov(
function test_final_fit_best_epochs_if_epoch_unspecified (line 93) | def test_final_fit_best_epochs_if_epoch_unspecified(
function test_super_with_1k_epochs_if_epoch_unspecified (line 118) | def test_super_with_1k_epochs_if_epoch_unspecified(
function test_tuner_not_call_super_search_with_overwrite (line 142) | def test_tuner_not_call_super_search_with_overwrite(
function test_tuner_does_not_crash_with_distribution_strategy (line 162) | def test_tuner_does_not_crash_with_distribution_strategy(tmp_path):
function test_adapt_with_model_with_preprocessing_layer_only (line 170) | def test_adapt_with_model_with_preprocessing_layer_only():
function test_build_block_in_blocks_with_same_name (line 180) | def test_build_block_in_blocks_with_same_name(tmp_path):
FILE: autokeras/graph.py
function feature_encoding_input (line 26) | def feature_encoding_input(block):
function load_graph (line 41) | def load_graph(filepath, custom_objects=None):
class Graph (line 48) | class Graph(keras_tuner.HyperModel, serializable.Serializable):
method __init__ (line 56) | def __init__(self, inputs=None, outputs=None, **kwargs):
method _build_network (line 71) | def _build_network(self):
method _search_network (line 143) | def _search_network(
method _add_block (line 169) | def _add_block(self, block):
method _add_node (line 175) | def _add_node(self, input_node):
method get_config (line 179) | def get_config(self):
method from_config (line 205) | def from_config(cls, config):
method compile (line 229) | def compile(self):
method build (line 235) | def build(self, hp):
method _get_metrics (line 265) | def _get_metrics(self):
method _get_loss (line 273) | def _get_loss(self):
method _compile_keras_model (line 281) | def _compile_keras_model(self, hp, model):
method save (line 326) | def save(self, filepath):
method set_io_shapes (line 329) | def set_io_shapes(self, shapes):
method set_fit_args (line 335) | def set_fit_args(self, validation_split, epochs=None):
method batch_size (line 345) | def batch_size(self):
FILE: autokeras/graph_test.py
function test_input_output_disconnect (line 24) | def test_input_output_disconnect():
function test_hyper_graph_cycle (line 39) | def test_hyper_graph_cycle():
function test_input_missing (line 56) | def test_input_missing():
function test_graph_basics (line 69) | def test_graph_basics():
function test_adamw_optimizer (line 82) | def test_adamw_optimizer():
function test_graph_save_load (line 101) | def test_graph_save_load(tmp_path):
function test_merge (line 124) | def test_merge():
function test_save_custom_metrics_loss (line 139) | def test_save_custom_metrics_loss(tmp_path):
function test_graph_can_init_with_one_missing_output (line 165) | def test_graph_can_init_with_one_missing_output():
function test_set_fit_args_with_none_validation_split (line 174) | def test_set_fit_args_with_none_validation_split():
FILE: autokeras/hyper_preprocessors.py
function serialize (line 21) | def serialize(encoder):
function deserialize (line 25) | def deserialize(config, custom_objects=None):
class DefaultHyperPreprocessor (line 34) | class DefaultHyperPreprocessor(hyper_preprocessor.HyperPreprocessor):
method __init__ (line 44) | def __init__(self, preprocessor, *args, **kwargs):
method build (line 48) | def build(self, hp, dataset):
method get_config (line 51) | def get_config(self):
method from_config (line 59) | def from_config(cls, config):
FILE: autokeras/hyper_preprocessors_test.py
function test_serialize_and_deserialize_default_hpps (line 21) | def test_serialize_and_deserialize_default_hpps():
function test_serialize_and_deserialize_default_hpps_categorical (line 34) | def test_serialize_and_deserialize_default_hpps_categorical():
FILE: autokeras/integration_tests/functional_api_test.py
function test_text_and_structured_data (line 22) | def test_text_and_structured_data(tmp_path):
function test_image_blocks (line 67) | def test_image_blocks(tmp_path):
FILE: autokeras/integration_tests/io_api_test.py
function test_io_api (line 21) | def test_io_api(tmp_path):
FILE: autokeras/integration_tests/task_api_test.py
function test_image_classifier (line 26) | def test_image_classifier(tmp_path):
function test_image_regressor (line 47) | def test_image_regressor(tmp_path):
function test_text_classifier (line 62) | def test_text_classifier(tmp_path):
function test_text_regressor (line 86) | def test_text_regressor(tmp_path):
function test_structured_data_regressor (line 106) | def test_structured_data_regressor(tmp_path):
function test_structured_data_classifier (line 129) | def test_structured_data_classifier(tmp_path):
FILE: autokeras/keras_layers.py
class PreprocessingLayer (line 27) | class PreprocessingLayer(layers.Layer):
class CastToFloat32 (line 32) | class CastToFloat32(PreprocessingLayer):
method get_config (line 33) | def get_config(self):
method call (line 36) | def call(self, inputs):
method adapt (line 40) | def adapt(self, data):
class ExpandLastDim (line 45) | class ExpandLastDim(PreprocessingLayer):
method get_config (line 46) | def get_config(self):
method call (line 49) | def call(self, inputs):
method adapt (line 52) | def adapt(self, data):
FILE: autokeras/keras_layers_test.py
function get_text_data (line 21) | def get_text_data():
function test_cast_to_float32_return_float32_tensor (line 44) | def test_cast_to_float32_return_float32_tensor(tmp_path):
function test_expand_last_dim_return_tensor_with_more_dims (line 52) | def test_expand_last_dim_return_tensor_with_more_dims(tmp_path):
FILE: autokeras/nodes.py
function serialize (line 33) | def serialize(obj):
function deserialize (line 37) | def deserialize(config, custom_objects=None):
class Input (line 46) | class Input(node_module.Node, io_hypermodel.IOHyperModel):
method __init__ (line 56) | def __init__(self, name: Optional[str] = None, **kwargs):
method build_node (line 59) | def build_node(self, hp):
method build (line 62) | def build(self, hp, inputs=None):
method get_adapter (line 66) | def get_adapter(self):
method get_analyser (line 69) | def get_analyser(self):
method get_block (line 72) | def get_block(self):
method get_hyper_preprocessors (line 75) | def get_hyper_preprocessors(self):
class ImageInput (line 79) | class ImageInput(Input):
method __init__ (line 91) | def __init__(self, name: Optional[str] = None, **kwargs):
method build (line 94) | def build(self, hp, inputs=None):
method get_adapter (line 101) | def get_adapter(self):
method get_analyser (line 104) | def get_analyser(self):
method get_block (line 107) | def get_block(self):
class TextInput (line 111) | class TextInput(Input):
method __init__ (line 123) | def __init__(self, name: Optional[str] = None, **kwargs):
method build_node (line 126) | def build_node(self, hp):
method build (line 129) | def build(self, hp, inputs=None):
method get_adapter (line 137) | def get_adapter(self):
method get_analyser (line 140) | def get_analyser(self):
method get_block (line 143) | def get_block(self):
method get_hyper_preprocessors (line 146) | def get_hyper_preprocessors(self):
class StructuredDataInput (line 157) | class StructuredDataInput(Input):
method __init__ (line 177) | def __init__(
method get_config (line 188) | def get_config(self):
method get_adapter (line 198) | def get_adapter(self):
method get_analyser (line 201) | def get_analyser(self):
method get_block (line 206) | def get_block(self):
method config_from_analyser (line 209) | def config_from_analyser(self, analyser):
method build (line 215) | def build(self, hp, inputs=None):
method get_hyper_preprocessors (line 218) | def get_hyper_preprocessors(self):
FILE: autokeras/nodes_test.py
function test_input_get_block_return_general_block (line 19) | def test_input_get_block_return_general_block():
FILE: autokeras/pipeline.py
class HyperPipeline (line 24) | class HyperPipeline(hpps_module.HyperPreprocessor):
method __init__ (line 32) | def __init__(self, inputs, outputs, **kwargs):
method _build_preprocessors (line 38) | def _build_preprocessors(hp, hpps_lists, dataset):
method build (line 52) | def build(self, hp, dataset):
function load_pipeline (line 69) | def load_pipeline(filepath, custom_objects=None):
class Pipeline (line 77) | class Pipeline(pps_module.Preprocessor):
method __init__ (line 87) | def __init__(self, inputs, outputs, **kwargs):
method fit (line 92) | def fit(self, dataset):
method transform (line 107) | def transform(self, dataset):
method transform_x (line 121) | def transform_x(self, dataset):
method transform_y (line 132) | def transform_y(self, dataset):
method _transform_data (line 143) | def _transform_data(self, dataset, pps_lists):
method save (line 154) | def save(self, filepath):
method get_config (line 157) | def get_config(self):
method from_config (line 176) | def from_config(cls, config):
method postprocess (line 194) | def postprocess(self, y):
FILE: autokeras/pipeline_test.py
function test_pipeline_postprocess_one_hot_to_labels (line 21) | def test_pipeline_postprocess_one_hot_to_labels():
function test_pipeline_postprocess_multiple_one_hot_to_labels (line 30) | def test_pipeline_postprocess_multiple_one_hot_to_labels():
FILE: autokeras/preprocessors/__init__.py
function serialize (line 28) | def serialize(preprocessor):
function deserialize (line 32) | def deserialize(config, custom_objects=None):
FILE: autokeras/preprocessors/common.py
class AddOneDimension (line 24) | class AddOneDimension(preprocessor.Preprocessor):
method transform (line 27) | def transform(self, dataset):
class CastToInt32 (line 32) | class CastToInt32(preprocessor.Preprocessor):
method transform (line 35) | def transform(self, dataset):
class CastToString (line 40) | class CastToString(preprocessor.Preprocessor):
method transform (line 43) | def transform(self, dataset):
class TextTokenizer (line 53) | class TextTokenizer(preprocessor.Preprocessor):
method __init__ (line 56) | def __init__(self, max_len=100, vocab=None, max_vocab=500, **kwargs):
method fit (line 62) | def fit(self, dataset):
method transform (line 75) | def transform(self, dataset):
method get_config (line 86) | def get_config(self):
FILE: autokeras/preprocessors/common_test.py
function test_cast_to_int32_return_int32 (line 21) | def test_cast_to_int32_return_int32():
function test_cast_to_string_with_bytes (line 28) | def test_cast_to_string_with_bytes():
function test_cast_to_string_with_strings (line 36) | def test_cast_to_string_with_strings():
function test_text_tokenizer_vocab_limit (line 44) | def test_text_tokenizer_vocab_limit():
function test_text_tokenizer_transform (line 54) | def test_text_tokenizer_transform():
FILE: autokeras/preprocessors/encoders.py
class Encoder (line 24) | class Encoder(preprocessor.TargetPreprocessor):
method __init__ (line 31) | def __init__(self, labels, **kwargs):
method get_config (line 38) | def get_config(self):
method fit (line 41) | def fit(self, dataset):
method transform (line 44) | def transform(self, dataset):
class OneHotEncoder (line 63) | class OneHotEncoder(Encoder):
method transform (line 64) | def transform(self, dataset):
method postprocess (line 82) | def postprocess(self, data):
class LabelEncoder (line 105) | class LabelEncoder(Encoder):
method transform (line 108) | def transform(self, dataset):
method postprocess (line 120) | def postprocess(self, data):
class CategoricalToNumerical (line 145) | class CategoricalToNumerical(preprocessor.Preprocessor):
method __init__ (line 161) | def __init__(self, column_names, column_types, **kwargs):
method fit (line 175) | def fit(self, dataset):
method transform (line 192) | def transform(self, dataset):
method get_config (line 206) | def get_config(self):
method from_config (line 231) | def from_config(cls, config):
FILE: autokeras/preprocessors/encoders_test.py
function test_one_hot_encoder_deserialize_transforms_to_np (line 22) | def test_one_hot_encoder_deserialize_transforms_to_np():
function test_one_hot_encoder_decode_to_same_string (line 32) | def test_one_hot_encoder_decode_to_same_string():
function test_label_encoder_decode_to_same_string (line 40) | def test_label_encoder_decode_to_same_string():
function test_label_encoder_encode_to_correct_shape (line 48) | def test_label_encoder_encode_to_correct_shape():
FILE: autokeras/preprocessors/postprocessors.py
class PostProcessor (line 22) | class PostProcessor(preprocessor.TargetPreprocessor):
method transform (line 23) | def transform(self, dataset):
class SigmoidPostprocessor (line 28) | class SigmoidPostprocessor(PostProcessor):
method postprocess (line 31) | def postprocess(self, data):
class SoftmaxPostprocessor (line 47) | class SoftmaxPostprocessor(PostProcessor):
method postprocess (line 50) | def postprocess(self, data):
FILE: autokeras/preprocessors/postprocessors_test.py
function test_sigmoid_postprocess_to_zero_one (line 21) | def test_sigmoid_postprocess_to_zero_one():
function test_sigmoid_deserialize_without_error (line 29) | def test_sigmoid_deserialize_without_error():
function test_softmax_postprocess_to_zero_one (line 40) | def test_softmax_postprocess_to_zero_one():
function test_softmax_transform_dataset_doesnt_change (line 48) | def test_softmax_transform_dataset_doesnt_change():
function test_softmax_deserialize_without_error (line 55) | def test_softmax_deserialize_without_error():
FILE: autokeras/tasks/image.py
class SupervisedImagePipeline (line 33) | class SupervisedImagePipeline(auto_model.AutoModel):
method __init__ (line 34) | def __init__(self, outputs, **kwargs):
class ImageClassifier (line 40) | class ImageClassifier(SupervisedImagePipeline):
method __init__ (line 74) | def __init__(
method fit (line 110) | def fit(
class ImageRegressor (line 179) | class ImageRegressor(SupervisedImagePipeline):
method __init__ (line 211) | def __init__(
method fit (line 243) | def fit(
FILE: autokeras/tasks/image_test.py
function test_img_clf_fit_call_auto_model_fit (line 22) | def test_img_clf_fit_call_auto_model_fit(fit, tmp_path):
function test_img_reg_fit_call_auto_model_fit (line 34) | def test_img_reg_fit_call_auto_model_fit(fit, tmp_path):
FILE: autokeras/tasks/structured_data.py
class BaseStructuredDataPipeline (line 32) | class BaseStructuredDataPipeline(auto_model.AutoModel):
method __init__ (line 33) | def __init__(self, inputs, outputs, **kwargs):
method check (line 38) | def check(self, column_names, column_types):
method check_in_fit (line 49) | def check_in_fit(self, x):
method fit (line 60) | def fit(
method predict (line 119) | def predict(self, x, **kwargs):
method evaluate (line 133) | def evaluate(self, x, y=None, **kwargs):
class SupervisedStructuredDataPipeline (line 152) | class SupervisedStructuredDataPipeline(BaseStructuredDataPipeline):
method __init__ (line 153) | def __init__(self, outputs, column_names, column_types, **kwargs):
class StructuredDataClassifier (line 160) | class StructuredDataClassifier(SupervisedStructuredDataPipeline):
method __init__ (line 201) | def __init__(
method fit (line 241) | def fit(
class StructuredDataRegressor (line 295) | class StructuredDataRegressor(SupervisedStructuredDataPipeline):
method __init__ (line 334) | def __init__(
FILE: autokeras/tasks/structured_data_test.py
function test_raise_error_unknown_str_in_col_type (line 25) | def test_raise_error_unknown_str_in_col_type(tmp_path):
function test_structured_data_input_name_type_mismatch_error (line 36) | def test_structured_data_input_name_type_mismatch_error(tmp_path):
function test_structured_data_col_type_no_name_error (line 49) | def test_structured_data_col_type_no_name_error(tmp_path):
function test_structured_clf_evaluate_call_automodel_evaluate (line 63) | def test_structured_clf_evaluate_call_automodel_evaluate(
function test_structured_clf_predict_csv_call_automodel_predict (line 78) | def test_structured_clf_predict_csv_call_automodel_predict(
function test_structured_clf_fit_call_auto_model_fit (line 92) | def test_structured_clf_fit_call_auto_model_fit(fit, tmp_path):
function test_structured_reg_fit_call_auto_model_fit (line 106) | def test_structured_reg_fit_call_auto_model_fit(fit, tmp_path):
FILE: autokeras/tasks/text.py
class SupervisedTextPipeline (line 29) | class SupervisedTextPipeline(auto_model.AutoModel):
method __init__ (line 30) | def __init__(self, outputs, **kwargs):
class TextClassifier (line 36) | class TextClassifier(SupervisedTextPipeline):
method __init__ (line 70) | def __init__(
method fit (line 106) | def fit(
class TextRegressor (line 175) | class TextRegressor(SupervisedTextPipeline):
method __init__ (line 207) | def __init__(
method fit (line 239) | def fit(
FILE: autokeras/tasks/text_test.py
function test_txt_clf_fit_call_auto_model_fit (line 24) | def test_txt_clf_fit_call_auto_model_fit(fit, tmp_path):
function test_txt_reg_fit_call_auto_model_fit (line 33) | def test_txt_reg_fit_call_auto_model_fit(fit, tmp_path):
FILE: autokeras/test_utils.py
function generate_data (line 60) | def generate_data(num_instances=100, shape=(32, 32, 3)):
function generate_one_hot_labels (line 68) | def generate_one_hot_labels(num_instances=100, num_classes=10):
function generate_text_data (line 75) | def generate_text_data(num_instances=100):
function build_graph (line 98) | def build_graph():
function get_func_args (line 109) | def get_func_args(func):
function get_object_detection_data (line 114) | def get_object_detection_data():
function generate_data_with_categorical (line 134) | def generate_data_with_categorical(
FILE: autokeras/tuners/bayesian_optimization.py
class BayesianOptimization (line 20) | class BayesianOptimization(
FILE: autokeras/tuners/greedy.py
class TrieNode (line 26) | class TrieNode(object):
method __init__ (line 27) | def __init__(self):
method is_leaf (line 33) | def is_leaf(self):
class Trie (line 37) | class Trie(object):
method __init__ (line 38) | def __init__(self):
method insert (line 42) | def insert(self, hp_name):
method nodes (line 61) | def nodes(self):
method _get_all_nodes (line 64) | def _get_all_nodes(self, node):
method get_hp_names (line 70) | def get_hp_names(self, node):
class GreedyOracle (line 79) | class GreedyOracle(keras_tuner.Oracle):
method __init__ (line 96) | def __init__(self, initial_hps=None, seed=None, **kwargs):
method get_state (line 101) | def get_state(self):
method set_state (line 111) | def set_state(self, state):
method _select_hps (line 116) | def _select_hps(self):
method _next_initial_hps (line 137) | def _next_initial_hps(self):
method populate_space (line 143) | def populate_space(self, trial_id):
method _get_best_hps (line 168) | def _get_best_hps(self):
method _generate_hp_values (line 175) | def _generate_hp_values(self, hp_names):
class Greedy (line 208) | class Greedy(tuner_module.AutoTuner):
method __init__ (line 209) | def __init__(
FILE: autokeras/tuners/greedy_test.py
function test_greedy_oracle_get_state_update_space_can_run (line 26) | def test_greedy_oracle_get_state_update_space_can_run():
function test_greedy_oracle_populate_different_values (line 35) | def test_greedy_oracle_populate_different_values(get_best_trials):
function test_greedy_oracle_populate_doesnt_crash_with_init_hps (line 52) | def test_greedy_oracle_populate_doesnt_crash_with_init_hps(get_best_tria...
function test_greedy_oracle_stop_reach_max_collision (line 85) | def test_greedy_oracle_stop_reach_max_collision(
function test_greedy_oracle_populate_space_with_no_hp (line 106) | def test_greedy_oracle_populate_space_with_no_hp(get_best_trials):
FILE: autokeras/tuners/hyperband.py
class Hyperband (line 20) | class Hyperband(keras_tuner.Hyperband, tuner_module.AutoTuner):
method __init__ (line 23) | def __init__(
FILE: autokeras/tuners/random_search.py
class RandomSearch (line 20) | class RandomSearch(keras_tuner.RandomSearch, tuner_module.AutoTuner):
FILE: autokeras/tuners/task_specific.py
class ImageClassifierTuner (line 130) | class ImageClassifierTuner(greedy.Greedy):
method __init__ (line 131) | def __init__(self, **kwargs):
class TextClassifierTuner (line 135) | class TextClassifierTuner(greedy.Greedy):
method __init__ (line 136) | def __init__(self, **kwargs):
class StructuredDataClassifierTuner (line 140) | class StructuredDataClassifierTuner(greedy.Greedy):
method __init__ (line 141) | def __init__(self, **kwargs):
class StructuredDataRegressorTuner (line 145) | class StructuredDataRegressorTuner(greedy.Greedy):
method __init__ (line 146) | def __init__(self, **kwargs):
FILE: autokeras/tuners/task_specific_test.py
function test_img_clf_init_hp0_equals_hp_of_a_model (line 23) | def test_img_clf_init_hp0_equals_hp_of_a_model(tmp_path):
function test_img_clf_init_hp1_equals_hp_of_a_model (line 36) | def test_img_clf_init_hp1_equals_hp_of_a_model(tmp_path):
function test_img_clf_init_hp2_equals_hp_of_a_model (line 49) | def test_img_clf_init_hp2_equals_hp_of_a_model(tmp_path):
function test_txt_clf_init_hp0_equals_hp_of_a_model (line 62) | def test_txt_clf_init_hp0_equals_hp_of_a_model(tmp_path):
function test_sd_clf_init_hp0_equals_hp_of_a_model (line 79) | def test_sd_clf_init_hp0_equals_hp_of_a_model(tmp_path):
function test_sd_reg_init_hp0_equals_hp_of_a_model (line 96) | def test_sd_reg_init_hp0_equals_hp_of_a_model(tmp_path):
FILE: autokeras/utils/data_utils.py
function split_dataset (line 21) | def split_dataset(dataset, validation_split):
function cast_to_float32 (line 56) | def cast_to_float32(tensor):
function dataset_shape (line 62) | def dataset_shape(dataset):
FILE: autokeras/utils/data_utils_test.py
function test_split_data_has_one_batch_error (line 21) | def test_split_data_has_one_batch_error():
FILE: autokeras/utils/io_utils.py
function save_json (line 22) | def save_json(path, obj):
function load_json (line 27) | def load_json(path):
function deserialize_block_arg (line 32) | def deserialize_block_arg(arg):
function serialize_block_arg (line 38) | def serialize_block_arg(arg):
FILE: autokeras/utils/layer_utils.py
function get_global_average_pooling (line 18) | def get_global_average_pooling(shape):
function get_global_max_pooling (line 26) | def get_global_max_pooling(shape):
function get_max_pooling (line 34) | def get_max_pooling(shape):
function get_conv (line 42) | def get_conv(shape):
function get_sep_conv (line 46) | def get_sep_conv(shape):
FILE: autokeras/utils/utils.py
function validate_num_inputs (line 47) | def validate_num_inputs(inputs, num):
function to_snake_case (line 56) | def to_snake_case(name):
function contain_instance (line 62) | def contain_instance(instance_list, instance_type):
function evaluate_with_adaptive_batch_size (line 68) | def evaluate_with_adaptive_batch_size(
function predict_with_adaptive_batch_size (line 80) | def predict_with_adaptive_batch_size(
function fit_with_adaptive_batch_size (line 92) | def fit_with_adaptive_batch_size(model, batch_size, **fit_kwargs):
function run_with_adaptive_batch_size (line 99) | def run_with_adaptive_batch_size(batch_size, func, **fit_kwargs):
function get_hyperparameter (line 123) | def get_hyperparameter(value, hp, dtype):
function add_to_hp (line 129) | def add_to_hp(hp, hps, name=None):
function serialize_keras_object (line 148) | def serialize_keras_object(obj):
function deserialize_keras_object (line 152) | def deserialize_keras_object(config, module_objects=None, custom_objects...
FILE: autokeras/utils/utils_test.py
function test_validate_num_inputs_error (line 21) | def test_validate_num_inputs_error():
function test_get_hyperparameter_with_none_return_hp (line 28) | def test_get_hyperparameter_with_none_return_hp():
function test_get_hyperparameter_with_int_return_int (line 35) | def test_get_hyperparameter_with_int_return_int():
function test_get_hyperparameter_with_hp_return_same (line 43) | def test_get_hyperparameter_with_hp_return_same():
FILE: benchmark/experiments/__init__.py
function get_experiments (line 18) | def get_experiments(task_name):
FILE: benchmark/experiments/experiment.py
class Experiment (line 19) | class Experiment(object):
method __init__ (line 20) | def __init__(self, name, tmp_dir="tmp_dir"):
method get_auto_model (line 24) | def get_auto_model(self):
method load_data (line 28) | def load_data():
method run_once (line 31) | def run_once(self):
method run (line 44) | def run(self, repeat_times=1):
method tear_down (line 54) | def tear_down(self):
FILE: benchmark/experiments/image.py
class ImageClassifierExperiment (line 21) | class ImageClassifierExperiment(experiment.Experiment):
method get_auto_model (line 22) | def get_auto_model(self):
class MNIST (line 28) | class MNIST(ImageClassifierExperiment):
method __init__ (line 29) | def __init__(self):
method load_data (line 33) | def load_data():
class CIFAR10 (line 37) | class CIFAR10(ImageClassifierExperiment):
method __init__ (line 38) | def __init__(self):
method load_data (line 42) | def load_data():
FILE: benchmark/experiments/structured_data.py
class StructuredDataClassifierExperiment (line 24) | class StructuredDataClassifierExperiment(experiment.Experiment):
method get_auto_model (line 25) | def get_auto_model(self):
class Titanic (line 31) | class Titanic(StructuredDataClassifierExperiment):
method __init__ (line 32) | def __init__(self):
method load_data (line 36) | def load_data():
class Iris (line 49) | class Iris(StructuredDataClassifierExperiment):
method __init__ (line 50) | def __init__(self):
method load_data (line 54) | def load_data():
class Wine (line 71) | class Wine(StructuredDataClassifierExperiment):
method __init__ (line 72) | def __init__(self):
method load_data (line 76) | def load_data():
class StructuredDataRegressorExperiment (line 94) | class StructuredDataRegressorExperiment(experiment.Experiment):
method get_auto_model (line 95) | def get_auto_model(self):
class CaliforniaHousing (line 101) | class CaliforniaHousing(StructuredDataRegressorExperiment):
method load_data (line 103) | def load_data():
FILE: benchmark/experiments/text.py
class IMDB (line 25) | class IMDB(experiment.Experiment):
method __init__ (line 26) | def __init__(self):
method get_auto_model (line 29) | def get_auto_model(self):
method load_data (line 35) | def load_data():
FILE: benchmark/performance.py
function imdb_raw (line 25) | def imdb_raw(num_instances=100):
function test_mnist_accuracy_over_98 (line 56) | def test_mnist_accuracy_over_98(tmp_path):
function test_cifar10_accuracy_over_93 (line 64) | def test_cifar10_accuracy_over_93(tmp_path):
function test_imdb_accuracy_over_92 (line 72) | def test_imdb_accuracy_over_92(tmp_path):
function test_titaninc_accuracy_over_77 (line 80) | def test_titaninc_accuracy_over_77(tmp_path):
FILE: benchmark/run.py
function generate_report (line 21) | def generate_report(experiments):
function main (line 43) | def main(argv):
FILE: docker/pre_commit.py
function check_bash_call (line 5) | def check_bash_call(string):
function _run_format_and_flake8 (line 9) | def _run_format_and_flake8():
function run_format_and_flake8 (line 28) | def run_format_and_flake8():
FILE: docs/autogen.py
function py_to_nb_md (line 103) | def py_to_nb_md(dest_dir):
function generate (line 144) | def generate(dest_dir):
FILE: docs/keras_autodoc/autogen.py
class DocumentationGenerator (line 16) | class DocumentationGenerator:
method __init__ (line 58) | def __init__(
method generate (line 77) | def generate(self, dest_dir):
method process_docstring (line 102) | def process_docstring(self, docstring, types: dict = None):
method process_signature (line 107) | def process_signature(self, signature):
method _render (line 111) | def _render(self, element):
method _render_from_object (line 125) | def _render_from_object(self, object_, signature_override: str):
method _fill_aliases (line 146) | def _fill_aliases(self, extra_aliases):
FILE: docs/keras_autodoc/docstring.py
function get_code_blocks (line 9) | def get_code_blocks(docstring):
function get_section_end (line 25) | def get_section_end(docstring, section_start):
function get_google_style_sections_without_code (line 35) | def get_google_style_sections_without_code(docstring):
function get_google_style_sections (line 54) | def get_google_style_sections(docstring):
function to_markdown (line 71) | def to_markdown(
function format_as_markdown_list (line 91) | def format_as_markdown_list(
function apply_aliases (line 110) | def apply_aliases(string: str, aliases: dict):
function reinject_strings (line 116) | def reinject_strings(target, strings_to_inject):
function process_docstring (line 122) | def process_docstring(docstring, types: dict = None, aliases=None):
FILE: docs/keras_autodoc/examples.py
function copy_examples (line 5) | def copy_examples(examples_dir, destination_dir):
function get_module_docstring (line 38) | def get_module_docstring(filepath):
FILE: docs/keras_autodoc/gathering_members.py
function get_classes (line 10) | def get_classes(module, exclude: List[str] = None, return_strings: bool ...
function get_functions (line 31) | def get_functions(
function get_methods (line 54) | def get_methods(cls, exclude=None, return_strings=True):
function _get_all_module_element (line 90) | def _get_all_module_element(module, exclude, return_strings, class_):
FILE: docs/keras_autodoc/get_signatures.py
function get_signature_start (line 11) | def get_signature_start(function):
function get_signature_end (line 28) | def get_signature_end(function):
function get_function_signature (line 37) | def get_function_signature(function, override=None, max_line_length: int...
function get_class_signature (line 46) | def get_class_signature(cls, override=None, max_line_length: int = 110):
function get_signature (line 55) | def get_signature(object_, override=None, max_line_length: int = 110):
function format_signature (line 62) | def format_signature(
function extract_signature_end (line 81) | def extract_signature_end(function_definition):
FILE: docs/keras_autodoc/utils.py
function count_leading_spaces (line 7) | def count_leading_spaces(s):
function insert_in_file (line 15) | def insert_in_file(markdown_text, file_path):
function code_snippet (line 35) | def code_snippet(snippet):
function make_source_link (line 39) | def make_source_link(cls, project_url):
function format_classes_list (line 52) | def format_classes_list(classes, page_name):
function get_class_from_method (line 66) | def get_class_from_method(meth):
function ismethod (line 89) | def ismethod(function):
function import_object (line 93) | def import_object(string: str):
function get_type (line 110) | def get_type(object_) -> str:
function insert_in_string (line 124) | def insert_in_string(target, string_to_insert, start, end):
function remove_indentation (line 130) | def remove_indentation(string):
function get_dotted_path (line 137) | def get_dotted_path(class_):
FILE: docs/py/customized.py
class SingleDenseLayerBlock (line 109) | class SingleDenseLayerBlock(ak.Block):
method build (line 110) | def build(self, hp, inputs=None):
FILE: docs/tutobooks.py
function nb_to_py (line 75) | def nb_to_py(nb_path, py_path):
function py_to_nb (line 122) | def py_to_nb(py_path, nb_path, fill_outputs=True):
function nb_to_md (line 211) | def nb_to_md(nb_path, md_path, img_dir, working_dir=None):
function py_to_md (line 270) | def py_to_md(py_path, nb_path, md_path, img_dir, working_dir=None):
function validate (line 275) | def validate(py):
function _count_locs (line 337) | def _count_locs(lines):
function _shorten_lines (line 356) | def _shorten_lines(py):
function _get_next_script_element (line 386) | def _get_next_script_element(py):
function _parse_header (line 418) | def _parse_header(header):
function _make_output_code_blocks (line 441) | def _make_output_code_blocks(md):
FILE: examples/celeb_age.py
function datenum_to_datetime (line 93) | def datenum_to_datetime(datenum):
function df2numpy (line 171) | def df2numpy(train_set):
FILE: examples/imdb.py
function imdb_raw (line 13) | def imdb_raw():
FILE: examples/reuters.py
function reuters_raw (line 20) | def reuters_raw(max_features=20000):
FILE: shell/contributors.py
function main (line 11) | def main(directory):
Condensed preview — 184 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (657K chars).
[
{
"path": ".devcontainer/Dockerfile",
"chars": 80,
"preview": "FROM mcr.microsoft.com/vscode/devcontainers/python:3.10\nCOPY setup.sh /setup.sh\n"
},
{
"path": ".devcontainer/devcontainer.json",
"chars": 746,
"preview": "{\n \"dockerFile\": \"Dockerfile\",\n \"postCreateCommand\": \"sh /setup.sh\",\n\t\"customizations\": {\n\t\t\"vscode\": {\n\t\t\t\"settin"
},
{
"path": ".devcontainer/setup.sh",
"chars": 141,
"preview": "sudo pip install --upgrade pip\nsudo pip install -e \".[tests]\"\necho \"sh shell/lint.sh\" > .git/hooks/pre-commit\nchmod a+x "
},
{
"path": ".dockerignore",
"chars": 26,
"preview": ".git\n.github\n*.Dockerfile\n"
},
{
"path": ".github/CODEOWNERS",
"chars": 25,
"preview": "* @haifeng-jin @fchollet\n"
},
{
"path": ".github/CODE_OF_CONDUCT.md",
"chars": 3209,
"preview": "# Contributor Covenant Code of Conduct\n\n## Our Pledge\n\nIn the interest of fostering an open and welcoming environment, w"
},
{
"path": ".github/CONTRIBUTING.md",
"chars": 2984,
"preview": "# Contributing Guide\n\nContributions are welcome, and greatly appreciated!\nThis page is only a guide of the best practice"
},
{
"path": ".github/ISSUE_TEMPLATE/bug_report.md",
"chars": 709,
"preview": "---\nname: Bug report\nabout: Create a report to help us improve\nlabels: [\"bug report\"]\ntitle: \"Bug: \"\n\n---\n\n### Bug Descr"
},
{
"path": ".github/ISSUE_TEMPLATE/custom.md",
"chars": 91,
"preview": "---\nname: Custom issue template\nabout: Describe this issue template's purpose here.\n\n---\n\n\n"
},
{
"path": ".github/ISSUE_TEMPLATE/feature_request.md",
"chars": 425,
"preview": "---\nname: Feature request\nabout: Suggest an idea for this project\nlabels: [\"feature request\"]\ntitle: \"Feature: \"\n\n---\n\n#"
},
{
"path": ".github/ISSUE_TEMPLATE/new-task-template.md",
"chars": 935,
"preview": "---\nname: New Task Template\nabout: Add a new machine learning task\nlabels: [\"algorithm\"]\ntitle: \"New Task: \"\n\n---\n\n<!---"
},
{
"path": ".github/PULL_REQUEST_TEMPLATE.md",
"chars": 525,
"preview": "<!-- STEP 1: Give the pull request a meaningful title. -->\n### Which issue(s) does this Pull Request fix?\n<!-- STEP 2: R"
},
{
"path": ".github/dependabot.yml",
"chars": 361,
"preview": "version: 2\nupdates:\n- package-ecosystem: pip\n directory: \"/\"\n schedule:\n interval: daily\n time: \"11:00\"\n open-p"
},
{
"path": ".github/workflows/actions.yml",
"chars": 2685,
"preview": "name: Tests\n\non:\n push:\n branches: [ master ]\n pull_request:\n release:\n types: [created]\njobs:\n build:\n nam"
},
{
"path": ".gitignore",
"chars": 1482,
"preview": "# vim swp files\n*.swp\n# caffe/pytorch model files\n*.pth\n\n# Mkdocs\n/docs/sources\n/docs/site\n\n.DS_Store\n.vscode\nsettings.j"
},
{
"path": "LICENSE",
"chars": 11354,
"preview": "\n Apache License\n Version 2.0, January 2004\n "
},
{
"path": "README.md",
"chars": 4088,
"preview": "<p align=\"center\">\n <img width=\"500\" alt=\"logo\" src=\"https://autokeras.com/img/row_red.svg\"/>\n</p>\n\n[;\n# you may no"
},
{
"path": "autokeras/adapters/__init__.py",
"chars": 965,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/adapters/input_adapters.py",
"chars": 2440,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/adapters/input_adapters_test.py",
"chars": 2893,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/adapters/output_adapters.py",
"chars": 1151,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/adapters/output_adapters_test.py",
"chars": 1082,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/analysers/__init__.py",
"chars": 1101,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/analysers/input_analysers.py",
"chars": 6144,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/analysers/input_analysers_test.py",
"chars": 4130,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/analysers/output_analysers.py",
"chars": 4113,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/analysers/output_analysers_test.py",
"chars": 4319,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/auto_model.py",
"chars": 18848,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/auto_model_test.py",
"chars": 8246,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/__init__.py",
"chars": 1846,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/basic.py",
"chars": 24132,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/basic_test.py",
"chars": 8925,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/heads.py",
"chars": 9569,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/heads_test.py",
"chars": 4238,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/preprocessing.py",
"chars": 9083,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/preprocessing_test.py",
"chars": 3220,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/reduction.py",
"chars": 6142,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/reduction_test.py",
"chars": 4302,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/wrapper.py",
"chars": 7384,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/blocks/wrapper_test.py",
"chars": 4734,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/conftest.py",
"chars": 985,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/__init__.py",
"chars": 586,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/adapter.py",
"chars": 1429,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/adapter_test.py",
"chars": 753,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/analyser.py",
"chars": 1968,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/analyser_test.py",
"chars": 2003,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/block.py",
"chars": 2617,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/block_test.py",
"chars": 859,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/head.py",
"chars": 2784,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/head_test.py",
"chars": 729,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/hyper_preprocessor.py",
"chars": 1189,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/io_hypermodel.py",
"chars": 2382,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/named_hypermodel.py",
"chars": 1448,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/node.py",
"chars": 959,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/node_test.py",
"chars": 586,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/preprocessor.py",
"chars": 1860,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/serializable.py",
"chars": 1089,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/tuner.py",
"chars": 11171,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/engine/tuner_test.py",
"chars": 6805,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/graph.py",
"chars": 12076,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/graph_test.py",
"chars": 6061,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/hyper_preprocessors.py",
"chars": 1952,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/hyper_preprocessors_test.py",
"chars": 2215,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/integration_tests/__init__.py",
"chars": 586,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/integration_tests/functional_api_test.py",
"chars": 2934,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/integration_tests/io_api_test.py",
"chars": 1968,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/integration_tests/task_api_test.py",
"chars": 4599,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/keras_layers.py",
"chars": 1373,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/keras_layers_test.py",
"chars": 1611,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/nodes.py",
"chars": 6999,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/nodes_test.py",
"chars": 793,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/pipeline.py",
"chars": 7123,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/pipeline_test.py",
"chars": 1424,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/preprocessors/__init__.py",
"chars": 1461,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/preprocessors/common.py",
"chars": 3168,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/preprocessors/common_test.py",
"chars": 2071,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/preprocessors/encoders.py",
"chars": 8259,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/preprocessors/encoders_test.py",
"chars": 1778,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/preprocessors/postprocessors.py",
"chars": 1964,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/preprocessors/postprocessors_test.py",
"chars": 1950,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tasks/__init__.py",
"chars": 918,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tasks/image.py",
"chars": 14058,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tasks/image_test.py",
"chars": 1423,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tasks/structured_data.py",
"chars": 16317,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tasks/structured_data_test.py",
"chars": 3670,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tasks/text.py",
"chars": 13667,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tasks/text_test.py",
"chars": 1239,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/test_utils.py",
"chars": 3980,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tuners/__init__.py",
"chars": 871,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tuners/bayesian_optimization.py",
"chars": 837,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tuners/greedy.py",
"chars": 7877,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tuners/greedy_test.py",
"chars": 3880,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tuners/hyperband.py",
"chars": 1000,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tuners/hyperband_test.py",
"chars": 586,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tuners/random_search.py",
"chars": 807,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tuners/random_search_test.py",
"chars": 586,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tuners/task_specific.py",
"chars": 6118,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/tuners/task_specific_test.py",
"chars": 3501,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/utils/__init__.py",
"chars": 586,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/utils/data_utils.py",
"chars": 2432,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/utils/data_utils_test.py",
"chars": 872,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/utils/io_utils.py",
"chars": 1153,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/utils/layer_utils.py",
"chars": 1381,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/utils/types.py",
"chars": 1008,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/utils/utils.py",
"chars": 4480,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "autokeras/utils/utils_test.py",
"chars": 1552,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "benchmark/README.md",
"chars": 73,
"preview": "Usage: python benchmark/run.py structured_data_classification report.csv\n"
},
{
"path": "benchmark/__init__.py",
"chars": 586,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "benchmark/datasets/titanic_test.csv",
"chars": 8298,
"preview": "sex,age,n_siblings_spouses,parch,fare,class,deck,embark_town,alone,survived\nfemale,15,0,0,7.225,3,?,C,True,1\nfemale,1,0,"
},
{
"path": "benchmark/datasets/titanic_train.csv",
"chars": 34363,
"preview": "sex,age,n_siblings_spouses,parch,fare,class,deck,embark_town,alone,survived\nfemale,29,0,0,211.3375,1,B5,S,True,1\nmale,0."
},
{
"path": "benchmark/experiments/__init__.py",
"chars": 863,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "benchmark/experiments/experiment.py",
"chars": 1680,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "benchmark/experiments/image.py",
"chars": 1262,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "benchmark/experiments/structured_data.py",
"chars": 3606,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "benchmark/experiments/text.py",
"chars": 1896,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "benchmark/performance.py",
"chars": 3203,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "benchmark/run.py",
"chars": 1543,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "codecov.yml",
"chars": 116,
"preview": "coverage:\n status:\n project:\n default:\n target: 100%\n patch:\n default:\n target: 100%\n"
},
{
"path": "docker/Dockerfile",
"chars": 133,
"preview": "FROM tensorflow/tensorflow:2.3.0\nWORKDIR /opt/autokeras\nCOPY . .\nRUN python -m pip install --no-cache-dir --editable .\nW"
},
{
"path": "docker/Makefile",
"chars": 704,
"preview": "help:\n\t@cat Makefile\n\nDATA?=\"${HOME}/Data\"\nGPUS?=all\nDOCKER_FILE?=Dockerfile\nDOCKER=docker\nTF_VERSION=2.3.0\nTEST=tests/\n"
},
{
"path": "docker/README.md",
"chars": 1556,
"preview": "# Using Autokeras via Docker\n\nThis directory contains `Dockerfile` to make it easy to get up and running with\nAutokeras "
},
{
"path": "docker/devel.Dockerfile",
"chars": 650,
"preview": "FROM ubuntu:18.04\n\nRUN mkdir /app\n\nWORKDIR /app\n\n\nRUN apt-get update && apt-get install -y --no-install-recommends \\\n "
},
{
"path": "docker/pre-commit.Dockerfile",
"chars": 111,
"preview": "FROM python:3.7\n\nRUN pip install flake8 black isort\n\nWORKDIR /autokeras\nCMD [\"python\", \"docker/pre_commit.py\"]\n"
},
{
"path": "docker/pre_commit.py",
"chars": 839,
"preview": "from subprocess import CalledProcessError\nfrom subprocess import check_call\n\n\ndef check_bash_call(string):\n check_cal"
},
{
"path": "docs/README.md",
"chars": 825,
"preview": "# AutoKeras Documentation\n\nThe source for AutoKeras documentation is in this directory.\nOur documentation uses extended "
},
{
"path": "docs/autogen.py",
"chars": 5241,
"preview": "import os\nimport pathlib\nimport shutil\n\nimport keras_autodoc\nimport tutobooks\n\nPAGES = {\n \"image_classifier.md\": [\n "
},
{
"path": "docs/ipynb/customized.ipynb",
"chars": 8919,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 0,\n \"metadata\": {\n \"colab_type\": \"code\"\n },\n \"o"
},
{
"path": "docs/ipynb/export.ipynb",
"chars": 2544,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 0,\n \"metadata\": {\n \"colab_type\": \"code\"\n },\n \"o"
},
{
"path": "docs/ipynb/image_classification.ipynb",
"chars": 7294,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 0,\n \"metadata\": {\n \"colab_type\": \"code\"\n },\n \"o"
},
{
"path": "docs/ipynb/image_regression.ipynb",
"chars": 7580,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 0,\n \"metadata\": {\n \"colab_type\": \"code\"\n },\n \"o"
},
{
"path": "docs/ipynb/multi.ipynb",
"chars": 9673,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 0,\n \"metadata\": {\n \"colab_type\": \"code\"\n },\n \"o"
},
{
"path": "docs/ipynb/structured_data_classification.ipynb",
"chars": 6236,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 0,\n \"metadata\": {\n \"colab_type\": \"code\"\n },\n \"o"
},
{
"path": "docs/ipynb/structured_data_regression.ipynb",
"chars": 5899,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 0,\n \"metadata\": {\n \"colab_type\": \"code\"\n },\n \"o"
},
{
"path": "docs/ipynb/text_classification.ipynb",
"chars": 6450,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 0,\n \"metadata\": {\n \"colab_type\": \"code\"\n },\n \"o"
},
{
"path": "docs/ipynb/text_regression.ipynb",
"chars": 6724,
"preview": "{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 0,\n \"metadata\": {\n \"colab_type\": \"code\"\n },\n \"o"
},
{
"path": "docs/keras_autodoc/__init__.py",
"chars": 175,
"preview": "from .autogen import DocumentationGenerator\nfrom .gathering_members import get_classes\nfrom .gathering_members import ge"
},
{
"path": "docs/keras_autodoc/autogen.py",
"chars": 6784,
"preview": "import pathlib\nimport shutil\nfrom inspect import getdoc\nfrom inspect import isclass\nfrom typing import Dict\nfrom typing "
},
{
"path": "docs/keras_autodoc/docstring.py",
"chars": 4414,
"preview": "import itertools\nimport re\n\nfrom sphinx.util.typing import stringify_annotation\n\nfrom . import utils\n\n\ndef get_code_bloc"
},
{
"path": "docs/keras_autodoc/examples.py",
"chars": 1613,
"preview": "import os\nimport pathlib\n\n\ndef copy_examples(examples_dir, destination_dir):\n \"\"\"Copy the examples directory in the d"
},
{
"path": "docs/keras_autodoc/gathering_members.py",
"chars": 4159,
"preview": "import inspect\nfrom inspect import isclass\nfrom inspect import isfunction\nfrom inspect import isroutine\nfrom typing impo"
},
{
"path": "docs/keras_autodoc/get_signatures.py",
"chars": 2870,
"preview": "import inspect\nimport warnings\n\nimport black\nfrom sphinx.util.inspect import signature\nfrom sphinx.util.inspect import s"
},
{
"path": "docs/keras_autodoc/utils.py",
"chars": 4061,
"preview": "import importlib\nimport inspect\nimport os\nimport re\n\n\ndef count_leading_spaces(s):\n ws = re.search(r\"\\S\", s)\n if w"
},
{
"path": "docs/mkdocs.yml",
"chars": 2004,
"preview": "site_name: AutoKeras\ntheme:\n favicon: '/img/favicon.png'\n logo: '/img/logo_white.svg'\n name: 'material'\n\ndocs_dir: so"
},
{
"path": "docs/py/customized.py",
"chars": 5729,
"preview": "\"\"\"shell\nexport KERAS_BACKEND=\"torch\"\npip install autokeras\n\"\"\"\n\nimport keras\nimport numpy as np\nimport tree\nfrom keras."
},
{
"path": "docs/py/export.py",
"chars": 1139,
"preview": "\"\"\"shell\nexport KERAS_BACKEND=\"torch\"\npip install autokeras\n\"\"\"\n\nimport numpy as np\nfrom keras.datasets import mnist\nfro"
},
{
"path": "docs/py/image_classification.py",
"chars": 3964,
"preview": "\"\"\"shell\nexport KERAS_BACKEND=\"torch\"\npip install autokeras\n\"\"\"\n\nfrom keras.datasets import mnist\n\nimport autokeras as a"
},
{
"path": "docs/py/image_regression.py",
"chars": 4219,
"preview": "\"\"\"shell\nexport KERAS_BACKEND=\"torch\"\npip install autokeras\n\"\"\"\n\nfrom keras.datasets import mnist\n\nimport autokeras as a"
},
{
"path": "docs/py/multi.py",
"chars": 5767,
"preview": "\"\"\"shell\nexport KERAS_BACKEND=\"torch\"\npip install autokeras\n\"\"\"\n\nimport numpy as np\n\nimport autokeras as ak\n\n\"\"\"\nIn this"
},
{
"path": "docs/py/structured_data_classification.py",
"chars": 3197,
"preview": "\"\"\"shell\nexport KERAS_BACKEND=\"torch\"\npip install autokeras\n\"\"\"\n\nimport keras\nimport pandas as pd\n\nimport autokeras as a"
},
{
"path": "docs/py/structured_data_regression.py",
"chars": 2952,
"preview": "\"\"\"shell\nexport KERAS_BACKEND=\"torch\"\npip install autokeras\n\"\"\"\n\nfrom sklearn.datasets import fetch_california_housing\n\n"
},
{
"path": "docs/py/text_classification.py",
"chars": 3402,
"preview": "\"\"\"shell\nexport KERAS_BACKEND=\"torch\"\npip install autokeras\n\"\"\"\n\nimport os\n\nimport keras\nimport numpy as np\nfrom sklearn"
},
{
"path": "docs/py/text_regression.py",
"chars": 3644,
"preview": "\"\"\"shell\nexport KERAS_BACKEND=\"torch\"\npip install autokeras\n\"\"\"\n\nimport os\n\nimport keras\nimport numpy as np\nfrom sklearn"
},
{
"path": "docs/requirements.txt",
"chars": 80,
"preview": "mkdocs\nmkdocs-material\npygments\njupyter\npymdown-extensions\nSphinx\nmarkdown\nblack"
},
{
"path": "docs/run_py_files.sh",
"chars": 285,
"preview": "#!/bin/bash\n\nSUCCESS_FILE=\"success.txt\"\nFAILURE_FILE=\"failure.txt\"\n\n# Clear the files\n> $SUCCESS_FILE\n> $FAILURE_FILE\n\nf"
},
{
"path": "docs/templates/about.md",
"chars": 725,
"preview": "This package is developed by [DATA LAB](http://faculty.cs.tamu.edu/xiahu/) at Texas A&M University,\ncollaborating with ["
},
{
"path": "docs/templates/index.md",
"chars": 145,
"preview": "#\n<img src=\"/img/row_red.svg\" alt=\"drawing\" width=\"400px\" style=\"display: block; margin-left: auto; margin-right: auto\"/"
},
{
"path": "docs/templates/install.md",
"chars": 907,
"preview": "## Requirements\n\n**Python 3**: Follow the TensorFlow install steps to install Python 3.\n\n**Pip**: Follow the TensorFlow "
},
{
"path": "docs/templates/stylesheets/extra.css",
"chars": 78,
"preview": ":root>* {\n --md-primary-fg-color: #d00000;\n --md-accent-fg-color: #d00000;\n}"
},
{
"path": "docs/templates/tutorial/faq.md",
"chars": 1494,
"preview": "## How to resume a previously killed run?\nThis feature is controlled by the `overwrite` argument of `AutoModel` or any o"
},
{
"path": "docs/templates/tutorial/overview.md",
"chars": 2181,
"preview": "# AutoKeras 1.0 Tutorial\n\n## Supported Tasks\n\nAutoKeras supports several tasks with an extremely simple interface.\nYou c"
},
{
"path": "docs/tutobooks.py",
"chars": 17649,
"preview": "\"\"\"Keras tutobooks implementation.\n\nA tutobook is a tutorial available simultaneously as a notebook,\nas a Python script,"
},
{
"path": "examples/automodel_with_cnn.py",
"chars": 1350,
"preview": "# Library import\nimport keras\nimport numpy as np\n\nimport autokeras as ak\n\n# Prepare example Data - Shape 1D\nnum_instance"
},
{
"path": "examples/celeb_age.py",
"chars": 8009,
"preview": "\"\"\"\nRegression tasks estimate a numeric variable, such as the price of a house or\nvoter turnout.\n\nThis example is adapte"
},
{
"path": "examples/cifar10.py",
"chars": 392,
"preview": "from keras.datasets import cifar10\n\nimport autokeras as ak\n\n# Prepare the dataset.\n(x_train, y_train), (x_test, y_test) "
},
{
"path": "examples/imdb.py",
"chars": 1628,
"preview": "\"\"\"\nSearch for a good model for the\n[IMDB](\nhttps://keras.io/datasets/#imdb-movie-reviews-sentiment-classification) data"
},
{
"path": "examples/mnist.py",
"chars": 634,
"preview": "\"\"\"\nSearch for a good model for the\n[MNIST](https://keras.io/datasets/#mnist-database-of-handwritten-digits)\ndataset.\n\"\""
},
{
"path": "examples/new_pop.py",
"chars": 1071,
"preview": "\"\"\"shell\npip install autokeras\n\"\"\"\n\nimport pandas as pd\n\nimport autokeras as ak\n\n\"\"\"\n## Social Media Articles Example\n\nR"
},
{
"path": "examples/reuters.py",
"chars": 1915,
"preview": "\"\"\"shell\n!pip install -q -U pip\n!pip install -q -U autokeras==1.0.8\n!pip install -q git+https://github.com/keras-team/ke"
},
{
"path": "pyproject.toml",
"chars": 1680,
"preview": "[build-system]\nrequires = [\"setuptools>=61.0\"]\nbuild-backend = \"setuptools.build_meta\"\n\n[project]\nname = \"autokeras\"\naut"
},
{
"path": "setup.cfg",
"chars": 450,
"preview": "[tool:pytest]\naddopts=-v\n -p no:warnings\n --durations=10\n --log-cli-level=CRITICAL\n\n# Do not run te"
},
{
"path": "shell/contributors.py",
"chars": 2268,
"preview": "import base64\nimport json\nimport os\nimport sys\nfrom io import BytesIO\n\nimport requests\nfrom PIL import Image\n\n\ndef main("
},
{
"path": "shell/contributors.sh",
"chars": 339,
"preview": "# node shell/generate_json.js\ngh api -H \"Accept: application/vnd.github+json\" /repos/keras-team/autokeras/contributors -"
},
{
"path": "shell/copyright.txt",
"chars": 587,
"preview": "# Copyright 2020 The AutoKeras Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may no"
},
{
"path": "shell/cov.sh",
"chars": 72,
"preview": "pytest tests --cov-report html --cov-report xml:cov.xml --cov=autokeras\n"
},
{
"path": "shell/coverage.sh",
"chars": 50,
"preview": "pytest --cov-report xml:cov.xml --cov autokeras $1"
},
{
"path": "shell/docs.sh",
"chars": 363,
"preview": "#!/usr/bin/env bash\ncd docs\npython autogen.py\nmkdocs build\ncd ..\nsh shell/format.sh\necho \"autokeras.com\" > docs/site/CNA"
},
{
"path": "shell/format.sh",
"chars": 192,
"preview": "isort .\nblack .\n\nfor i in $(find autokeras benchmark -name '*.py')\ndo\n if ! grep -q Copyright $i\n then\n echo $i\n "
},
{
"path": "shell/generate_json.js",
"chars": 307,
"preview": "const { Octokit } = require(\"@octokit/rest\");\nconst fs = require('fs')\nconst octokit = new Octokit({});\n\noctokit.paginat"
},
{
"path": "shell/lint.sh",
"chars": 514,
"preview": "isort -c .\nif ! [ $? -eq 0 ]\nthen\n echo \"Please run \\\"sh shell/format.sh\\\" to format the code.\"\n exit 1\nfi\nflake8 .\nif"
},
{
"path": "shell/perf.sh",
"chars": 50,
"preview": "pytest tests/performance.py | tee perf_output.txt\n"
},
{
"path": "shell/pre-commit.sh",
"chars": 191,
"preview": "#!/usr/bin/env bash\n\nset -e\n\nexport DOCKER_BUILDKIT=1\ndocker build -t autokeras_formatting -f docker/pre-commit.Dockerfi"
},
{
"path": "shell/pypi.sh",
"chars": 115,
"preview": "#!/usr/bin/env bash\nrm dist/*\npython -m build\ntwine upload --repository-url https://upload.pypi.org/legacy/ dist/*\n"
}
]
About this extraction
This page contains the full source code of the keras-team/autokeras GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 184 files (601.8 KB), approximately 167.7k tokens, and a symbol index with 769 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.