目标使用 TensorFlow 示例项目中的预训练模型,更具体地说是Tensorflow hub
1.
tensorflow_hub
:conda install -c conda-forge tensorflow-hub
conda list
输出:....tensorflow-hub 0.12.0 pyhca92ed8_0 conda-forge ....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'
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
pip install --upgrade tensorflow_hub
conda_tensorflow2_p36
conda activate tensorflow2_p36
第一个解决方案:
您可以尝试将tensorflow_hub直接安装到Jupyter Notebook使用的Python环境中。
!pip install --upgrade tensorflow_hub
或者您可以使用以下代码将其安装在您的环境中:
pip install --upgrade tensorflow_hub
第二种解决方案:
如果这也不起作用(这通常发生在您在 Jupyter 笔记本中工作时),则运行以下代码:
import sys
!{sys.executable} -m pip install tensorflow_hub
这会将tensorflow_hub直接安装到Jupyter Notebook使用的Python环境中。