from tensorflow.keras.applications import VGG16
network = VGG16(weights='imagenet',include_top=False)
network.summary()
執(zhí)行上面的代碼會發(fā)生報錯起宽,這個應(yīng)該是網(wǎng)絡(luò)或是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] 由于連接方在一段時間后沒有正確答復(fù)或連接的主機沒有反應(yīng)瘫俊,連接嘗試失敗鹊杖。
根據(jù)提示可以看到問題就是出在VGG的模型文件無法下載。鏈接是:https://storage.googleapis.com/tensorflow/keras-applications/vgg16/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5
解決方法
將這個鏈接使用瀏覽器下載下來扛芽,然后將文件復(fù)制到C:\Users\(用戶名)\.keras
這個文件夾骂蓖,重現(xiàn)運行就可以了。