tensorflow / hub

A library for transfer learning by reusing parts of TensorFlow models.
https://tensorflow.org/hub
Apache License 2.0
3.48k stars 1.66k forks source link

How to use Tensorflow Hub Model? #767

Closed stromal closed 3 years ago

stromal commented 3 years ago

GOAL to use a pre trained model from a TensorFlow example project more specifically Tensorflow hub

1.

ModuleNotFoundError: No module named 'tensorflow_hub'

- after many error it is installed with ```conda install -c conda-forge tensorflow-hub```
- but downgraded tf to 1.4 and it don't want to allow me to upgrade it to tf +2

2.

- I have manually downloaded the model and uploaded to the ec2 but I don't know how to load it in and use it

3. Adding with 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.

OUTPUT

(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)
arghyaganguly commented 3 years ago

@stromal ,

1)Could you please try installing(then importing) the latest versions of tensorflow2.x and tensorflow-hub in a fresh anaconda virtual environment after opening a new notebook in sagemaker(newly created kernel) using the commands below:-

a)!pip install --upgrade tensorflow
b)!pip install --upgrade tensorflow_hub
c)import tensorflow as tf
d)import tensorflow_hub as hub

2)for loading the model through hub, please use:


hub_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2') 
WGierke commented 3 years ago

Closing this since it appears like the author asked the same question on SO and accepted an answer there.