LoginSignup
3
0

More than 3 years have passed since last update.

Kerasでモデル平均化(Model averaging)のメモ

Posted at

モデル平均化(Model averaging)

機械学習では学習する度に結果が異なる。そのため、同じ条件で複数のモデルを作成し平均をとる。

原文:
Model averaging is an ensemble learning technique that reduces the variance in a final neural network model, sacrificing spread in the performance of the model for a confidence in what performance to expect from the model.

翻訳:
モデル平均化は、最終的なニューラルネットワークモデルの分散を低減するアンサンブル学習手法であり、モデルのパフォーマンスの広がりを犠牲にして、モデルに期待されるパフォーマンスの信頼性を高めます。

引用:
https://machinelearningmastery.com/model-averaging-ensemble-for-deep-learning-neural-networks/

モデルのコピー

keras.models.clone_modelを使う。

Help on function clone_model in module keras.models:

clone_model(model, input_tensors=None)
    Clone any `Model` instance.

    Model cloning is similar to calling a model on new inputs,
    except that it creates new layers (and thus new weights) instead
    of sharing the weights of the existing layers.

    # Arguments
        model: Instance of `Model`
            (could be a functional model or a Sequential model).
        input_tensors: optional list of input tensors
            to build the model upon. If not provided,
            placeholders will be created.

    # Returns
        An instance of `Model` reproducing the behavior
        of the original model, on top of new inputs tensors,
        using newly instantiated weights.

    # Raises
        ValueError: in case of invalid `model` argument value.

keras.models.clone_modelで複製したモデルの重みは複製されない。初期の重みはランダムに設定されるのかな。
そのため、クローン元のモデルからmodel.get_weights()で重みを取り出す。
そして、クローンするモデルに.load_weights('my_weights')を用いて重みを設定する。

参考:https://stackoverflow.com/questions/54366935/make-a-deep-copy-of-a-keras-model-in-python

予測を組み合わせる

下記のURLを参考にしてみてください。
https://machinelearningmastery.com/model-averaging-ensemble-for-deep-learning-neural-networks/

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0