3

現在、私はVGG16 + Keras + Theanoを使用して、転移学習の方法論を植物のクラスを認識すると考えました。それはうまく機能し、良い精度が得られます。しかし、私が解決しようとしている次の問題は、入力画像に植物が含まれているかどうかを識別する方法を見つけることです。それは本当に効率的ではないので、それを行う別の分類子を持ちたくありません。

そのため、いくつかの検索を行ったところ、最新のモデル レイヤー (アクティベーション レイヤーの前) からアクティベーションを取得して分析できることがわかりました。

from keras import backend as K

model = util.load_model() # VGG16 model
model.load_weights(path_to_weights)

def get_activations(m, layer, X_batch):
    x = [m.layers[0].input, K.learning_phase()]
    y = [m.get_layer(layer).output]
    get_activations = K.function(x, y)
    activations = get_activations([X_batch, 0])

    # trying to get some features from activations
    # to understand how can we identify if an image is relevant
    for l in activations[0]:
        not_nulls = [x for x in l if x > 0]

        # shows percentage of activated neurons
        c1 = float(len(not_nulls)) / len(l)
        n_activated = len(not_nulls)
        print 'c1:{}, n_activated:{}'.format(c1, n_activated)

    return activations

get_activations(model, 'the_latest_layer_name', inputs)

上記のコードから、非常に無関係な画像がある場合、活性化されたニューロンの数が植物を含む画像よりも多いことに気付きました。

  1. モデルのトレーニングに使用していた画像の場合、活性化されたニューロンの数は 19% ~ 23%
  2. 未知の植物種を含む画像の場合 20%-26%
  3. 無関係な画像の場合 24%-28%

パーセンテージ値として関連する画像が交差しているかどうかを理解するのは、あまり良い機能ではありません。

では、この問題を解決する良い方法はありますか?

4

1 に答える 1