Skip to content

Instantly share code, notes, and snippets.

@lehoang318
Last active April 7, 2025 16:04
Tensorflow

Trouble Shooting

Common

  • pip 22.x issue

  • Compatibility

  • export PYTHONPATH=$PYTHONPATH:/path/to/tensorflow-models

  • tf_keras -> tf.keras

  • exp_config.runtime.num_gpus = 1

  • To avoid GCS warnings/errors

    • tensorflow_datasets.core.utils.gcs_utils._is_gcs_disabled = True
    • os.environ['NO_GCE_CHECK'] = 'true'
  • object_detection/builders/model_builder_tf2_test.py + protobuf + runtime_version issue

    • Step 1: pip install --upgrade protobuf
    • Step 2: save <venv>/lib/python3.10/site-packages/google/protobuf/runtime_version.py somewhere else
    • Step 3: pip install protobuf==3.20.3
    • Step 4: restore runtime_version.py

Windows Native

  • Environment

    • OS: Wins 11 x64
      • Shell: PowerShell (PSVersion: 5.1.26100.2161)
    • Python 3.10.9 (venv)
      • Pip 25.0.1
  • tensorflow/models

  • Command: pip install .

    • setup.py: add 'PyYAML==5.3.1' to REQUIRED_PACKAGES

WSL2

pip install setuptools-scm wheel

Troubleshooting

mobilenet_v2 ="https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4"

classifier_model = mobilenet_v2 #@param ["mobilenet_v2", "inception_v3"] {type:"raw"}
IMAGE_SHAPE = (224, 224)

hub_layer = hub.KerasLayer(classifier_model, input_shape=IMAGE_SHAPE+(3,))
hub_layer_wrapper = tf.keras.layers.Lambda(lambda x: hub_layer(x))
classifier = tf.keras.Sequential([
    hub_layer_wrapper
])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment