kaggle无法下载resnet50预训练模型

时间:2017-11-19 15:27:26

标签: python keras kaggle resnet

我正在尝试在Kaggle内核上使用resnet50预训练模型。

但是,当我运行以下代码时,会发生错误,无法下载预训练模型。我怎样才能让它发挥作用?

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)

错误:

  

- > 1318 encode_chunked = req.has_header(' Transfer-encoding'))1319
  除了OSError为错误:#timeout error   ......

     

异常:网址提取失败   https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5:   无 - [Errno -2]名称或服务未知

所有日志:

  

使用TensorFlow后端。   /opt/conda/lib/python3.6/importlib/_bootstrap.py:219:RuntimeWarning:   compiletime版本3.5的模块   ' tensorflow.python.framework.fast_tensor_util'与运行时不匹配   版本3.6返回f(* args,** kwds)

     

从中下载数据   https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5

     

----------------------------------------------- ---------------------------- gaierror Traceback(最近的电话   在do_open中的/opt/conda/lib/python3.6/urllib/request.py(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
  除了OSError为错误:#timeout error

     请求中的

/opt/conda/lib/python3.6/http/client.py(self,method,url,   body,headers,encode_chunked)1238"""发送完整   请求服务器。"""    - > 1239 self._send_request(method,url,body,headers,encode_chunked)1240

     _send_request中的

/opt/conda/lib/python3.6/http/client.py(self,method,   url,body,headers,encode_chunked)1284 body =   _encode(身体,'身体')    - > 1285 self.endheaders(body,encode_chunked = encode_chunked)1286

     终结者中的

/opt/conda/lib/python3.6/http/client.py(self,   message_body,encode_chunked)1233加注   CannotSendHeader()    - > 1234 self._send_output(message_body,encode_chunked = encode_chunked)1235

     _send_output中的

/opt/conda/lib/python3.6/http/client.py(self,   message_body,encode_chunked)1025 del self._buffer [:]    - > 1026 self.send(msg)1027

     发送中的

/opt/conda/lib/python3.6/http/client.py(self,data)       963如果self.auto_open:    - > 964 self.connect()       965否则:

     

/opt/conda/lib/python3.6/http/client.py in connect(self)1391    - > 1392 super()。connect()1393

     连接中的

/opt/conda/lib/python3.6/http/client.py(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)

     create_connection中的

/opt/conda/lib/python3.6/socket.py(地址,   超时,source_address)       703 err =无    - > 704 for get in getddrinfo(host,port,0,SOCK_STREAM):       705 af,socktype,proto,canonname,sa = res

     getaddrinfo中的

/opt/conda/lib/python3.6/socket.py(主机,端口,系列,   类型,原型,旗帜)       744 addrlist = []    - > 745用于_socket.getaddrinfo中的res(主机,端口,系列,类型,原型,标志):       746 af,socktype,proto,canonname,sa = res

     

gaierror:[Errno -2]名称或服务未知

     

在处理上述异常期间,发生了另一个异常:

     

URLError Traceback(最近的电话   持续)   /opt/conda/lib/python3.6/site-packages/Keras-2.0.6-py3.6.egg/keras/utils/data_utils.py   在get_file中(fname,origin,untar,md5_hash,file_hash,cache_subdir,   hash_algorithm,extract,archive_format,cache_dir)       219尝试:    - > 220 urlretrieve(origin,fpath,dl_progress)       221除URLError外为e:

     urlretrieve中的

/opt/conda/lib/python3.6/urllib/request.py(url,   文件名,reporthook,数据)       247    - > 248使用contextlib.closing(urlopen(url,data))作为fp:       249 headers = fp.info()

     urlopen中的

/opt/conda/lib/python3.6/urllib/request.py(url,data,   超时,cafile,capath,cadefault,context)       222 opener = _opener    - > 223返回opener.open(url,data,timeout)       224

     

/opt/conda/lib/python3.6/urllib/request.py in open(self,fullurl,   数据,超时)       525    - > 526 response = self._open(req,data)       527

     _open中的

/opt/conda/lib/python3.6/urllib/request.py(self,req,data)       543 result = self._call_chain(self.handle_open,protocol,protocol +    - > 544' _open',req)       545如果结果:

     _call_chain中的

/opt/conda/lib/python3.6/urllib/request.py(自我,链,   kind,meth_name,* args)       503 func = getattr(handler,meth_name)    - > 504结果= func(* args)       505如果结果不是无:

     https_open中的

/opt/conda/lib/python3.6/urllib/request.py(self,req)
  1360返回self.do_open(http.client.HTTPSConnection,req,    - > 1361 context = self._context,check_hostname = self._check_hostname)1362

     do_open中的

/opt/conda/lib/python3.6/urllib/request.py(self,   http_class,req,** http_conn_args)1319除了OSError   为错误:#timeout错误    - > 1320引发URLError(错误)1321 r = h.getresponse()

     

URLError:

     

在处理上述异常期间,发生了另一个异常:

     

Exception Traceback(最近的电话   最后)in()         4导入numpy为np         五   ----> 6 model = ResNet50(权重=' imagenet',include_top = False)

     ResNet50中的

/opt/conda/lib/python3.6/site-packages/Keras-2.0.6-py3.6.egg/keras/applications/resnet50.py(include_top,weight,input_tensor,input_shape,pooling,   班)       261 WEIGHTS_PATH_NO_TOP,       262 cache_subdir =' models',    - > 263 md5_hash =' a268eb855778b3df3c7506639542a6af')       264 model.load_weights(weights_path)       265如果K.backend()==' theano':

     

/opt/conda/lib/python3.6/site-packages/Keras-2.0.6-py3.6.egg/keras/utils/data_utils.py   在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引发异常(error_msg.format(origin,e.errno,e.reason))       223除HTTPError外e:       224引发异常(error_msg.format(origin,e.code,e.msg))

     

异常:网址提取失败   https://github.com/fchollet/deep-learning-models/releases/download/v0.2/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5:   无 - [Errno -2]名称或服务未知

2 个答案:

答案 0 :(得分:1)

据我所知,Kaggle内核在没有Internet访问的独立容器中运行。必须设置所有训练模型并将其作为数据集附加。您可以尝试在公共数据集库中搜索所需内容。例如,可以在此处找到Resnet50:https://www.kaggle.com/keras/resnet50

答案 1 :(得分:0)

kaggle的默认互联网设置为关闭。如果打开它,则可以下载预训练的模型。