ValueError: Input 0 of layer dense is incompatible with the layer: its rank is undefined, but the layer requires a defined rank

ValueError: Input 0 of layer dense is incompatible with the layer: its rank is undefined, but the layer requires a defined rank

当使用 tf '2.0.0-alpha0' 在本地计算机上尝试 https://www.tensorflow.org/tutorials/images/hub_with_keras 的示例时(下载,pip-下载 hub '0.4.0-dev' 并删除 !pip... 行,安装 tf 2,删除 enable_v2_behavior , 运行 file), 它失败了

ValueError: Input 0 of layer dense is incompatible with the layer: its rank is undefined, but the layer requires a defined rank.

不过 运行 在 Google colab 上没问题。为什么会这样,如何解决?

正如@arnoegw 在评论中提出的那样,这已在 tf-nightly-2.0-preview 中修复。所以在它投入生产之前,只需使用

pip install tf-nightly-2.0-preview