tensorflow - Tensorflow 集线器错误 - “URLError:"
问题描述
所以我正在参加 Kaggle 的Object Detection比赛,我使用的是 TensorFlow Hub 的模型。
这是一个模型-faster_rcnn/openimages_v4/inception_resnet_v2
模型 URL - https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1
所以我在 Kaggle 的笔记本中尝试以下代码:
module_handle = "https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1"
with tf.device('/device:GPU:0'):
with tf.Graph().as_default():
detector = hub.Module("https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1")
image_string_placeholder = tf.placeholder(tf.string)
decoded_image = tf.image.decode_jpeg(image_string_placeholder)
decoded_image_float = tf.image.convert_image_dtype(image=decode_image,
dtype=tf.float32)
module_input = tf.expand_dims(decoded_image_float, axis=0) # this operation inserts a dimension of 1 at the dimension index 'axis' of 'input's' shape
result = detector(module_input, as_dict=True)
init_ops = [tf.global_variables_initializer(), tf.tables_initializer()]
session = tf.Session()
session.run(init_ops)
我收到以下错误:
---------------------------------------------------------------------------
gaierror Traceback (most recent call last)
/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1318 h.request(req.get_method(), req.selector, req.data, headers,
-> 1319 encode_chunked=req.has_header('Transfer-encoding'))
1320 except OSError as err: # timeout error
/opt/conda/lib/python3.7/http/client.py in request(self, method, url, body, headers, encode_chunked)
1251 """Send a complete request to the server."""
-> 1252 self._send_request(method, url, body, headers, encode_chunked)
1253
/opt/conda/lib/python3.7/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
1297 body = _encode(body, 'body')
-> 1298 self.endheaders(body, encode_chunked=encode_chunked)
1299
/opt/conda/lib/python3.7/http/client.py in endheaders(self, message_body, encode_chunked)
1246 raise CannotSendHeader()
-> 1247 self._send_output(message_body, encode_chunked=encode_chunked)
1248
/opt/conda/lib/python3.7/http/client.py in _send_output(self, message_body, encode_chunked)
1025 del self._buffer[:]
-> 1026 self.send(msg)
1027
/opt/conda/lib/python3.7/http/client.py in send(self, data)
965 if self.auto_open:
--> 966 self.connect()
967 else:
/opt/conda/lib/python3.7/http/client.py in connect(self)
1413
-> 1414 super().connect()
1415
/opt/conda/lib/python3.7/http/client.py in connect(self)
937 self.sock = self._create_connection(
--> 938 (self.host,self.port), self.timeout, self.source_address)
939 self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
/opt/conda/lib/python3.7/socket.py in create_connection(address, timeout, source_address)
706 err = None
--> 707 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
708 af, socktype, proto, canonname, sa = res
/opt/conda/lib/python3.7/socket.py in getaddrinfo(host, port, family, type, proto, flags)
751 addrlist = []
--> 752 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
753 af, socktype, proto, canonname, sa = res
gaierror: [Errno -3] Temporary failure in name resolution
During handling of the above exception, another exception occurred:
URLError Traceback (most recent call last)
<ipython-input-10-5a767207aaa7> in <module>
2 with tf.device('/device:GPU:0'):
3 with tf.Graph().as_default():
----> 4 detector = hub.Module("https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1")
5 image_string_placeholder = tf.placeholder(tf.string)
6 decoded_image = tf.image.decode_jpeg(image_string_placeholder)
/opt/conda/lib/python3.7/site-packages/tensorflow_hub/module.py in __init__(self, spec, trainable, name, tags)
152 """
153 self._graph = tf_v1.get_default_graph()
--> 154 self._spec = as_module_spec(spec)
155 self._trainable = trainable
156
/opt/conda/lib/python3.7/site-packages/tensorflow_hub/module.py in as_module_spec(spec)
34 return spec
35 elif isinstance(spec, six.string_types):
---> 36 return load_module_spec(spec)
37 else:
38 raise ValueError("Unknown module spec type: %r" % type(spec))
/opt/conda/lib/python3.7/site-packages/tensorflow_hub/module.py in load_module_spec(path)
61 tf.errors.OpError: on file handling exceptions.
62 """
---> 63 path = registry.resolver(path)
64 return registry.loader(path)
65
/opt/conda/lib/python3.7/site-packages/tensorflow_hub/registry.py in __call__(self, *args, **kwargs)
40 for impl in reversed(self._impls):
41 if impl.is_supported(*args, **kwargs):
---> 42 return impl(*args, **kwargs)
43 raise RuntimeError(
44 "Missing implementation that supports: %s(*%r, **%r)" % (
/opt/conda/lib/python3.7/site-packages/tensorflow_hub/compressed_module_resolver.py in __call__(self, handle)
86
87 return resolver.atomic_download(handle, download, module_dir,
---> 88 self._lock_file_timeout_sec())
89
90 def _lock_file_timeout_sec(self):
/opt/conda/lib/python3.7/site-packages/tensorflow_hub/resolver.py in atomic_download(handle, download_fn, module_dir, lock_file_timeout_sec)
413 logging.info("Downloading TF-Hub Module '%s'.", handle)
414 tf_v1.gfile.MakeDirs(tmp_dir)
--> 415 download_fn(handle, tmp_dir)
416 # Write module descriptor to capture information about which module was
417 # downloaded by whom and when. The file stored at the same level as a
/opt/conda/lib/python3.7/site-packages/tensorflow_hub/compressed_module_resolver.py in download(handle, tmp_dir)
81 """Fetch a module via HTTP(S), handling redirect and download headers."""
82 request = url.Request(_append_compressed_format_query(handle))
---> 83 response = self._call_urlopen(request)
84 return resolver.DownloadManager(handle).download_and_uncompress(
85 response, tmp_dir)
/opt/conda/lib/python3.7/site-packages/tensorflow_hub/compressed_module_resolver.py in _call_urlopen(self, request)
94 def _call_urlopen(self, request):
95 # Overriding this method allows setting SSL context in Python 3.
---> 96 return url.urlopen(request)
97
98
/opt/conda/lib/python3.7/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
224 def install_opener(opener):
/opt/conda/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout)
523 req = meth(req)
524
--> 525 response = self._open(req, data)
526
527 # post-process response
/opt/conda/lib/python3.7/urllib/request.py in _open(self, req, data)
541 protocol = req.type
542 result = self._call_chain(self.handle_open, protocol, protocol +
--> 543 '_open', req)
544 if result:
545 return result
/opt/conda/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
501 for handler in handlers:
502 func = getattr(handler, meth_name)
--> 503 result = func(*args)
504 if result is not None:
505 return result
/opt/conda/lib/python3.7/urllib/request.py in https_open(self, req)
1360 def https_open(self, req):
1361 return self.do_open(http.client.HTTPSConnection, req,
-> 1362 context=self._context, check_hostname=self._check_hostname)
1363
1364 https_request = AbstractHTTPHandler.do_request_
/opt/conda/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1319 encode_chunked=req.has_header('Transfer-encoding'))
1320 except OSError as err: # timeout error
-> 1321 raise URLError(err)
1322 r = h.getresponse()
1323 except:
URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
请注意:我收到此错误,仅在 Kaggle 内(在 Kaggle 内运行笔记本)。我试图在 Google Colab 上运行它并且工作得很好。
解决方案
推荐阅读
- typescript - 记录之间的区别
和 [key: string]: 类型 - rust - 如何创建所有子命令都是可选的 StructOpt 命令
- ibm-mq - 命令 mqreply.c 超时
- vue.js - Chrome 调试器在断点处跳转到错误的文件
- mongodb - mongo 4.4 中是否存在 mongorestore.exe 文件?
- python - 从 Pandas 中的括号中提取
- r - 如何辨别哪些变量取决于分组变量?
- php - 如果在laravel中满足条件,如何跳过数据行
- assembly - nasm "尝试在 bss 部分初始化内存"
- sql - 无法组合 GROUP BY、ORDER BY 和 UNION