Discussion:
[theano-users] LogisticRegression object has no attribute 'input' in predict()
Lazaros Polymenakos
2015-09-09 00:52:38 UTC
Permalink
Hello,

I am fairly new to THEANO. I am trying out the examples and adapting them
to run new experiments.

In the documentation, there is a piece of code for the Logistic Regression
example that is called predict()
and it is used to load a trained model and test on a set of data.

I append the modified code. The actual data loads and the sizes are correct.

I get the following error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "logistic_reg.py", line 180, in predict
inputs=[classifier2.input],
AttributeError: 'LogisticRegression' object has no attribute 'input'


I would appreciate some insight on what could be wrong and how I could fix
it.


def predict():
"""
An example of how to load a trained model and use it
to predict labels.
"""

# load the saved model
classifier = cPickle.load(open('best_model.pkl'))
print classifier.b.get_value().shape
# 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()
train_set_x = numpy.load('m_trainA.npy')
train_set_y = numpy.load('m_labels1.npy')
test_set_x = numpy.load('m_testA.npy')
test_set_y = numpy.load('m_labels2.npy')

predicted_values = predict_model(test_set_x[:10])
print ("Predicted values for the first 10 examples in test set:")
print predicted_values

Many thanks in advance
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Daniel Renshaw
2015-09-09 06:26:42 UTC
Permalink
The error message doesn't seem tally with the code.

The error message is failing in this snippet of code

inputs=[classifier2.input],

but the code doesn't mention `classifier2`, just `classifier`.

Can you share the code you're using to load, or initialize, `classifier2`?

The problem is that whatever `classifier2` is, it doesn't have an attribute
called `ìnput`. Have you modified the `LogisticRegression` class?

Daniel
Post by Lazaros Polymenakos
Hello,
I am fairly new to THEANO. I am trying out the examples and adapting them
to run new experiments.
In the documentation, there is a piece of code for the Logistic Regression
example that is called predict()
and it is used to load a trained model and test on a set of data.
I append the modified code. The actual data loads and the sizes are correct.
File "<stdin>", line 1, in <module>
File "logistic_reg.py", line 180, in predict
inputs=[classifier2.input],
AttributeError: 'LogisticRegression' object has no attribute 'input'
I would appreciate some insight on what could be wrong and how I could fix
it.
"""
An example of how to load a trained model and use it
to predict labels.
"""
# load the saved model
classifier = cPickle.load(open('best_model.pkl'))
print classifier.b.get_value().shape
# 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()
train_set_x = numpy.load('m_trainA.npy')
train_set_y = numpy.load('m_labels1.npy')
test_set_x = numpy.load('m_testA.npy')
test_set_y = numpy.load('m_labels2.npy')
predicted_values = predict_model(test_set_x[:10])
print ("Predicted values for the first 10 examples in test set:")
print predicted_values
Many thanks in advance
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Lazaros Polymenakos
2015-09-09 14:46:42 UTC
Permalink
Hello Daniel,

The classifier2 is a typo that I introduced when I tranferred the code to
post it.

it should read classifier.input.


Here is what the error is pasted again:

logistic_reg.predict()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "logistic_reg.py", line 180, in predict
inputs=[classifier.input],
AttributeError: 'LogisticRegression' object has no attribute 'input'


Sorry about the confusion.

Many thanks.

LP


On Tuesday, September 8, 2015 at 8:52:38 PM UTC-4, Lazaros Polymenakos
Post by Lazaros Polymenakos
Hello,
I am fairly new to THEANO. I am trying out the examples and adapting them
to run new experiments.
In the documentation, there is a piece of code for the Logistic Regression
example that is called predict()
and it is used to load a trained model and test on a set of data.
I append the modified code. The actual data loads and the sizes are correct.
File "<stdin>", line 1, in <module>
File "logistic_reg.py", line 180, in predict
inputs=[classifier.input],
AttributeError: 'LogisticRegression' object has no attribute 'input'
I would appreciate some insight on what could be wrong and how I could fix
it.
"""
An example of how to load a trained model and use it
to predict labels.
"""
# load the saved model
classifier = cPickle.load(open('best_model.pkl'))
print classifier.b.get_value().shape
# 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()
train_set_x = numpy.load('m_trainA.npy')
train_set_y = numpy.load('m_labels1.npy')
test_set_x = numpy.load('m_testA.npy')
test_set_y = numpy.load('m_labels2.npy')
predicted_values = predict_model(test_set_x[:10])
print ("Predicted values for the first 10 examples in test set:")
print predicted_values
Many thanks in advance
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Daniel Renshaw
2015-09-10 11:44:37 UTC
Permalink
The LogisticRegression class in the Theano sample definitely has an
attribute called `ìnput`. Have you created your own class called
LogisticRegression that is could be conflicting with the sample code's
version?

To help test this, what happens if you run the following code while in the
current directory of wherever you have saved the logistic_sgd.py script?

import theano
import theano.tensor as tt
import logistic_sgd
a = logistic_sgd.LogisticRegression(tt.matrix(name='x'), 10, 20)
print a.input.name

This should not cause any errors and should simply print `x`.

Daniel
Post by Lazaros Polymenakos
Hello Daniel,
The classifier2 is a typo that I introduced when I tranferred the code to
post it.
it should read classifier.input.
logistic_reg.predict()
File "<stdin>", line 1, in <module>
File "logistic_reg.py", line 180, in predict
inputs=[classifier.input],
AttributeError: 'LogisticRegression' object has no attribute 'input'
Sorry about the confusion.
Many thanks.
LP
On Tuesday, September 8, 2015 at 8:52:38 PM UTC-4, Lazaros Polymenakos
Post by Lazaros Polymenakos
Hello,
I am fairly new to THEANO. I am trying out the examples and adapting them
to run new experiments.
In the documentation, there is a piece of code for the Logistic
Regression example that is called predict()
and it is used to load a trained model and test on a set of data.
I append the modified code. The actual data loads and the sizes are correct.
File "<stdin>", line 1, in <module>
File "logistic_reg.py", line 180, in predict
inputs=[classifier.input],
AttributeError: 'LogisticRegression' object has no attribute 'input'
I would appreciate some insight on what could be wrong and how I could
fix it.
"""
An example of how to load a trained model and use it
to predict labels.
"""
# load the saved model
classifier = cPickle.load(open('best_model.pkl'))
print classifier.b.get_value().shape
# 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()
train_set_x = numpy.load('m_trainA.npy')
train_set_y = numpy.load('m_labels1.npy')
test_set_x = numpy.load('m_testA.npy')
test_set_y = numpy.load('m_labels2.npy')
predicted_values = predict_model(test_set_x[:10])
print ("Predicted values for the first 10 examples in test set:")
print predicted_values
Many thanks in advance
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Lazaros Polymenakos
2015-09-11 16:19:20 UTC
Permalink
Thank you very much Daniel. The test commands you posted below, helped me
trace the problem(s)

For the record: there were several problems that had to be fixed:

1) in copying the logistic_sgd and modifying it to run on my data, the line

self.input = input

was commented out.

2) The pickle file was never saved properly because of the above.

3) when running the predict() function from a python command line,
importing just the file that contains it (in this case logistic_sgd) did
not seem to be enough. When I finally did: from logistic_reg import *
(with the above problems fixed) it worked!

Many thanks for the help,

LP
Post by Daniel Renshaw
The LogisticRegression class in the Theano sample definitely has an
attribute called `ìnput`. Have you created your own class called
LogisticRegression that is could be conflicting with the sample code's
version?
To help test this, what happens if you run the following code while in the
current directory of wherever you have saved the logistic_sgd.py script?
import theano
import theano.tensor as tt
import logistic_sgd
a = logistic_sgd.LogisticRegression(tt.matrix(name='x'), 10, 20)
print a.input.name
This should not cause any errors and should simply print `x`.
Daniel
Post by Lazaros Polymenakos
Hello Daniel,
The classifier2 is a typo that I introduced when I tranferred the code to
post it.
it should read classifier.input.
logistic_reg.predict()
File "<stdin>", line 1, in <module>
File "logistic_reg.py", line 180, in predict
inputs=[classifier.input],
AttributeError: 'LogisticRegression' object has no attribute 'input'
Sorry about the confusion.
Many thanks.
LP
On Tuesday, September 8, 2015 at 8:52:38 PM UTC-4, Lazaros Polymenakos
Post by Lazaros Polymenakos
Hello,
I am fairly new to THEANO. I am trying out the examples and adapting
them to run new experiments.
In the documentation, there is a piece of code for the Logistic
Regression example that is called predict()
and it is used to load a trained model and test on a set of data.
I append the modified code. The actual data loads and the sizes are correct.
File "<stdin>", line 1, in <module>
File "logistic_reg.py", line 180, in predict
inputs=[classifier.input],
AttributeError: 'LogisticRegression' object has no attribute 'input'
I would appreciate some insight on what could be wrong and how I could
fix it.
"""
An example of how to load a trained model and use it
to predict labels.
"""
# load the saved model
classifier = cPickle.load(open('best_model.pkl'))
print classifier.b.get_value().shape
# 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()
train_set_x = numpy.load('m_trainA.npy')
train_set_y = numpy.load('m_labels1.npy')
test_set_x = numpy.load('m_testA.npy')
test_set_y = numpy.load('m_labels2.npy')
predicted_values = predict_model(test_set_x[:10])
print ("Predicted values for the first 10 examples in test set:")
print predicted_values
Many thanks in advance
--
---
You received this message because you are subscribed to the Google Groups
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Golnoush
2018-08-28 17:07:45 UTC
Permalink
I am also using the same code for saving my trained network and predict on
my new dataset. The code I am using is https://github.com/aseveryn/deep-qa.
The main part is run_nnet.py. I could save and load my network by the same
code in
https://github.com/lzhbrian/RBM-DBN-theano-DL4J/blob/master/src/theano/code/logistic_sgd.py
. but I continously get the same errors in this part,

predict_model = theano.function(inputs=[classifier.input],
outputs=classifier.y_pred)


actually I am not certain what I need to put in the inputs according to my
code. Which one is right?


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)


each of them I try I got the errors:

ImportError: No module named MiniBatchIteratorConstantBatchSize

or

NameError: global name 'predict_prob_batch' is not defined

I would really appreciate if you could help me.
I also used this command for running the code but still the errors.

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()'


Thank you.

On Friday, September 11, 2015 at 12:19:20 PM UTC-4, Lazaros Polymenakos
Post by Lazaros Polymenakos
Thank you very much Daniel. The test commands you posted below, helped me
trace the problem(s)
1) in copying the logistic_sgd and modifying it to run on my data, the line
self.input = input
was commented out.
2) The pickle file was never saved properly because of the above.
3) when running the predict() function from a python command line,
importing just the file that contains it (in this case logistic_sgd) did
not seem to be enough. When I finally did: from logistic_reg import *
(with the above problems fixed) it worked!
Many thanks for the help,
LP
Post by Daniel Renshaw
The LogisticRegression class in the Theano sample definitely has an
attribute called `ìnput`. Have you created your own class called
LogisticRegression that is could be conflicting with the sample code's
version?
To help test this, what happens if you run the following code while in
the current directory of wherever you have saved the logistic_sgd.py script?
import theano
import theano.tensor as tt
import logistic_sgd
a = logistic_sgd.LogisticRegression(tt.matrix(name='x'), 10, 20)
print a.input.name
This should not cause any errors and should simply print `x`.
Daniel
Post by Lazaros Polymenakos
Hello Daniel,
The classifier2 is a typo that I introduced when I tranferred the code
to post it.
it should read classifier.input.
logistic_reg.predict()
File "<stdin>", line 1, in <module>
File "logistic_reg.py", line 180, in predict
inputs=[classifier.input],
AttributeError: 'LogisticRegression' object has no attribute 'input'
Sorry about the confusion.
Many thanks.
LP
On Tuesday, September 8, 2015 at 8:52:38 PM UTC-4, Lazaros Polymenakos
Post by Lazaros Polymenakos
Hello,
I am fairly new to THEANO. I am trying out the examples and adapting
them to run new experiments.
In the documentation, there is a piece of code for the Logistic
Regression example that is called predict()
and it is used to load a trained model and test on a set of data.
I append the modified code. The actual data loads and the sizes are correct.
File "<stdin>", line 1, in <module>
File "logistic_reg.py", line 180, in predict
inputs=[classifier.input],
AttributeError: 'LogisticRegression' object has no attribute 'input'
I would appreciate some insight on what could be wrong and how I could
fix it.
"""
An example of how to load a trained model and use it
to predict labels.
"""
# load the saved model
classifier = cPickle.load(open('best_model.pkl'))
print classifier.b.get_value().shape
# 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()
train_set_x = numpy.load('m_trainA.npy')
train_set_y = numpy.load('m_labels1.npy')
test_set_x = numpy.load('m_testA.npy')
test_set_y = numpy.load('m_labels2.npy')
predicted_values = predict_model(test_set_x[:10])
print ("Predicted values for the first 10 examples in test set:")
print predicted_values
Many thanks in advance
--
---
You received this message because you are subscribed to the Google
Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...