from tensorflow.keras.applications import VGG16
network = VGG16(weights='imagenet',include_top=False)
network.summary()
执行上面的代码会发生报错,这个应该是网络或是PyCharm的问题,报错信息如下:
Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/vgg16/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5
Traceback (most recent call last):
File "S:\Anaconda3\envs\DeepLearning\lib\urllib\request.py", line 1349, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "S:\Anaconda3\envs\DeepLearning\lib\http\client.py", line 1287, in request
self._send_request(method, url, body, headers, encode_chunked)
File "S:\Anaconda3\envs\DeepLearning\lib\http\client.py", line 1333, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "S:\Anaconda3\envs\DeepLearning\lib\http\client.py", line 1282, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "S:\Anaconda3\envs\DeepLearning\lib\http\client.py", line 1042, in _send_output
self.send(msg)
File "S:\Anaconda3\envs\DeepLearning\lib\http\client.py", line 980, in send
self.connect()
File "S:\Anaconda3\envs\DeepLearning\lib\http\client.py", line 1448, in connect
server_hostname=server_hostname)
File "S:\Anaconda3\envs\DeepLearning\lib\ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "S:\Anaconda3\envs\DeepLearning\lib\ssl.py", line 817, in __init__
self.do_handshake()
File "S:\Anaconda3\envs\DeepLearning\lib\ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "S:\Anaconda3\envs\DeepLearning\lib\ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
根据提示可以看到问题就是出在VGG的模型文件无法下载。链接是:https://storage.googleapis.com/tensorflow/keras-applications/vgg16/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5
解决方法
将这个链接使用浏览器下载下来,然后将文件复制到C:\Users\(用户名)\.keras
这个文件夹,重现运行就可以了。
网友评论