Description
Describe the bug
I am experiencing the following error message while trying to run the example file autokeras.examples.automodel_with_cnn.py
:
2024-11-20 20:24:34.105906: W tensorflow/core/framework/local_rendezvous.cc:404] Local rendezvous is aborting with status: OUT_OF_RANGE: End of sequence
> /home/humbulani/tensorflow/env/lib/python3.12/site-packages/autokeras/auto_model.py(391)_analyze_data()
-> for analyser in analysers:
(Pdb) c
Traceback (most recent call last):
File "/home/humbulani/tensorflow/examples_auto/automodel_with_cnn.py", line 39, in <module>
auto_model.fit(x_train, y_train, epochs=1)
File "/home/humbulani/tensorflow/env/lib/python3.12/site-packages/autokeras/auto_model.py", line 296, in fit
self._analyze_data(dataset)
File "/home/humbulani/tensorflow/env/lib/python3.12/site-packages/autokeras/auto_model.py", line 392, in _analyze_data
analyser.finalize()
File "/home/humbulani/tensorflow/env/lib/python3.12/site-packages/autokeras/analysers/output_analysers.py", line 80, in finalize
raise ValueError(
ValueError: Expect the target data for classification_head_1 to have shape [2], but got [].
Attempted fixes
I read the file automodel_with_cnn.py
and I couldn't find any errors, AutoKeras API
usage seems to ok together with functions and classes signatures - so, I don't think the error is on API usage.
I decided to read AutoKeras
source code to trace the error with pdb
. The error is from the following code snippet from the function ClassificationAnalyser.finalize
:
...
# 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:]
)
)
The above code snippet calls the function 'get_expected_shape' reproduced below:
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]
The 'actual
local variable is not equal to the expected
local variable, so it raises a ValueError
exception. I Then decided to force them to be equal by removing not
keyword from the line: if self.num_classes == 2 and not self.multi_label:
. And it worked. I don't know yet implications of this on the whole codebase but I hope I proper fix can be found.
One implication of the above fix is that we have to include the keyword argument multi_label=True
in the instantiation of the classifier: clf = ak.TextClassifier(max_trials=3, multi_label=True)
from the example file imdb.py
.
Note There are other small issues like numpy
dtypes deprecation where we dtypes like str
has changed to str_
from example file like imdb.py
. I suspect this is probably due to numpy
versions.
Tests
I ran only the tests from the analysers
directory with no errors.
Environment
python == 3.12
autokeras == 2.0.0
keras == 3.6.0
tensorflow == 2.16.2
To reproduce
Please run the example
files from the autokeras/examples
directory.