aigamedev / scikit-neuralnetwork

Deep neural networks without the learning cliff! Classifiers and regressors compatible with scikit-learn.
BSD 3-Clause "New" or "Revised" License
1.21k stars 221 forks source link

scoring using the second layer output of a network with five layers #192

Open yhifny opened 8 years ago

yhifny commented 8 years ago

Hi, I have a mlp network [693,128,30,128,5]. I would like to compute the scores of the second layer ( 30 dim vector) and ignore the rest of the network during scoring (bottleneck features). How to do that?

alexjc commented 8 years ago

There's currently no way to access intermediate outputs from a network. You could create a new smaller network and transfer some of the values from get_parameters() manually...

yhifny commented 8 years ago

nn = pickle.load(open('/home/speech/dialect_work_AA/htk_scripts/nn1.pkl', 'rb')) test_X = np.load('test_x.npy') print test_X.shape test_y = np.load('test_y.npy') y_pred=nn.predict(test_X) print accuracy_score(test_y, y_pred)

params=nn.get_parameters()[0:2] print params logreg = Classifier(layers=[Layer("Rectifier",units=128),Layer("Rectifier", units=30) ], weights=params) y_pred=logreg.predict_proba(test_X) print y_pred.shape

I got this error:

Initializing neural network with 2 layers, 693 inputs and 30 outputs.
  - Dense: Rectifier  Units:  128
  - Dense: Rectifier  Units:  30
number of layers 2 .
Reloading parameters for 2 layer weights and biases.
i= 0 .
Traceback (most recent call last):
  File "../frontend/mlp_bnf.py", line 38, in <module>
    y_pred=logreg.predict_proba(test_X)
  File "/usr/local/lib/python2.7/dist-packages/sknn/mlp.py", line 420, in predict_proba
    proba = super(Classifier, self)._predict(X)
  File "/usr/local/lib/python2.7/dist-packages/sknn/mlp.py", line 253, in _predict
    self._initialize(X)
  File "/usr/local/lib/python2.7/dist-packages/sknn/mlp.py", line 42, in _initialize
    return self._backend._initialize_impl(X, y, w)
  File "/usr/local/lib/python2.7/dist-packages/sknn/backend/lasagne/mlp.py", line 214, in _initialize_impl
    self._create_mlp(X, w)
  File "/usr/local/lib/python2.7/dist-packages/sknn/backend/lasagne/mlp.py", line 194, in _create_mlp
    self._array_to_mlp(self.weights, self.mlp)
  File "/usr/local/lib/python2.7/dist-packages/sknn/backend/lasagne/mlp.py", line 335, in _array_to_mlp
    weights, biases = data
ValueError: too many values to unpack

any idea how to solve it?

Thanks, Yasser

alexjc commented 8 years ago

Can you get it working without loading from pickle?

alexjc commented 8 years ago

Ah, I think I know what this is... Looking into it!