title: use a saved trained model to predict on new dataset
body: <p>I am using theano, sklearn and numpy in Python. I found this code for saving my trained network and predict on my new dataset in this link <a href="https://github.com/lzhbrian/RBM-DBN-theano-DL4J/blob/master/src/theano/code/logistic_sgd.py" rel="nofollow noreferrer">https://github.com/lzhbrian/RBM-DBN-theano-DL4J/blob/master/src/theano/code/logistic_sgd.py</a>. the part of the code I am using is this :</p>
  
  <pre><code>"""
  An example of how to load a trained model and use it
  to predict labels.
  """
  def predict():
  # load the saved model
  classifier = pickle.load(open('best_model.pkl'))
  
  # compile a predictor function
  predict_model = theano.function(
  inputs=[classifier.input],
  outputs=classifier.y_pred)
  
  # We can test it on some examples from test test
  dataset='mnist.pkl.gz'
  datasets = load_data(dataset)
  test_set_x, test_set_y = datasets[2]
  test_set_x = test_set_x.get_value()
  
  predicted_values = predict_model(test_set_x[:10])
  print("Predicted values for the first 10 examples in test set:")
  print(predicted_values)
  
  if __name__ == '__main__':
  sgd_optimization_mnist()
  </code></pre>
  
  <p>The code for the neural network model  I want to save and load and predict with is <a href="https://github.com/aseveryn/deep-qa" rel="nofollow noreferrer">https://github.com/aseveryn/deep-qa</a>. I could save and load the model with cPickle but I continuously get errors in <code># compile a predictor function</code> part:</p>
  
  <pre><code>predict_model = theano.function(inputs=[classifier.input],outputs=classifier.y_pred)
  </code></pre>
  
  <p>Actually I am not certain what I need to put in the inputs according to my code. Which one is right?</p>
  
  <pre><code>inputs=[main.predict_prob_batch.batch_iterator],  outputs=test_nnet.layers[-1].
  y_pred)
  
  inputs=[predict_prob_batch.batch_iterator],
  outputs=test_nnet.layers[-1].y_pred)
  
  inputs=[MiniBatchIteratorConstantBatchSize.dataset],
  outputs=test_nnet.layers[-1].y_pred)
  
  inputs=[
  sgd_trainer.MiniBatchIteratorConstantBatchSize.dataset],
  outputs=test_nnet.layers[-1].y_pred)
  </code></pre>
  
  <p>or none of them???</p>
  
  <p>Each of them I tried I got the errors:</p>
  
  <blockquote>
    <p>ImportError: No module named MiniBatchIteratorConstantBatchSize</p>
  </blockquote>
  
  <p>or</p>
  
  <blockquote>
    <p>NameError: global name 'predict_prob_batch' is not defined</p>
  </blockquote>
  
  <p>I would really appreciate if you could help me.
  I also used these commands for running the code but still the errors.</p>
  
  <pre><code>python -c 'from run_nnet import predict; from sgd_trainer import MiniBatchIteratorConstantBatchSize; from MiniBatchIteratorConstantBatchSize import dataset; print predict()'
  
  
  python -c 'from run_nnet import predict; from sgd_trainer import *; from MiniBatchIteratorConstantBatchSize import dataset; print predict()'
  </code></pre>
  
  <p>Thank you and let me know please if you know a better way to predict for new dataset on the loaded trained model. </p>