2017-09-25 10 views
1

画像+画像+値を入力とし、画像にコンボルーション+プーリングを行い、結果を線形変換するニューラルネットを作りたいと考えています。私はケラスでそれをすることはできますか?ノンスタンダード入力のニューラルネット

+0

画像の順序と数は固定されていますか? –

+0

@ Craig.Liはい、ちょうど2 – UpmostScarab

答えて

1

これはアーキテクチャクレイグリーの回答に似ていますが、画像、画像、値の形式で、VGG16、ちょうどバニラCNNを使用していません。これらは3つの別々のネットワークで、個々に処理された後に出力が連結され、結果として連結されたベクトルはすべての入力からの情報を含む最終層を通過します。

input_1 = Input(data_1.shape[1:], name = 'input_1') 
conv_branch_1 = Conv2D(filters, (kernel_size, kernel_size), 
       activation = LeakyReLU())(conv_branch_1) 
conv_branch_1 = MaxPooling2D(pool_size = (2,2))(conv_branch_1) 
conv_branch_1 = Flatten()(conv_branch_1) 

input_2 = Input(data_2.shape[1:], name = 'input_2') 
conv_branch_2 = Conv2D(filters, (kernel_size, kernel_size), 
       activation = LeakyReLU())(conv_branch_2) 
conv_branch_2 = MaxPooling2D(pool_size = (2,2))(conv_branch_2) 
conv_branch_2 = Flatten()(conv_branch_2) 

value_input = Input(value_data.shape[1:], name = 'value_input') 
fc_branch = Dense(80, activation=LeakyReLU())(value_input) 

merged_branches = concatenate([conv_branch_1, conv_branch_2, fc_branch]) 
merged_branches = Dense(60, activation=LeakyReLU())(merged_branches) 
merged_branches = Dropout(0.25)(merged_branches) 
merged_branches = Dense(30, activation=LeakyReLU())(merged_branches) 

merged_branches = Dense(1, activation='sigmoid')(merged_branches) 

model = Model(inputs=[input_1, input_2, value_input], outputs=[merged_branches]) 

#if binary classification do this otherwise whatever loss you need 

model.compile(loss='binary_crossentropy') 
1

、あなたのようnumpyで2枚の画像を組み合わせることができます(3、幅、高さ)画像の形状があり、あなたのイメージは、RGBタイプであると仮定します。唯一の私たち、このように2枚の画像を組み合わせて

import numpy as np 
    from PIL import Image 

    img1 = Image.open('image1.jpg') 
    img2 = Image.open('imgae2.jpg') 

    img1 = img1.resize((width,height)) 
    img2 = img2.resize((width,height)) 

    img1_arr = np.asarray(img1,dtype='int32') 
    img2_arr = np.asarray(img2,dtype='int32') 

    #shape of img_arr is (width,height,6) 
    img_arr = np.concatenate((img1_arr,img2_arr),axis=2) 

チャンネルを増やすので、最初の2つの軸でコンボリューションを行うことができます。

UPDATE: 私はあなたが、あなたがKerasはconcatenate()はそれを行うことができます持って、畳み込みの後に2枚の画像をマージするマルチタスクモデルを意味すると思います。

input_tensor = Input(shape=(channels, img_width, img_height)) 
    # Task1 on image1 
    conv_model1 = VGG16(input_tensor=input_tensor, weights=None, include_top=False, classes=classes, 
        input_shape=(channels, img_width, img_height)) 
    conv_output1 = conv_model1.output 
    flatten1 = Flatten()(conv_output1) 
    # Task2 on image2 
    conv_model2 = VGG16(input_tensor=input_tensor, weights=None, include_top=False, classes=classes, 
        input_shape=(channels, img_width, img_height)) 
    conv_output2 = conv_model2.output 
    flatten2 = Flatten()(conv_output2) 
    # Merge the output 
    merged = concatenate([conv_output1, conv_output2], axis=1) 
    merged = Dense(classes,activation='softmax')(merged) 

    # add some Dense layers and Dropout, 
    final_model = Model(inputs=[input_tensor,input_tensor],outputs=merged) 
+0

ありがとうございましたが、いずれの画像でも私の畳み込みに異なる重みを付けたいと思います。だから、私はそれが、最終的に接続されているより多くの種類の異なるレイヤーであることを望みます。 – UpmostScarab

+0

もう一度、お返事ありがとうございます。 convolutionBoyは、私が持っていたかったものに近いものでした(したがって名前)。 – UpmostScarab

関連する問題