質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

2448閲覧

tf.keras.application モデルがダウンロードできない

mochmoch

総合スコア39

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/11/09 09:38

編集2020/11/12 03:26

tf.keras.application.Mobilenetがダウンロードできない

何が起こったか

機械学習プログラムを書こうと思い、試しに以下のコードを書きました。

python

1from tensorflow import keras 2 3if __name__ == "__main__": 4 inputs = keras.layers.Input(shape=(128, 128, 1)) 5 x = keras.layers.Conv2D(filters=3, kernel_size=3, padding="same", 6 activation="relu")(inputs) 7 x = keras.applications.MobileNet(include_top=False, 8 input_shape=(128, 128, 3), 9 weights="imagenet", 10 pooling="max")(x) 11 x = keras.layers.Dense(128, activation="relu")(x) 12 x = keras.layers.Dropout(0.3)(x) 13 pred = keras.layers.Dense(100, activation="softmax")(x) 14 model = keras.Model(inputs=inputs, outputs=pred) 15 model.summary()

mobilenetを持ってきて転移学習をしようと思ったのですがこのコードの時点で以下のエラーが発生しました。

console

12020-11-09 18:21:44.333555: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: c 2annot open shared object file: No such file or directory 32020-11-09 18:21:44.333600: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 42020-11-09 18:21:45.650596: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open 5 shared object file: No such file or directory 62020-11-09 18:21:45.650656: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303) 72020-11-09 18:21:45.650686: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (mochi-MizLab): /proc/driver/ 8nvidia/version does not exist 92020-11-09 18:21:45.650988: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use t 10he following CPU instructions in performance-critical operations: AVX2 FMA 11To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 122020-11-09 18:21:45.677190: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 2400500000 Hz 132020-11-09 18:21:45.680459: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x563fb5dd3270 initialized for platform Host (this does not guarantee that XLA will 14 be used). Devices: 152020-11-09 18:21:45.680515: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version 16Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/mobilenet/mobilenet_1_0_128_tf_no_top.h5 17Traceback (most recent call last): 18 File "/usr/lib/python3.8/urllib/request.py", line 1350, in do_open 19 h.request(req.get_method(), req.selector, req.data, headers, 20 File "/usr/lib/python3.8/http/client.py", line 1255, in request 21 self._send_request(method, url, body, headers, encode_chunked) 22 File "/usr/lib/python3.8/http/client.py", line 1301, in _send_request 23 self.endheaders(body, encode_chunked=encode_chunked) 24 File "/usr/lib/python3.8/http/client.py", line 1250, in endheaders 25 self._send_output(message_body, encode_chunked=encode_chunked) 26 File "/usr/lib/python3.8/http/client.py", line 1010, in _send_output 27 self.send(msg) 28 File "/usr/lib/python3.8/http/client.py", line 950, in send 29 self.connect() 30 File "/usr/lib/python3.8/http/client.py", line 1417, in connect 31 super().connect() 32 File "/usr/lib/python3.8/http/client.py", line 921, in connect [5/129] 33 self.sock = self._create_connection( 34 File "/usr/lib/python3.8/socket.py", line 787, in create_connection 35 for res in getaddrinfo(host, port, 0, SOCK_STREAM): 36 File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo 37 for res in _socket.getaddrinfo(host, port, family, type, proto, flags): 38socket.gaierror: [Errno -2] Name or service not known 39 40During handling of the above exception, another exception occurred: 41 42Traceback (most recent call last): 43 File "/home/mochi/.local/share/virtualenvs/machine-genome-classification-lm-emihK/lib/python3.8/site-packages/tensorflow/python/keras/utils/data_utils.py", line 278, in ge 44t_file 45 urlretrieve(origin, fpath, dl_progress) 46 File "/usr/lib/python3.8/urllib/request.py", line 247, in urlretrieve 47 with contextlib.closing(urlopen(url, data)) as fp: 48 File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen 49 return opener.open(url, data, timeout) 50 File "/usr/lib/python3.8/urllib/request.py", line 525, in open 51 response = self._open(req, data) 52 File "/usr/lib/python3.8/urllib/request.py", line 542, in _open 53 result = self._call_chain(self.handle_open, protocol, protocol + 54 File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain 55 result = func(*args) 56 File "/usr/lib/python3.8/urllib/request.py", line 1393, in https_open 57 return self.do_open(http.client.HTTPSConnection, req, 58 File "/usr/lib/python3.8/urllib/request.py", line 1353, in do_open 59 raise URLError(err) 60urllib.error.URLError: <urlopen error [Errno -2] Name or service not known> 61 62During handling of the above exception, another exception occurred: 63 64Traceback (most recent call last): 65 File "src/machine_learning/tensorflow/foo.py", line 7, in <module> 66 x = keras.applications.MobileNet(include_top=False, 67 File "/home/mochi/.local/share/virtualenvs/machine-genome-classification-lm-emihK/lib/python3.8/site-packages/tensorflow/python/keras/applications/mobilenet.py", line 304, 68 in MobileNet 69 weights_path = data_utils.get_file( 70 File "/home/mochi/.local/share/virtualenvs/machine-genome-classification-lm-emihK/lib/python3.8/site-packages/tensorflow/python/keras/utils/data_utils.py", line 282, in ge 71t_file 72 raise Exception(error_msg.format(origin, e.errno, e.reason)) 73Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/keras-applications/mobilenet/mobilenet_1_0_128_tf_no_top.h5: None -- [Errno -2] Name or service not 74known

試してみたこと

どうやらhttps://storage.googleapis.com/tensorflow/keras-applications/mobilenet/mobilenet_1_0_128_tf_no_top.h5がURLとして正しくないようなのですが、手動でこのURLにアクセスすると以下のXMLレスポンスが得られました。

xml

1 2<?xml version='1.0' encoding='UTF-8'?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Details>No such object: tensorflow/keras-applications/mobilenet/mobilenet_1_0_128_tf_no_top.h5:</Details></Error>

また、weights=Noneではモデルが読み込めたことから、

  • モデルの呼び出し方法が違う
  • keras内でURLをうまく組み立てられてない

のどちらかではないかと思っているのですが、どのように対処すればよいでしょうか?

ご教授よろしくお願いいたします。

環境

OS: Manjaro Linux x86_64
Python: 3.8.6
tensorflow: 2.3.1

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

いま前述のURLにアクセスしたところ、ダウンロードができました。

おそらくgoogleのサーバ側の問題だったようです。

投稿2020/11/13 06:28

mochmoch

総合スコア39

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問