Hub: tf_hub from behind proxy?

Created on 6 Sep 2018  路  4Comments  路  Source: tensorflow/hub

Hiya - what do i need to do to make the tf hub download imagenet etc files it wants from behind a proxy server?

cheers

Most helpful comment

You can handle proxy this way from your code (e.g. you do not need to edit compressed_module_resolver.py) in python(3.6):

import tensorflow_hub as hub
import os
import getpass

module_url = "https://tfhub.dev/google/universal-sentence-encoder/2"
print("Loading model from {}".format(module_url))
user = getpass.getuser()
password = getpass.getpass("proxy password:")
os.environ["https_proxy"] = f"http://{user}:{password}@10.204.10.2:3128"
embed = hub.Module(module_url)

All 4 comments

TF-Hub uses "urllib" to download modules. It appears you can configure it via http_proxy environment variable.

hmm doesnt seem to want to work the https required

so found a workaround - that works for me.
editted
def download(handle, tmp_dir) in compressed_module_resolver.py

proxy_support = url.ProxyHandler({'http' : 'http://username:password@proxyip:port',
'https': 'https://username:password@proxyip:port'})

..
then later in the function
url_opener = url.build_opener(LoggingHTTPRedirectHandler,proxy_support )

and its working for me...yeah its hard coded and hardcoded == bad....but that'll do for me now

cheers

You can handle proxy this way from your code (e.g. you do not need to edit compressed_module_resolver.py) in python(3.6):

import tensorflow_hub as hub
import os
import getpass

module_url = "https://tfhub.dev/google/universal-sentence-encoder/2"
print("Loading model from {}".format(module_url))
user = getpass.getuser()
password = getpass.getpass("proxy password:")
os.environ["https_proxy"] = f"http://{user}:{password}@10.204.10.2:3128"
embed = hub.Module(module_url)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bhack picture bhack  路  3Comments

truas picture truas  路  5Comments

r-wheeler picture r-wheeler  路  4Comments

lugq1990 picture lugq1990  路  4Comments

AlfredAM picture AlfredAM  路  4Comments