cannin
cannin

Reputation: 3285

Error Running autokeras Image Classifier Tutorial on Google Colab

The autokeras tutorial here https://colab.research.google.com/github/keras-team/autokeras/blob/master/docs/templates/tutorial/image_classification.ipynb

fails on the line:

import autokeras as ak

# Initialize the image classifier.
clf = ak.ImageClassifier(max_trials=10) # It tries 10 different models.
# Feed the image classifier with training data.
clf.fit(x_train, y_train,epochs=3)

with error:

AttributeError: in user code:

    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:503 train_function  *
        outputs = self.distribute_strategy.run(
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:951 run  **
        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2290 call_for_each_replica
        return self._call_for_each_replica(fn, args, kwargs)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2649 _call_for_each_replica
        return fn(*args, **kwargs)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:475 train_step  **
        self.compiled_metrics.update_state(y, y_pred, sample_weight)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:386 update_state
        self._build(y_pred, y_true)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:317 _build
        self._metrics, y_true, y_pred)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py:1118 map_structure_up_to
        **kwargs)
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py:1214 map_structure_with_tuple_paths_up_to
        *flat_value_lists)]
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py:1213 <listcomp>
        results = [func(*args, **kwargs) for args in zip(flat_path_list,
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/util/nest.py:1116 <lambda>
        lambda _, *values: func(*values),  # Discards the path arg.
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:416 _get_metric_objects
        return [self._get_metric_object(m, y_t, y_p) for m in metrics]
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:416 <listcomp>
        return [self._get_metric_object(m, y_t, y_p) for m in metrics]
    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/compile_utils.py:437 _get_metric_object
        y_t_rank = len(y_t.shape.as_list())

    AttributeError: 'tuple' object has no attribute 'shape'

Is this an error in the code or in the Google Colab setup?

Upvotes: 2

Views: 1111

Answers (4)

Walid Ahmed
Walid Ahmed

Reputation: 71

I have TF 2.1.0 and still have the same error. code running on my machine but not on google colab

Upvotes: 0

Amsci Fi
Amsci Fi

Reputation: 33

Neither pip install tensorflow==2.1.0 nor %tensorflow_version 2.x helped me. I am still getting the same error.

You would need exact 2.1 version as mentioned in the accepted answer above to get rid of the error.

I am using Google Colab

Upvotes: 1

korakot
korakot

Reputation: 40818

You also don't need to install TensorFlow 2.1 again.

You can select it simply by calling:

%tensorflow_version 2.x

Upvotes: 0

kareem_emad
kareem_emad

Reputation: 1183

The problem is not with the code, I tried it myself on my local machine and it works perfectly. The real problem is this line

pip install tensorflow

This line gives pip full responsibility for choosing tensorflow version to install, sadly it chose to install the rc version tensorflow-2.2.0rc1 which looks like it has a problem with autokeras.

So all you have to do to make this work is to fix the version to the latest stable tensorflow verison that is known to work with autokeras

pip install tensorflow==2.1.0

Upvotes: 1

Related Questions