Skip to content

Commit cbffa8b

Browse files
authored
Support Keras 3 with TF backend (#1908)
* initial renaming * renaming tree * rename tensorflow.keras * update * update version numbers * update imports to keras * now the tests can run bug failed some * fix more tests * fix more tests * fix more tests * removed structured data and time series, object detection, and segmentation * remove structured data from docs * fix docs * minor fix * fix more tests * fix more tests * fix more tests * update docs * update * fix more tests * add notes & improve coverage * fix tests * update * update * update input block * fix coverage * update the tutorials
1 parent ec4ebd1 commit cbffa8b

File tree

114 files changed

+514
-6756
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+514
-6756
lines changed

RELEASE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# Release v2.0.0
2+
3+
## Breaking changes
4+
5+
* Requires `keras>=3.0.0` instead of `tf.keras`.
6+
* Removed the structured data related tasks by removing the following public
7+
APIs:
8+
* `CategoricalToNumerical`
9+
* `MultiCategoryEncoding`
10+
* `StructuredDataInput`
11+
* `StructuredDataBlock`
12+
* `StructuredDataClassifier`
13+
* `StructuredDataRegressor`
14+
* Removed the Time series related tasks by removing the following public APIs:
15+
* `TimeseriesInput`
16+
* `TimeseriesForecaster`
17+
* Reduced search space of Text related tasks by removing the following blocks.
18+
* `Embedding`
19+
* `TextToIntSequence`
20+
* `TextToNgramVector`
21+
* `Transformer`
22+
123
# Release v1.1.0
224

325
## Breaking changes

autokeras/__init__.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616

1717
from autokeras.auto_model import AutoModel
1818
from autokeras.blocks import BertBlock
19-
from autokeras.blocks import CategoricalToNumerical
2019
from autokeras.blocks import ClassificationHead
2120
from autokeras.blocks import ConvBlock
2221
from autokeras.blocks import DenseBlock
2322
from autokeras.blocks import EfficientNetBlock
24-
from autokeras.blocks import Embedding
2523
from autokeras.blocks import Flatten
2624
from autokeras.blocks import ImageAugmentation
2725
from autokeras.blocks import ImageBlock
@@ -31,49 +29,33 @@
3129
from autokeras.blocks import ResNetBlock
3230
from autokeras.blocks import RNNBlock
3331
from autokeras.blocks import SpatialReduction
34-
from autokeras.blocks import StructuredDataBlock
3532
from autokeras.blocks import TemporalReduction
3633
from autokeras.blocks import TextBlock
37-
from autokeras.blocks import TextToIntSequence
38-
from autokeras.blocks import TextToNgramVector
39-
from autokeras.blocks import Transformer
4034
from autokeras.blocks import XceptionBlock
4135
from autokeras.engine.block import Block
4236
from autokeras.engine.head import Head
4337
from autokeras.engine.node import Node
4438
from autokeras.keras_layers import CastToFloat32
4539
from autokeras.keras_layers import ExpandLastDim
46-
from autokeras.keras_layers import MultiCategoryEncoding
4740
from autokeras.nodes import ImageInput
4841
from autokeras.nodes import Input
49-
from autokeras.nodes import StructuredDataInput
5042
from autokeras.nodes import TextInput
51-
from autokeras.nodes import TimeseriesInput
5243
from autokeras.tasks import ImageClassifier
5344
from autokeras.tasks import ImageRegressor
54-
from autokeras.tasks import StructuredDataClassifier
55-
from autokeras.tasks import StructuredDataRegressor
5645
from autokeras.tasks import TextClassifier
5746
from autokeras.tasks import TextRegressor
58-
from autokeras.tasks import TimeseriesForecaster
5947
from autokeras.tuners import BayesianOptimization
6048
from autokeras.tuners import Greedy
6149
from autokeras.tuners import Hyperband
6250
from autokeras.tuners import RandomSearch
6351
from autokeras.utils.io_utils import image_dataset_from_directory
6452
from autokeras.utils.io_utils import text_dataset_from_directory
65-
from autokeras.utils.utils import check_kt_version
66-
from autokeras.utils.utils import check_tf_version
6753

68-
__version__ = "1.1.1dev"
69-
70-
check_tf_version()
71-
check_kt_version()
54+
__version__ = "2.0.0dev"
7255

7356
CUSTOM_OBJECTS = {
7457
"BertPreprocessor": keras_nlp.models.BertPreprocessor,
7558
"BertBackbone": keras_nlp.models.BertBackbone,
7659
"CastToFloat32": CastToFloat32,
7760
"ExpandLastDim": ExpandLastDim,
78-
"MultiCategoryEncoding": MultiCategoryEncoding,
7961
}

autokeras/adapters/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
from autokeras.adapters.input_adapters import ImageAdapter
1616
from autokeras.adapters.input_adapters import InputAdapter
17-
from autokeras.adapters.input_adapters import StructuredDataAdapter
1817
from autokeras.adapters.input_adapters import TextAdapter
19-
from autokeras.adapters.input_adapters import TimeseriesAdapter
2018
from autokeras.adapters.output_adapters import ClassificationAdapter
2119
from autokeras.adapters.output_adapters import RegressionAdapter
22-
from autokeras.adapters.output_adapters import SegmentationHeadAdapter

autokeras/adapters/input_adapters.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import numpy as np
16-
import pandas as pd
1716
import tensorflow as tf
1817

1918
from autokeras.engine import adapter as adapter_module
@@ -57,40 +56,3 @@ def check(self, x):
5756
"Expect the data to TextInput to be numpy.ndarray or "
5857
"tf.data.Dataset, but got {type}.".format(type=type(x))
5958
)
60-
61-
62-
class StructuredDataAdapter(adapter_module.Adapter):
63-
def check(self, x):
64-
if not isinstance(x, (pd.DataFrame, np.ndarray, tf.data.Dataset)):
65-
raise TypeError(
66-
"Unsupported type {type} for "
67-
"{name}.".format(type=type(x), name=self.__class__.__name__)
68-
)
69-
70-
def convert_to_dataset(self, dataset, batch_size):
71-
if isinstance(dataset, pd.DataFrame):
72-
dataset = dataset.values
73-
if isinstance(dataset, np.ndarray) and dataset.dtype == object:
74-
dataset = dataset.astype(str)
75-
return super().convert_to_dataset(dataset, batch_size)
76-
77-
78-
class TimeseriesAdapter(adapter_module.Adapter):
79-
def __init__(self, lookback=None, **kwargs):
80-
super().__init__(**kwargs)
81-
self.lookback = lookback
82-
83-
def check(self, x):
84-
"""Record any information needed by transform."""
85-
if not isinstance(x, (pd.DataFrame, np.ndarray, tf.data.Dataset)):
86-
raise TypeError(
87-
"Expect the data in TimeseriesInput to be numpy.ndarray"
88-
" or tf.data.Dataset or pd.DataFrame, but got {type}.".format(
89-
type=type(x)
90-
)
91-
)
92-
93-
def convert_to_dataset(self, dataset, batch_size):
94-
if isinstance(dataset, pd.DataFrame):
95-
dataset = dataset.values
96-
return super().convert_to_dataset(dataset, batch_size)

autokeras/adapters/input_adapters_test.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
import numpy as np
17-
import pandas as pd
1817
import pytest
1918
import tensorflow as tf
2019

@@ -23,25 +22,6 @@
2322
from autokeras.utils import data_utils
2423

2524

26-
def test_structured_data_input_unsupported_type_error():
27-
with pytest.raises(TypeError) as info:
28-
adapter = input_adapters.StructuredDataAdapter()
29-
adapter.adapt("unknown", batch_size=32)
30-
31-
assert "Unsupported type" in str(info.value)
32-
33-
34-
def test_structured_data_input_transform_to_dataset():
35-
x = tf.data.Dataset.from_tensor_slices(
36-
pd.read_csv(test_utils.TRAIN_CSV_PATH).to_numpy().astype(str)
37-
)
38-
adapter = input_adapters.StructuredDataAdapter()
39-
40-
x = adapter.adapt(x, batch_size=32)
41-
42-
assert isinstance(x, tf.data.Dataset)
43-
44-
4525
def test_image_input_adapter_transform_to_dataset():
4626
x = test_utils.generate_data()
4727
adapter = input_adapters.ImageAdapter()
@@ -115,19 +95,3 @@ def test_text_input_type_error():
11595
with pytest.raises(TypeError) as info:
11696
x = adapter.adapt(x, batch_size=32)
11797
assert "Expect the data to TextInput to be numpy" in str(info.value)
118-
119-
120-
def test_time_series_input_type_error():
121-
x = "unknown"
122-
adapter = input_adapters.TimeseriesAdapter()
123-
with pytest.raises(TypeError) as info:
124-
x = adapter.adapt(x, batch_size=32)
125-
assert "Expect the data in TimeseriesInput to be numpy" in str(info.value)
126-
127-
128-
def test_time_series_input_transform_df_to_dataset():
129-
adapter = input_adapters.TimeseriesAdapter()
130-
131-
x = adapter.adapt(pd.DataFrame(np.random.rand(100, 32)), batch_size=32)
132-
133-
assert isinstance(x, tf.data.Dataset)

autokeras/adapters/output_adapters.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import numpy as np
16-
import pandas as pd
1716
import tensorflow as tf
1817

1918
from autokeras.engine import adapter as adapter_module
@@ -25,19 +24,14 @@ def __init__(self, name, **kwargs):
2524
self.name = name
2625

2726
def check(self, dataset):
28-
supported_types = (tf.data.Dataset, np.ndarray, pd.DataFrame, pd.Series)
27+
supported_types = (tf.data.Dataset, np.ndarray)
2928
if not isinstance(dataset, supported_types):
3029
raise TypeError(
3130
f"Expect the target data of {self.name} to be tf.data.Dataset,"
32-
f" np.ndarray, pd.DataFrame or pd.Series, "
33-
f"but got {type(dataset)}."
31+
f" np.ndarray, but got {type(dataset)}."
3432
)
3533

3634
def convert_to_dataset(self, dataset, batch_size):
37-
if isinstance(dataset, pd.DataFrame):
38-
dataset = dataset.values
39-
if isinstance(dataset, pd.Series):
40-
dataset = dataset.values
4135
return super().convert_to_dataset(dataset, batch_size)
4236

4337

@@ -47,7 +41,3 @@ class ClassificationAdapter(HeadAdapter):
4741

4842
class RegressionAdapter(HeadAdapter):
4943
pass
50-
51-
52-
class SegmentationHeadAdapter(ClassificationAdapter):
53-
pass

autokeras/adapters/output_adapters_test.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,12 @@
1313
# limitations under the License.
1414

1515
import numpy as np
16-
import pandas as pd
1716
import pytest
1817
import tensorflow as tf
1918

20-
from autokeras import test_utils
2119
from autokeras.adapters import output_adapters
2220

2321

24-
def test_clf_head_transform_pd_series_to_dataset():
25-
adapter = output_adapters.ClassificationAdapter(name="a")
26-
27-
y = adapter.adapt(
28-
pd.read_csv(test_utils.TEST_CSV_PATH).pop("survived"), batch_size=32
29-
)
30-
31-
assert isinstance(y, tf.data.Dataset)
32-
33-
34-
def test_clf_head_transform_df_to_dataset():
35-
adapter = output_adapters.ClassificationAdapter(name="a")
36-
37-
y = adapter.adapt(
38-
pd.DataFrame(
39-
test_utils.generate_one_hot_labels(dtype="np", num_classes=10)
40-
),
41-
batch_size=32,
42-
)
43-
44-
assert isinstance(y, tf.data.Dataset)
45-
46-
4722
def test_unsupported_types_error():
4823
adapter = output_adapters.ClassificationAdapter(name="a")
4924

@@ -53,16 +28,6 @@ def test_unsupported_types_error():
5328
assert "Expect the target data of a to be tf" in str(info.value)
5429

5530

56-
def test_reg_head_transform_pd_series():
57-
adapter = output_adapters.RegressionAdapter(name="a")
58-
59-
y = adapter.adapt(
60-
pd.read_csv(test_utils.TEST_CSV_PATH).pop("survived"), batch_size=32
61-
)
62-
63-
assert isinstance(y, tf.data.Dataset)
64-
65-
6631
def test_reg_head_transform_1d_np():
6732
adapter = output_adapters.RegressionAdapter(name="a")
6833

autokeras/analysers/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from autokeras.analysers.input_analysers import CATEGORICAL
16-
from autokeras.analysers.input_analysers import NUMERICAL
1715
from autokeras.analysers.input_analysers import ImageAnalyser
1816
from autokeras.analysers.input_analysers import InputAnalyser
19-
from autokeras.analysers.input_analysers import StructuredDataAnalyser
2017
from autokeras.analysers.input_analysers import TextAnalyser
21-
from autokeras.analysers.input_analysers import TimeseriesAnalyser
2218
from autokeras.analysers.output_analysers import ClassificationAnalyser
2319
from autokeras.analysers.output_analysers import RegressionAnalyser

0 commit comments

Comments
 (0)