Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors while running example files #1938

Open
Humbulani1234 opened this issue Nov 21, 2024 · 0 comments
Open

Errors while running example files #1938

Humbulani1234 opened this issue Nov 21, 2024 · 0 comments

Comments

@Humbulani1234
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant