# Invalid input in LSTM prediction

**URL:** <https://community.konduit.ai/t/invalid-input-in-lstm-prediction/1911>\
**Category:** DL4J\
**Created:** [June 27, 2022, 8:46am UTC](https://community.konduit.ai/t/invalid-input-in-lstm-prediction/1911 "2022-06-27T08:46:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![devcdos](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/devcdos/32/774_2.png) [@devcdos](https://community.konduit.ai/u/devcdos)\
**Post date:** [June 27, 2022, 8:46am UTC](https://community.konduit.ai/t/invalid-input-in-lstm-prediction/1911/1 "2022-06-27T08:46:03Z")

</div>

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](https://github.com/eclipse/deeplearning4j/issues/4556),  
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?
