Ich bin der tutorial in der Version v0.8 von Theano.Wie zu beheben Dimensionsfehler in Theano V0.8 tutorial code
Es ein Beispiel umfasst & der Schaffung einer logistischen Regressions Ausbildung wie unten dargestellt:
rng = np.random
N = 400 # training sample size
feats = 784 # number of input vars
D = (rng.randn(N, feats), rng.randint(size=N, low=0, high=2)) # generate a dataset
training_steps = 10000
x, y = T.matrix('x'), T.matrix('y')
w = theano.shared(rng.randn(feats), name='w') # init a weight vector randomly
b = theano.shared(0., name='b') # init bias variable
# both w and b are 'shared'
print "logistic regression: initial model:"
print w.get_value()
print b.get_value()
# build expression graph
p_1 = 1/(1+T.exp(-T.dot(x,w)-b)) # Probability that target = 1
prediction = p_1 > 0.5 # prediction threshold
xent = -y * T.log(p_1) - (1-y) * T.log(1-p_1) # Cross-entropy loss function
cost = xent.mean() + 0.01 * (w ** 2).sum() # The cost to minimize
gw, gb = T.grad(cost, [w, b]) # Cost gradient = func(w,b)
train = theano.function( # compile training function
inputs=[x,y],
outputs=[prediction, xent],
updates=((w, w - 0.1 * gw), (b, b - 0.1 * gb)))
predict = theano.function(inputs=[x], outputs=prediction)
for i in range(training_steps): # do the training
pred, err = train(D[0], D[1])
Theano den folgenden Fehler wirft:
TypeError: ('Bad input argument to theano function with name "./tut.py:206" at index 1(0-based)', 'Wrong number of dimensions: expected 2, got 1 with shape (400,).')
ich ziemlich sicher bin das Update einfach ist (aufgrund meines Newb-Status bei Theano) und vielleicht einen Umformungsschritt beinhaltet. Das Tutorial hat keinen guten Hinweis. Vorschläge?
Welche Zeile verursacht den Fehler? Dieser: pred, err = Zug (D [0], D [1])? –
Das von Ihnen angegebene Lernprogramm verwendet T.vector für 'y', aber Sie verwenden T.matrix; Labels (allgemein) sind immer Vektor (zumindest für Klassifikationsprobleme). – uyaseen
Ich habe das T.Vector-Problem für die Y-Label-Variable übersehen. Danke für das Aufzeigen! –