【问题标题】:How to use Tensorflow Hub Model?如何使用 TensorFlow Hub 模型?
【发布时间】:2021-08-14 00:08:38
【问题描述】:

目标使用来自 TensorFlow 的预训练模型example project,更具体地说是Tensorflow hub

1.

  • 为此,我尝试使用以下命令安装tensorflow_hubconda install -c conda-forge tensorflow-hub
  • conda list 输出:.... tensorflow-hub 0.12.0 pyhca92ed8_0 conda-forge ....
  • 到 sagemenaker EC2 实例的 anaconda 环境。
  • 整个安装过程运行顺利,没有任何错误,但是当我尝试导入包时,它就像没有安装一样import tensorflow_hub as hub
  • 错误
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-14-5c017171c13e> in <module>
----> 1 import tensorflow_hub as hub

ModuleNotFoundError: No module named 'tensorflow_hub'
  • 我已经手动下载了模型并上传到了ec2,但是不知道怎么加载和使用
  1. 使用 pip 添加 tensorflow_hub https://stackoverflow.com/a/43729857/10270590
1. Run `conda create -n venv_name` and `source activate venv_name`, where `venv_name` is the name of your virtual environment. 

2. Run `conda install pip`. This will install pip to your venv directory. 

3. Find your anaconda directory, and find the actual venv folder. It should be somewhere like `/anaconda/envs/venv_name/`. 

4. Install new packages by doing `/anaconda/envs/venv_name/bin/pip install package_name`. 

输出

(tf2p37) ubuntu@ip:~/anaconda3/envs/tf2p37/bin$ pip install --upgrade tensorflow-hub
Requirement already satisfied: tensorflow-hub in /home/ubuntu/anaconda3/envs/tf2p37/lib/python3.7/site-packages (0.12.0)
Requirement already satisfied: protobuf>=3.8.0 in /home/ubuntu/anaconda3/envs/tf2p37/lib/python3.7/site-packages (from tensorflow-hub) (3.15.2)
Requirement already satisfied: numpy>=1.12.0 in /home/ubuntu/anaconda3/envs/tf2p37/lib/python3.7/site-packages (from tensorflow-hub) (1.19.5)
Requirement already satisfied: six>=1.9 in /home/ubuntu/anaconda3/envs/tf2p37/lib/python3.7/site-packages (from protobuf>=3.8.0->tensorflow-hub) (1.15.0)
  • 它就在那里,但是当我执行时它仍然不想被导入:import tensorflow_hub as hub

【问题讨论】:

  • 1) 请使用以下命令在 sagemaker(新创建的内核)中打开新笔记本后,尝试在新的 anaconda 虚拟环境中安装(然后导入)最新版本的 tensorflow2.x 和 tensorflow-hub :- a)!pip install --upgrade tensorflow b)!pip install --upgrade tensorflow_hub c)import tensorflow as tf d)import tensorflow_hub as hub 2)通过hub加载模型,请使用: hub_model = hub.load( 'tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/…)

标签: python tensorflow anaconda tensorflow2.0 tensorflow-hub


【解决方案1】:
  • 我刚刚从 Jupiter notebook 安装了
  • pip install --upgrade tensorflow_hub
  • 这并没有以某种方式覆盖所有其他文件。
  • 基础环境是 SageMaker conda_tensorflow2_p36
  • 您可以将其激活为conda activate tensorflow2_p36

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-07
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 2019-11-15
    • 2021-09-10
    • 2019-12-28
    • 1970-01-01
    相关资源
    最近更新 更多