Fehler aufgrund von Theano und NumPy-Variablen-Typen

Schreibe ich diesen code mithilfe von numpy 1.9 und die neueste version von Theano, aber ich bekomme eine Fehlermeldung die ich nicht beheben kann. Ich Zweifel es sein könnte, die Art, wie ich erklären-Variablen-Typen, aber ich kann nicht arbeiten es um. Ich Schätze Ihre Vorschläge. Ich möchte Produkt einer matrix mit einem Vektor und Betrag mit einem bias.

import theano.tensor as T
from theano import function
import numpy as np
import pprint
def test_theano_matrix():
   pp = pprint.PrettyPrinter(indent=3)
   W= T.fmatrix()
   x=T.fvector()
   b= T.fvector()
   y = T.dot(W,x) + b
   lin_func = function([W,x,b],y)
   dt = np.dtype(np.float)
   w_inp = np.matrix('1 0;0 1',dtype=dt)
   x_inp = np.matrix('2;1',dtype=dt)
   b_inp = np.matrix('0;0',dtype=dt)
   lin_func(w_inp,x_inp,b_inp)

 if __name__ == '__main__':
   test_theano_matrix()

Bekomme ich die folgende Fehlermeldung:

raise TypeError(err_msg, data)
TypeError: ('Bad input argument to theano function at index 0(0-based)',
'TensorType(float32, matrix) cannot store a value of dtype float64 without risking loss of precision. If you do not mind this loss, you can: 1) explicitly cast your data to float32, or 2) set "allow_input_downcast=True" when calling "function".', matrix([[ 1.,  0.],[ 0.,  1.]]))

Vielen Dank für Ihre Zeit!

  • Warum ändern Sie ihn dann nicht dt = np.type(np.float) zu np.float64? Darüber hinaus wird die traceback-explizit sagt Sie zwei Möglichkeiten, wie Sie das problem selbst lösen können...
  • Es ändert sich die Fehlermeldung zu TypeError: ('Bad input argument to theano function at index 1(0-based)', 'Wrong number of dimensions: expected 1, got 2 with shape (2, 1).')
  • Wieder, wird die traceback-erzählen Sie das problem... Der erste Fehler (bei index 0) wurde behoben mit der richtigen dtype. Nun, es beschwert sich über das argument mit index 1, x_inp, und es Ihnen die Form ist falsch.
  • W_inp ist 2x2 matrix und x_inp ist 2x1, so sehe ich nicht, warum es ist, beschwerte sich über die Form.
Schreibe einen Kommentar