python - 在 Google Colab 上运行 autokeras 图像分类器教程时出错

标签 python keras google-colaboratory auto-keras

autokeras教程在这里https://colab.research.google.com/github/keras-team/autokeras/blob/master/docs/templates/tutorial/image_classification.ipynb

线路失败:

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)

有错误:

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'

这是代码或 Google Colab 设置中的错误吗?

最佳答案

问题不在于代码,我自己在本地机器上尝试过,它运行得很好。真正的问题是这一行

pip install tensorflow

这一行让pip完全负责选择要安装的tensorflow版本,遗憾的是它选择安装rc版本tensorflow-2.2.0rc1,它看起来有问题与autokeras

因此,要完成这项工作,您所要做的就是将版本修复为已知可与 autokeras 配合使用的最新稳定 tensorflow 版本

pip install tensorflow==2.1.0

关于python - 在 Google Colab 上运行 autokeras 图像分类器教程时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60921372/

相关文章:

google-cloud-platform - 使用 Colaboratory 永久允许 Google Cloud SDK 访问您的 Google 帐户

python - 如何将元组列表转换为字符串?

python - 是否有任何方法可以调整整个图的大小以及 matplotlib 或 seaborn 中的字体大小和线宽?

python - "a:1"不应该是 python 中的语法错误吗?

python - TensorFlow Keras 自定义回调 on_test_begin 不会覆盖自身

python - keras 中的 categorical_crossentropy 是如何实现的?

python - Keras,我训练模型后如何预测?

python - 您可以在本地计算机上运行 Google Colab 吗?

python - 警告 :tensorflow:Compiled the loaded model, 但尚未构建已编译指标

google-colaboratory - 可以在 Google Colab 上使用 OpenSlide 吗?