0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PyramidSepDropのResidualDropoutを自作した(逃げ)

Last updated at Posted at 2018-12-18

環境

MacOS Mojave
Python 3.6
Keras 2.1.5(backend TensorFlow)

失敗した話

先日、この記事と同じ主題で、KerasのDropoutレイヤーを参考に、Layerクラスを継承した物を実装しました。

ただ、callメソッドはバッチ毎に毎回呼ばれると思っていたんですが、インスタンス化した後に1回しか呼ばれない(らしき)ことが判明しまして…。全部パァになりました。

というわけで、完全に逃げの1手を打ち、無理やり実装しました。

実装

import keras
from keras.layers import GlobalAveragePooling2D, GlobalAveragePooling1D, Reshape, Lambda, multiply

def ResidualDropout(inputs, rate):
    layer = GlobalAveragePooling2D()(inputs)
    dim = layer.get_shape()[1]
    layer = Reshape((dim,1))(layer)
    layer = GlobalAveragePooling1D()(layer)
    layer = Lambda(lambda x : x ** 0)(layer)
    layer = Dropout(rate)(layer)
    return multiply([inputs,layer])

結果的に学習すべきパラメータ数は一切増えてないです。
けど、できればかっこよく実装したかったなぁと。

入力をひたすら圧縮(平均)していってある値にして、0乗する事で無理やり1にして、通常のDropoutで0、もしくは1にしてもらい、元の入力にかけています。

完全に力不足で太刀打ちできなかったので、逃げました。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?