简体   繁体   English

kaggle 无法下载 resnet50 预训练模型

[英]kaggle could not download resnet50 pretrained model

I am trying to use resnet50 pretrained model on Kaggle kernel.我正在尝试在 Kaggle 内核上使用 resnet50 预训练模型。

But, when I run the following code, Error occurs and it could not download the pretrained model.但是,当我运行以下代码时,发生错误并且无法下载预训练模型。 How Can I make it work?我怎样才能让它工作?

from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
import numpy as np

model = ResNet50(weights='imagenet', include_top=False)

Error:错误:

-> 1318 encode_chunked=req.has_header('Transfer-encoding')) 1319 -> 1318 encode_chunked=req.has_header('传输编码')) 1319
except OSError as err: # timeout error ...除了 OSError 作为 err: # timeout error ...

Exception: URL fetch failure on https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5 : None -- [Errno -2] Name or service not known例外: https : //github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5上的 URL 获取失败:无 -- [Errno -2] 名称或服务未知

All logs:所有日志:

Using TensorFlow backend.使用 TensorFlow 后端。 /opt/conda/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6 return f(*args, **kwds) /opt/conda/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: 模块 'tensorflow.python.framework.fast_tensor_util' 的编译时版本 3.5 与运行时版本 3.6 不匹配 return f(*args, **kwds )

Downloading data from https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_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 -------------------------------------------------- ------------------------- gaierror Traceback (最近一次调用最后一次) /opt/conda/lib/python3.6/urllib/request.py in do_open(自我,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 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除了 OSError 作为 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 request(self, method, url, body, headers, encode_chunked) 1238 """向服务器发送一个完整的请求。""" -> 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 _send_request(self, method, url, body, headers, encode_chunked) 1284 body = _encode(body, 'body') -> 1285 self.endheaders(body第 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 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_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 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) 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/http/client.py in connect(self) 935 self.sock = self._create_connection( --> 936 (self.host,self.port), self.timeout, self.源地址)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 create_connection(address, timeout, source_address) 703 err = None --> 704 for res in getaddrinfo(host, port, 0, SOCK_STREAM): 705 af, socktype,原型,规范名称,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 /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 , 类型, 原型, 标志): 746 af, socktype, proto, canonname, sa = res

gaierror: [Errno -2] Name or service not known gaierror: [Errno -2] 名称或服务未知

During handling of the above exception, another exception occurred:在处理上述异常的过程中,又发生了一个异常:

URLError Traceback (most recent call last) /opt/conda/lib/python3.6/site-packages/Keras-2.0.6-py3.6.egg/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir) 219 try: --> 220 urlretrieve(origin, fpath, dl_progress) 221 except URLError as e: URLError Traceback(最近一次调用)/opt/conda/lib/python3.6/site-packages/Keras-2.0.6-py3.6.egg/keras/utils/data_utils.py in get_file(fname, origin, untar , md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir) 219 try: --> 220 urlretrieve(origin, fpath, dl_progress) 221 除了 URLError 为 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 urlretrieve(url, filename, reporthook, data) 247 --> 248 with contextlib.closure(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 urlopen(url, data, timeout, cafile, capath, cadefault, context) 222 opener = _opener --> 223 return opener.open(url, data,第 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, 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 _open(self, req, data) 543 result = self._call_chain(self.handle_open, protocol, protocol + --> 544 '_open', req) 545 如果结果:

/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 _call_chain(self, chain, kind, meth_name, *args) 503 func = getattr(handler, meth_name) --> 504 result = func(*args) 505 如果结果不是 None:

/opt/conda/lib/python3.6/urllib/request.py in https_open(self, req) /opt/conda/lib/python3.6/urllib/request.py 在 https_open(self, req)
1360 return self.do_open(http.client.HTTPSConnection, req, -> 1361 context=self._context, check_hostname=self._check_hostname) 1362第1360章 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() /opt/conda/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args) 1319 除了 OSError 作为 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 () 4 import numpy as np 5 ----> 6 model = ResNet50(weights='imagenet', include_top=False)异常回溯(最近一次调用最后一次)在 () 4 import numpy as np 5 ----> 6 model = ResNet50(weights='imagenet', include_top=False)

/opt/conda/lib/python3.6/site-packages/Keras-2.0.6-py3.6.egg/keras/applications/resnet50.py in ResNet50(include_top, weights, input_tensor, input_shape, pooling, classes) 261 WEIGHTS_PATH_NO_TOP, 262 cache_subdir='models', --> 263 md5_hash='a268eb855778b3df3c7506639542a6af') 264 model.load_weights(weights_path) 265 if K.backend() == 'theano': ResNet50中的/opt/conda/lib/python3.6/site-packages/Keras-2.0.6-py3.6.egg/keras/applications/resnet50.py(包括_top,权重,input_tensor,input_shape,池化,类)261 WEIGHTS_PATH_NO_TOP, 262 cache_subdir='models', --> 263 md5_hash='a268eb855778b3df3c7506639542a6af') 264 model.load_weights(weights_path) 265 if K.backend(): ==

/opt/conda/lib/python3.6/site-packages/Keras-2.0.6-py3.6.egg/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm, extract, archive_format, cache_dir) 220 urlretrieve(origin, fpath, dl_progress) 221 except URLError as e: --> 222 raise Exception(error_msg.format(origin, e.errno, e.reason)) 223 except HTTPError as e: 224 raise Exception(error_msg.format(origin, e.code, e.msg)) /opt/conda/lib/python3.6/site-packages/Keras-2.0.6-py3.6.egg/keras/utils/data_utils.py in get_file(fname, origin, untar, md5_hash, file_hash, cache_subdir, hash_algorithm ,extract,archive_format,cache_dir) 220 urlretrieve(origin, fpath, dl_progress) 221 除了 URLError 作为 e: --> 222 raise Exception(error_msg.format(origin, e.errno, e.reason)) 223 除了 HTTPError 作为 e: 224引发异常(error_msg.format(origin,e.code,e.msg))

Exception: URL fetch failure on https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5 : None -- [Errno -2] Name or service not known例外: https : //github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5上的 URL 获取失败:无 -- [Errno -2] 名称或服务未知

Internet setting comes off as default on kaggle.互联网设置在 kaggle 上默认关闭。 If you turn on it, you can download the pre-trained models.如果你打开它,你可以下载预训练的模型。

On the right side of the kernel, you will see the settings you can enable the Internet there.在内核的右侧,您将看到可以在那里启用 Internet 的设置。在此处输入图片说明

As far as I know, Kaggle kernels run in isolated containers without Internet access.据我所知,Kaggle 内核在没有 Internet 访问的隔离容器中运行。 All training models must be set up and attached as data sets.所有训练模型都必须设置并附加为数据集。 You can try searching for what you need within the public dataset library.您可以尝试在公共数据集库中搜索您需要的内容。 For example, Resnet50 can be found here: https://www.kaggle.com/keras/resnet50例如,可以在这里找到 Resnet50: https ://www.kaggle.com/keras/resnet50

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM