I’m trying to deploy LSTM models trained through python’s keras in my java web application.I trained with the input(1,24,21),1 is minibatch,24 is timelength,21 is input size.But When I build the test data,it errors with
Unexpected error occurred in scheduled task
org.deeplearning4j.exception.DL4JInvalidInputException: Received input with size(1) = 24 (input array shape = [1, 24, 21]); input.size(1) must match layer nIn size (nIn = 21)
I refer to Keras Model with Reshape + LSTM Fails When Imported · Issue #4556 · eclipse/deeplearning4j · GitHub,
exchanging the position of timelength and input size.It still errors even the input array has been transfromed into(1,21,24).Here is my code.
String dateStart=getNewTime();
List<float> X_test=new ArrayList<>();
List<List> result_elec=elecDao.queryElectricity(dateStart);
List<List<Float>> result_humtem=temphumidDao.queryHumidandTem(dateStart);
List<List<Float>> result_pass=passengerDao.queryPassengerCounter(dateStart);
List<Float> temp= new ArrayList<>();
for(int i=0,j=0,e=0;i<result_humtem.size();i++){
if(i % 8!=0 || i==0){
temp.addAll(result_humtem.get(i));
}
else{
temp.addAll(result_pass.get(j));
j++;
temp.addAll(result_pass.get(j))
j++;
temp.addAll(result_elec.get(e));
e++;
float[] templ=new float[temp.size()];
for(int k =0;k<temp.size();k++){
templ[k]=temp.get(k);
}
X_test.add(templ);
temp.clear();
temp.addAll(result_humtem.get(i));
}
}
NormalizerMinMaxScaler myMinMaxScaler = new NormalizerMinMaxScaler();
INDArray test_X= Nd4j.create(X_test.toArray(new float[X_test.size()][]));
INDArray test_Y=Nd4j.create(elecDao.getNewActualConsumption());
DataSet test_data=new DataSet(test_X,test_Y);
;
myMinMaxScaler.fit(test_data);
myMinMaxScaler.transform(test_X);
myMinMaxScaler.transform(test_Y);
test_X=test_X.transpose();
test_X=test_X.reshape(1,test_X.shape()[0],test_X.shape()[1]);
log.info(String.valueOf(model_elec_hour.output(test_X)));
I print the shape of test_X, it shows(1,21,24).but the errorl tells me the input is (1,24,21).Anybody knows the answer?