Search code examples
pythontensorflowgoogle-colaboratorytensorflow-hub

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


When trying the example at https://www.tensorflow.org/tutorials/images/hub_with_keras at a local computer with tf '2.0.0-alpha0' (download, pip-download hub '0.4.0-dev' and remove !pip... lines, install tf 2, remove enable_v2_behavior , run file), it failed with

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

It runs fine on Google colab though. Why is this and how can it be fixed?


Solution

  • As proposed by @arnoegw in the comments, this is fixed in tf-nightly-2.0-preview. So until it lands in production, just use

    pip install tf-nightly-2.0-preview