Hi everyone I've been some trouble lately trying to understand why the hell 
theano keeps changing my variable types without being explicitly instructed 
to do so.
I've enforced in my .theanorc to use float32 and also to raise any warning 
in case of use float64 via the flag warn_float64=raise.

Here is a minimal example which I cannot understand where the change of 
variable type is coming from.

import numpy as np
import theano
from theano import tensor as T
floatX = theano.config.floatX

N = 400                                   
feats = 784                               
n_classes = 2

D = (np.random.randn(N, feats), np.random.randint(size=N, low=0, high=2))

training_steps = 10000

X = T.fmatrix("X")
y = T.ivector("y")

W = theano.shared(np.random.randn(feats, n_classes).astype(dtype=floatX),

b = theano.shared(np.zeros(W.get_value().shape[1]).astype(dtype=floatX),

p_1 = 1./(1 + T.exp(-T.dot(X, W) - b))

prediction = p_1 > 0.5

cost = T.mean(-y * T.log(p_1) - (1-y) * T.log(1-p_1),
              dtype=floatX, acc_dtype=floatX)

cost += 0.01 * T.sum(W ** 2, dtype=floatX)

gW, gb = T.grad(cost, [W, b])

train = theano.function(inputs=[X, y], outputs=[prediction, cost],
                        updates=((W, W - 0.1 * gW), (b, b - 0.1 * gb)))

predict = theano.function(inputs=[X], outputs=prediction)

for i in range(training_steps):
    pred, err = train(D[0], D[1])

print("Final model:")
print("target values for D:")
print("prediction on D:")

I always get an exception:

Exception: You are creating a TensorVariable with float64 dtype. You 
requested an action via the Theano flag 

Which points to the cost regarding the cross entropy error. 

But I've explicitly told to use float32 both for the inner summation 
calculation in mean operator and and also to cast the output as float32.

I don't understand where this exception is coming from?

Pretty much everything as been set up to float32.

Any help much appreciated?


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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to