Skip to content

Commit ec4ebd1

Browse files
authored
Fix the tests (#1894)
* make tests faster * skip tests that always fail on tf-nightly * fix tests * fix tests * remove nightly tests * remove nightly
1 parent 04525a5 commit ec4ebd1

File tree

3 files changed

+48
-58
lines changed

3 files changed

+48
-58
lines changed

.github/workflows/nightly.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.

autokeras/integration_tests/task_api_test.py

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,50 @@
2020
import autokeras as ak
2121
from autokeras import test_utils
2222

23+
NUM_INSTANCES = 3
24+
BATCH_SIZE = 2
25+
2326

2427
def test_image_classifier(tmp_path):
25-
train_x = test_utils.generate_data(num_instances=320, shape=(32, 32))
28+
train_x = test_utils.generate_data(
29+
num_instances=NUM_INSTANCES, shape=(32, 32)
30+
)
2631
train_y = test_utils.generate_one_hot_labels(
27-
num_instances=320, num_classes=10
32+
num_instances=NUM_INSTANCES, num_classes=10
2833
)
2934
clf = ak.ImageClassifier(
3035
directory=tmp_path,
3136
max_trials=2,
3237
seed=test_utils.SEED,
3338
distribution_strategy=tf.distribute.MirroredStrategy(),
3439
)
35-
clf.fit(train_x, train_y, epochs=1, validation_split=0.2)
40+
clf.fit(
41+
train_x, train_y, epochs=1, validation_split=0.2, batch_size=BATCH_SIZE
42+
)
3643
keras_model = clf.export_model()
3744
clf.evaluate(train_x, train_y)
3845
assert clf.predict(train_x).shape == (len(train_x), 10)
3946
assert isinstance(keras_model, keras.Model)
4047

4148

4249
def test_image_regressor(tmp_path):
43-
train_x = test_utils.generate_data(num_instances=320, shape=(32, 32, 3))
44-
train_y = test_utils.generate_data(num_instances=320, shape=(1,))
50+
train_x = test_utils.generate_data(
51+
num_instances=NUM_INSTANCES, shape=(32, 32, 3)
52+
)
53+
train_y = test_utils.generate_data(num_instances=NUM_INSTANCES, shape=(1,))
4554
clf = ak.ImageRegressor(
4655
directory=tmp_path, max_trials=2, seed=test_utils.SEED
4756
)
48-
clf.fit(train_x, train_y, epochs=1, validation_split=0.2)
57+
clf.fit(
58+
train_x, train_y, epochs=1, validation_split=0.2, batch_size=BATCH_SIZE
59+
)
4960
clf.export_model()
5061
assert clf.predict(train_x).shape == (len(train_x), 1)
5162

5263

5364
def test_text_classifier(tmp_path):
54-
train_x = test_utils.generate_text_data(num_instances=320)
55-
train_y = np.random.randint(0, 2, 320)
65+
train_x = test_utils.generate_text_data(num_instances=NUM_INSTANCES)
66+
train_y = np.array([0, 1] * ((NUM_INSTANCES + 1) // 2))[:NUM_INSTANCES]
5667
test_x = train_x
5768
test_y = train_y
5869
clf = ak.TextClassifier(
@@ -67,29 +78,35 @@ def test_text_classifier(tmp_path):
6778
train_y,
6879
epochs=2,
6980
validation_data=(test_x, test_y),
70-
batch_size=6,
81+
batch_size=BATCH_SIZE,
7182
)
7283
clf.export_model()
7384
assert clf.predict(test_x).shape == (len(test_x), 1)
7485
assert clf.tuner._get_best_trial_epochs() <= 2
7586

7687

7788
def test_text_regressor(tmp_path):
78-
train_x = test_utils.generate_text_data(num_instances=300)
89+
train_x = test_utils.generate_text_data(num_instances=NUM_INSTANCES)
7990
test_x = train_x
80-
train_y = test_utils.generate_data(num_instances=300, shape=(1,))
91+
train_y = test_utils.generate_data(num_instances=NUM_INSTANCES, shape=(1,))
8192
test_y = train_y
8293
clf = ak.TextRegressor(
8394
directory=tmp_path, max_trials=2, seed=test_utils.SEED
8495
)
85-
clf.fit(train_x, train_y, epochs=1, validation_data=(test_x, test_y))
96+
clf.fit(
97+
train_x,
98+
train_y,
99+
epochs=1,
100+
validation_data=(test_x, test_y),
101+
batch_size=BATCH_SIZE,
102+
)
86103
clf.export_model()
87104
assert clf.predict(test_x).shape == (len(test_x), 1)
88105

89106

90107
def test_structured_data_regressor(tmp_path):
91-
num_data = 500
92-
num_train = 400
108+
num_data = NUM_INSTANCES * 2
109+
num_train = NUM_INSTANCES
93110
data = (
94111
pd.read_csv(test_utils.TRAIN_CSV_PATH).to_numpy().astype(str)[:num_data]
95112
)
@@ -99,14 +116,20 @@ def test_structured_data_regressor(tmp_path):
99116
clf = ak.StructuredDataRegressor(
100117
directory=tmp_path, max_trials=2, seed=test_utils.SEED
101118
)
102-
clf.fit(x_train, y_train, epochs=11, validation_data=(x_train, y_train))
119+
clf.fit(
120+
x_train,
121+
y_train,
122+
epochs=11,
123+
validation_data=(x_train, y_train),
124+
batch_size=BATCH_SIZE,
125+
)
103126
clf.export_model()
104127
assert clf.predict(x_test).shape == (len(y_test), 1)
105128

106129

107130
def test_structured_data_classifier(tmp_path):
108-
num_data = 500
109-
num_train = 400
131+
num_data = NUM_INSTANCES * 2
132+
num_train = NUM_INSTANCES
110133
data = (
111134
pd.read_csv(test_utils.TRAIN_CSV_PATH).to_numpy().astype(str)[:num_data]
112135
)
@@ -118,7 +141,13 @@ def test_structured_data_classifier(tmp_path):
118141
clf = ak.StructuredDataClassifier(
119142
directory=tmp_path, max_trials=1, seed=test_utils.SEED
120143
)
121-
clf.fit(x_train, y_train, epochs=2, validation_data=(x_train, y_train))
144+
clf.fit(
145+
x_train,
146+
y_train,
147+
epochs=2,
148+
validation_data=(x_train, y_train),
149+
batch_size=BATCH_SIZE,
150+
)
122151
clf.export_model()
123152
assert clf.predict(x_test).shape == (len(y_test), 3)
124153

autokeras/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def generate_data(num_instances=100, shape=(32, 32, 3), dtype="np"):
6969
def generate_one_hot_labels(num_instances=100, num_classes=10, dtype="np"):
7070
np.random.seed(SEED)
7171
labels = np.random.randint(num_classes, size=num_instances)
72-
data = keras.utils.to_categorical(labels)
72+
data = keras.utils.to_categorical(labels, num_classes=num_classes)
7373
if dtype == "np":
7474
return data
7575
if dtype == "dataset":

0 commit comments

Comments
 (0)