Reputation: 11
I want to train first a autoencoder (works) and then use the pretrained encoder and add a mlp for classification. I tried writing a struct but. I use also the package NNHelferlein. My matrix is x_pN=(22283,440) with numbers from 0 to 1 (its fine to generate rand for testing). Then I created minibtaches:
trn_pN_mb = minibatch(x_pN,x_pN, 16, shuffle=false,partial=true);
The NN:
encoder_mlp_diseaseStage = Chain(
Dense(22283, 256),
Dense(256, 64),
Dense(64, 32, actf=relu));
mlp_mlp_diseaseStage = Classifier(
Dense(32,16),
Dense(16,8),
Dense(8,3, actf=identity));
mlp_encoder_diseaseStage = EncoderMLP(encoder_mlp_diseaseStage, mlp_mlp_diseaseStage);
struct EncoderMLP <: DNN
encoder
mlp
end
function (ae::EncoderMLP)(x)
# encode - mlp
x = ae.encoder(x)
x = ae.mlp(x)
return x
end
# square loss:
(ae::EncoderMLP)(x, y) = sum(abs2, ae(x) .- y)
(ae::EncoderMLP)(d::Knet.Data) = mean( ae(x,y) for (x,y) in d)
Training:
mlp_encoder_diseaseStage = tb_train!(mlp_encoder_diseaseStage, Adam, trn_pN_mb_frame, epochs=50, lr=0.0002, l2=0.0001, l1=0.00002, tb_name="AE_MLP_Disease_Stage", tb_text="AE_MLP");
My Error is a dimension missmatch, which makes sence, if the ae expects the same dimension for input and output. But I need for the mlp classsification an other output dimension. I appreciate any help.
Upvotes: 1
Views: 68