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

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

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

Kaggleは、機械学習モデルを構築するコンペティションのプラットフォームおよびその運営企業を指します。企業や政府といった組織とデータサイエンティスト・機械学習エンジニアを繋げるプラットフォームであり、単純なマッチングではなくコンペティションが特徴です。

Python

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

Q&A

解決済

1回答

970閲覧

オフラインでkerasモデルを実行したい

0990

総合スコア8

Kaggle

Kaggleは、機械学習モデルを構築するコンペティションのプラットフォームおよびその運営企業を指します。企業や政府といった組織とデータサイエンティスト・機械学習エンジニアを繋げるプラットフォームであり、単純なマッチングではなくコンペティションが特徴です。

Python

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

0グッド

1クリップ

投稿2023/01/09 15:13

実現したいこと

kaggleのコンペのルールでインターネットをOFFの状態で実行しなければいけません。
作成したモデルが自動でインターネットに接続されアプリをダウンロードする仕組みのようで、そこで止まってしまいます。

該当のソースコード

keras.backend.clear_session() with strategy.scope(): model = keras.Sequential( [ keras.layers.InputLayer(input_shape=INP_SIZE+(3,)), data_preprocessing, data_augmentations, applications.EfficientNetB0(include_top=False, pooling='avg'), keras.layers.Dense(1, activation=None, dtype='float32') ] ) model.compile( optimizer = tfa.optimizers.RectifiedAdam(learning_rate=0.003, amsgrad=False), loss = binary_focal_loss( apply_class_balancing=True, apply_bce_weight=5, alpha=0.75, gamma=7.0, label_smoothing=0.05, from_logits=True, reduction='mean' ), metrics = [ tf_pfbeta(beta=1.0, from_logits=True), tf_auc(from_logits=True), ] ) model.summary()

発生している問題・エラーメッセージ

ファイルをダウンロードしようとして失敗しています。

Downloading data from https://storage.googleapis.com/keras-applications/efficientnetb0_notop.h5 ~~~~ gaierror Traceback (most recent call last) . . gaierror: [Errno -3] Temporary failure in name resolution During handling of the above exception, another exception occurred: URLError Traceback (most recent call last) . . URLError: <urlopen error [Errno -3] Temporary failure in name resolution> During handling of the above exception, another exception occurred: Exception Traceback (most recent call last) . . Exception: URL fetch failure on https://storage.googleapis.com/keras-applications/efficientnetb0_notop.h5: None -- [Errno -3] Temporary failure in name resolution

試したこと

一旦オンラインで,
https://storage.googleapis.com/keras-applications/efficientnetb0_notop.h5 のファイルをダウンロードしてオフラインでinstallしようとしましたがエラーになります。

!pip install /kaggle/input/efficientnetb0-notop/efficientnetb0_notop.h5
ERROR: Invalid requirement: '/kaggle/input/efficientnetb0-notop/efficientnetb0_notop.h5' Hint: It looks like a path. The path does exist. The argument you provided (/kaggle/input/efficientnetb0-notop/efficientnetb0_notop.h5) appears to be a requirements file. If that is the case, use the '-r' flag to install the packages specified within it.
!pip install -r /kaggle/input/efficientnetb0-notop/efficientnetb0_notop.h5
ERROR: Exception: Traceback (most recent call last): UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

補足情報(FW/ツールのバージョンなど)

このコードはオンラインでは動きます。

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

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

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

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

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

jbpb0

2023/01/10 02:07

applications.EfficientNetB0(include_top=False, pooling='avg'), ↓ 変更 applications.EfficientNetB0(include_top=False, pooling='avg', weights=None), で、どうでしょうか?
meg_

2023/01/10 05:31

> kaggleのコンペのルールでインターネットをOFFの状態で実行しなければいけません。 どのコンペか教えていただくことは可能でしょうか?
guest

回答1

0

ベストアンサー

Kerasのドキュメント

Keras API reference / Keras Applications / EfficientNet B0 to B7

weights: One of None (random initialization), 'imagenet' (pre-training on ImageNet), or the path to the weights file to be loaded. Defaults to 'imagenet'.

のとおり,ダウンロードされた事前学習済み重みefficientnetb0_notop.h5を利用するなら,the path to the weightsなので

Python

1with strategy.scope(): 2 model = keras.Sequential( 3 [ 4 keras.layers.InputLayer(input_shape=INP_SIZE+(3,)), 5 data_preprocessing, 6 data_augmentations, 7 applications.EfficientNetB0(include_top=False, pooling='avg'weights = "/kaggle/input/efficientnetb0-notop/efficientnetb0_notop.h5"), 8 keras.layers.Dense(1, activation=None, dtype='float32') 9 ] 10 )

にするべきです.ゼロから学習したいならweights = Noneにするべきでしょう.

投稿2023/01/10 03:20

編集2023/01/10 11:00
PondVillege

総合スコア1579

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問