在 kaggle 上导入预训练的 vgg 模型时出现 Gaierror
Gaierror while importing pretrained vgg model on kaggle
initial_model = VGG19(weights='imagenet', pooling = max)
我正在尝试在 kaggle 的 keras 中导入预训练的 VGG 模型。我 运行 通过一个不熟悉的 gaierror
Downloading data from
https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5
--------------------------------------------------------------------------- gaierror Traceback (most recent call
last) /opt/conda/lib/python3.6/urllib/request.py in do_open(self,
http_class, req, **http_conn_args) 1317
h.request(req.get_method(), req.selector, req.data, headers,
-> 1318 encode_chunked=req.has_header('Transfer-encoding')) 1319
except OSError as err: # timeout error
/opt/conda/lib/python3.6/http/client.py in request(self, method, url,
body, headers, encode_chunked) 1238 """Send a complete
request to the server."""
-> 1239 self._send_request(method, url, body, headers, encode_chunked) 1240
/opt/conda/lib/python3.6/http/client.py in _send_request(self, method,
url, body, headers, encode_chunked) 1284 body =
_encode(body, 'body')
-> 1285 self.endheaders(body, encode_chunked=encode_chunked) 1286
/opt/conda/lib/python3.6/http/client.py in endheaders(self,
message_body, encode_chunked) 1233 raise
CannotSendHeader()
-> 1234 self._send_output(message_body, encode_chunked=encode_chunked) 1235
/opt/conda/lib/python3.6/http/client.py in _send_output(self,
message_body, encode_chunked) 1025 del self._buffer[:]
-> 1026 self.send(msg) 1027
/opt/conda/lib/python3.6/http/client.py in send(self, data)
963 if self.auto_open:
--> 964 self.connect()
965 else:
/opt/conda/lib/python3.6/http/client.py in connect(self) 1391
-> 1392 super().connect() 1393
/opt/conda/lib/python3.6/http/client.py in connect(self)
935 self.sock = self._create_connection(
--> 936 (self.host,self.port), self.timeout, self.source_address)
937 self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
/opt/conda/lib/python3.6/socket.py in create_connection(address,
timeout, source_address)
703 err = None
--> 704 for res in getaddrinfo(host, port, 0, SOCK_STREAM):
705 af, socktype, proto, canonname, sa = res
/opt/conda/lib/python3.6/socket.py in getaddrinfo(host, port, family,
type, proto, flags)
744 addrlist = []
--> 745 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
746 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) /opt/conda/lib/python3.6/site-packages/keras/utils/data_utils.py
in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir,
hash_algorithm, extract, archive_format, cache_dir)
221 try:
--> 222 urlretrieve(origin, fpath, dl_progress)
223 except HTTPError as e:
/opt/conda/lib/python3.6/urllib/request.py in urlretrieve(url,
filename, reporthook, data)
247
--> 248 with contextlib.closing(urlopen(url, data)) as fp:
249 headers = fp.info()
/opt/conda/lib/python3.6/urllib/request.py in urlopen(url, data,
timeout, cafile, capath, cadefault, context)
222 opener = _opener
--> 223 return opener.open(url, data, timeout)
224
/opt/conda/lib/python3.6/urllib/request.py in open(self, fullurl,
data, timeout)
525
--> 526 response = self._open(req, data)
527
/opt/conda/lib/python3.6/urllib/request.py in _open(self, req, data)
543 result = self._call_chain(self.handle_open, protocol, protocol +
--> 544 '_open', req)
545 if result:
/opt/conda/lib/python3.6/urllib/request.py in _call_chain(self, chain,
kind, meth_name, *args)
503 func = getattr(handler, meth_name)
--> 504 result = func(*args)
505 if result is not None:
/opt/conda/lib/python3.6/urllib/request.py in https_open(self, req)
1360 return self.do_open(http.client.HTTPSConnection, req,
-> 1361 context=self._context, check_hostname=self._check_hostname) 1362
/opt/conda/lib/python3.6/urllib/request.py in do_open(self,
http_class, req, **http_conn_args) 1319 except OSError
as err: # timeout error
-> 1320 raise URLError(err) 1321 r = h.getresponse()
URLError:
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call
last) in ()
----> 1 initial_model = VGG19(include_top=False, input_shape=(128,128,3), weights='imagenet')
/opt/conda/lib/python3.6/site-packages/keras/applications/init.py
in wrapper(*args, **kwargs)
26 kwargs['models'] = models
27 kwargs['utils'] = utils
---> 28 return base_fun(*args, **kwargs)
29
30 return wrapper
/opt/conda/lib/python3.6/site-packages/keras/applications/vgg19.py in
VGG19(*args, **kwargs)
9 @keras_modules_injection
10 def VGG19(*args, **kwargs):
---> 11 return vgg19.VGG19(*args, **kwargs)
12
13
/opt/conda/lib/python3.6/site-packages/keras_applications/vgg19.py in
VGG19(include_top, weights, input_tensor, input_shape, pooling,
classes, **kwargs)
219 WEIGHTS_PATH_NO_TOP,
220 cache_subdir='models',
--> 221 file_hash='253f8cb515780f3b799900260a226db6')
222 model.load_weights(weights_path)
223 if backend.backend() == 'theano':
/opt/conda/lib/python3.6/site-packages/keras/utils/data_utils.py in
get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir,
hash_algorithm, extract, archive_format, cache_dir)
224 raise Exception(error_msg.format(origin, e.code, e.msg))
225 except URLError as e:
--> 226 raise Exception(error_msg.format(origin, e.errno, e.reason))
227 except (Exception, KeyboardInterrupt):
228 if os.path.exists(fpath):
Exception: URL fetch failure on
https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5:
None -- [Errno -3] Temporary failure in name resolution
看起来您可能没有在您的内核中启用互联网访问。您可以在右侧的面板中执行此操作。添加互联网连接后,您将能够下载文件。
其实我们也已经有了the VGG-19 weights uploaded to Kaggle。如果愿意,您可以将这个现有数据集添加到您的内核而不是下载它,这对您来说可能会更快一些。
希望对您有所帮助! :)
在右侧,您将有一个名为 "Internet" 的选项,检查它是否设置为“打开”。如果没有,启用它然后尝试。它应该可以工作
首先,我们需要验证 phone 号码,以启用互联网选项。然后只需启用它并重新 运行 笔记本。希望它能奏效。
initial_model = VGG19(weights='imagenet', pooling = max)
我正在尝试在 kaggle 的 keras 中导入预训练的 VGG 模型。我 运行 通过一个不熟悉的 gaierror
Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5
--------------------------------------------------------------------------- gaierror Traceback (most recent call last) /opt/conda/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args) 1317
h.request(req.get_method(), req.selector, req.data, headers, -> 1318 encode_chunked=req.has_header('Transfer-encoding')) 1319
except OSError as err: # timeout error/opt/conda/lib/python3.6/http/client.py in request(self, method, url, body, headers, encode_chunked) 1238 """Send a complete request to the server.""" -> 1239 self._send_request(method, url, body, headers, encode_chunked) 1240
/opt/conda/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked) 1284 body = _encode(body, 'body') -> 1285 self.endheaders(body, encode_chunked=encode_chunked) 1286
/opt/conda/lib/python3.6/http/client.py in endheaders(self, message_body, encode_chunked) 1233 raise CannotSendHeader() -> 1234 self._send_output(message_body, encode_chunked=encode_chunked) 1235
/opt/conda/lib/python3.6/http/client.py in _send_output(self, message_body, encode_chunked) 1025 del self._buffer[:] -> 1026 self.send(msg) 1027
/opt/conda/lib/python3.6/http/client.py in send(self, data) 963 if self.auto_open: --> 964 self.connect() 965 else:
/opt/conda/lib/python3.6/http/client.py in connect(self) 1391 -> 1392 super().connect() 1393
/opt/conda/lib/python3.6/http/client.py in connect(self) 935 self.sock = self._create_connection( --> 936 (self.host,self.port), self.timeout, self.source_address) 937 self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
/opt/conda/lib/python3.6/socket.py in create_connection(address, timeout, source_address) 703 err = None --> 704 for res in getaddrinfo(host, port, 0, SOCK_STREAM): 705 af, socktype, proto, canonname, sa = res
/opt/conda/lib/python3.6/socket.py in getaddrinfo(host, port, family, type, proto, flags) 744 addrlist = [] --> 745 for res in _socket.getaddrinfo(host, port, family, type, proto, flags): 746 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) /opt/conda/lib/python3.6/site-packages/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir) 221 try: --> 222 urlretrieve(origin, fpath, dl_progress) 223 except HTTPError as e:
/opt/conda/lib/python3.6/urllib/request.py in urlretrieve(url, filename, reporthook, data) 247 --> 248 with contextlib.closing(urlopen(url, data)) as fp: 249 headers = fp.info()
/opt/conda/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context) 222 opener = _opener --> 223 return opener.open(url, data, timeout) 224
/opt/conda/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout) 525 --> 526 response = self._open(req, data) 527
/opt/conda/lib/python3.6/urllib/request.py in _open(self, req, data) 543 result = self._call_chain(self.handle_open, protocol, protocol + --> 544 '_open', req) 545 if result:
/opt/conda/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args) 503 func = getattr(handler, meth_name) --> 504 result = func(*args) 505 if result is not None:
/opt/conda/lib/python3.6/urllib/request.py in https_open(self, req)
1360 return self.do_open(http.client.HTTPSConnection, req, -> 1361 context=self._context, check_hostname=self._check_hostname) 1362/opt/conda/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args) 1319 except OSError as err: # timeout error -> 1320 raise URLError(err) 1321 r = h.getresponse()
URLError:
During handling of the above exception, another exception occurred:
Exception Traceback (most recent call last) in () ----> 1 initial_model = VGG19(include_top=False, input_shape=(128,128,3), weights='imagenet')
/opt/conda/lib/python3.6/site-packages/keras/applications/init.py in wrapper(*args, **kwargs) 26 kwargs['models'] = models 27 kwargs['utils'] = utils ---> 28 return base_fun(*args, **kwargs) 29 30 return wrapper
/opt/conda/lib/python3.6/site-packages/keras/applications/vgg19.py in VGG19(*args, **kwargs) 9 @keras_modules_injection 10 def VGG19(*args, **kwargs): ---> 11 return vgg19.VGG19(*args, **kwargs) 12 13
/opt/conda/lib/python3.6/site-packages/keras_applications/vgg19.py in VGG19(include_top, weights, input_tensor, input_shape, pooling, classes, **kwargs) 219 WEIGHTS_PATH_NO_TOP, 220 cache_subdir='models', --> 221 file_hash='253f8cb515780f3b799900260a226db6') 222 model.load_weights(weights_path) 223 if backend.backend() == 'theano':
/opt/conda/lib/python3.6/site-packages/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir) 224 raise Exception(error_msg.format(origin, e.code, e.msg)) 225 except URLError as e: --> 226 raise Exception(error_msg.format(origin, e.errno, e.reason)) 227 except (Exception, KeyboardInterrupt): 228 if os.path.exists(fpath):
Exception: URL fetch failure on https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5: None -- [Errno -3] Temporary failure in name resolution
看起来您可能没有在您的内核中启用互联网访问。您可以在右侧的面板中执行此操作。添加互联网连接后,您将能够下载文件。
其实我们也已经有了the VGG-19 weights uploaded to Kaggle。如果愿意,您可以将这个现有数据集添加到您的内核而不是下载它,这对您来说可能会更快一些。
希望对您有所帮助! :)
在右侧,您将有一个名为 "Internet" 的选项,检查它是否设置为“打开”。如果没有,启用它然后尝试。它应该可以工作
首先,我们需要验证 phone 号码,以启用互联网选项。然后只需启用它并重新 运行 笔记本。希望它能奏效。