Oh, so you want to build the graph completely first, then sample the parameters once given the size of the first example (for instance), then start training, is that correct?
There is no real way of making a Theano function perform something different at the first call than at the later ones, but you could have two different functions: - First, initialize your shared variables for your parameters with a dummy value, for instance an array of size 0 but the right number of dimensions. - Then, build a function that generate samples from a symbolic RandomStreams (given the image) and update the shared variable with that sampled value. - Build also your regular training function, that does not use random streams at all. - When you get your first example, call the initializing function once, and then start your regular training loop. On Wed, Aug 31, 2016, Yanghoon Kim wrote: > Thanks for replying > > I didn't mean to have a weight matrix that change size between but still > keeps the same values. > > for instance, when I want to construct a cnn model which have multiple > layers, I want the model to automatically recognize the size of the > image(image size is not given, because it can be calculated by > image.shape), then randomly initialize those properties of filter( of > course, output channel, filter_size are given). Those training images must > be the same size during one training process, and what I want to construct > is the model which can be adapted to the case image be different size while > there is no image shape given. I know the way using numpy to sample just > once, then there must be the image shape given. > > > > On Wed, Aug 31, 2016 at 2:12 AM, Pascal Lamblin <[email protected]> > wrote: > > > Hi, > > > > If you want to sample the weights only once, before the training starts, > > you need to know in advance what the size of those weights should be. > > It does not make sense to have a weight matrix that change size between > > iterations, but still keeps the same values. > > > > numpy.random _is_ the way to go. > > > > If you need to compute the size of intermediate symbolic variable > > once, when constructing the graph, you can use something like > > that_tensor.eval() or that_tensor.eval({input_variable: input_value}) > > where input_value is a numpy array, for instance the first minibatch > > from your dataset. > > > > On Mon, Aug 29, 2016, Yanghoon Kim wrote: > > > > > > > > > partial code as follows:( please just pay attention to the context of the > > > code) > > > > > > > > > rng = T.shared_randomstreams.RandomStreams() > > > > > > > > > class gen_rand(object): > > > def init(self, rng, input): > > > self.input_shape = input.shape > > > print type(self.input_shape) > > > self.output = rng.uniform(size=self.input_shape, low=0, high=1) > > > def return_output(self): > > > return self.output > > > > > > I coded a neural network code with one of the weigh W initialized with > > > T.shared_randomstreams.RandomStreams(), the reason I didn't use > > > numpy.random is that I don't want to feed input.shape everytime, but to > > > compute the shape of input in the code. > > > > > > the code works but just because it's random tensor, It can't be used as a > > > Weight in neural network, it changes every time. > > > > > > How can I initialize a weight in NN with random module in theano( just > > want > > > to randomly generate value once at the beginning and not to be updated by > > > itself, i tried 'no_default_updates=True' then it can't be updated > > through > > > gradient descent!!, I also tried copy modue in python to shallow copy > > > rng.uniform, there was an error. I tried numpy.random, but it requires > > > numerical size of the random value but not tensor) > > > > > > -- > > > > > > --- > > > 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 [email protected]. > > > For more options, visit https://groups.google.com/d/optout. > > > > > > -- > > Pascal > > > > -- > > > > --- > > You received this message because you are subscribed to a topic in the > > Google Groups "theano-users" group. > > To unsubscribe from this topic, visit https://groups.google.com/d/ > > topic/theano-users/4WvaZ2RHRqI/unsubscribe. > > To unsubscribe from this group and all its topics, send an email to > > [email protected]. > > For more options, visit https://groups.google.com/d/optout. > > > > > > -- > *___________________* > *Yanghoon Kim* > > Seoul National University. > Department of Electrical and Computer Engineering. > Machine Intelligence Lab. > *Tel : +82 10-2297-5301 > *Email : [email protected] > *___________________* > > -- > > --- > 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 [email protected]. > For more options, visit https://groups.google.com/d/optout. -- Pascal -- --- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
