【问题标题】:Colab ImportError: cannot import name 'squeeze_or_expand_dimensions'Colab ImportError:无法导入名称“squeeze_or_expand_dimensions”
【发布时间】:2020-06-03 09:21:10
【问题描述】:

按照Transfer Learning with TensorFlow Hub for TFLite教程,第一步是

!pip install -q -U "tensorflow-gpu=2.0.0b1"

设置:

import os

import matplotlib.pylab as plt
import numpy as np

import tensorflow as tf
import tensorflow_hub as hub

print("Version: ", tf.__version__)
print("Eager mode: ", tf.executing_eagerly())
print("Hub version: ", hub.__version__)
print("GPU is", "available" if tf.test.is_gpu_available() else "NOT AVAILABLE")

出现错误:ImportError: cannot import name 'export_saved_model' 我试过之后

%tensorflow_version 2.x
!pip uninstall -y tensorflow
!pip install tensorflow-gpu==1.14.0

根据this answer,引发了另一个错误: ImportError:无法导入名称“squeeze_or_expand_dimensions”

另外,我尝试了!pip install --upgrade tensorflow,并引发了另一个错误...ImportError: cannot import name 'collections_abc' 我被困在这里了……

【问题讨论】:

  • @Jeff Snyder 我的声誉无法评论你的答案,你能帮我吗

标签: tensorflow google-colaboratory


【解决方案1】:

不要运行!pip install -q -U "tensorflow-gpu==2.0.0b1"

在“运行时”菜单下“更改运行时类型”为“GPU”和“恢复出厂设置运行时”。

import os

import matplotlib.pylab as plt
import numpy as np

import tensorflow as tf
import tensorflow_hub as hub

print("Version: ", tf.__version__)
print("Eager mode: ", tf.executing_eagerly())
print("Hub version: ", hub.__version__)
print("GPU is", "available" if tf.test.is_gpu_available() else "NOT AVAILABLE")

输出:

Version:  2.2.0
Eager mode:  True
Hub version:  0.8.0
GPU is available

【讨论】:

  • 成功了! !谢谢很多只是不知道为什么教程(来自udacity)运行?
  • 很高兴能帮上忙。
猜你喜欢
  • 1970-01-01
  • 2021-05-24
  • 2021-07-13
  • 1970-01-01
  • 1970-01-01
  • 2019-10-24
  • 2016-03-31
  • 2014-10-10
  • 2014-09-20
相关资源
最近更新 更多