comparison deep/rbm/rbm.py @ 375:e36ccffb3870

Changes to cast NIST data to floatX for rbm code
author Xavier Glorot <glorotxa@iro.umontreal.ca>
date Sun, 25 Apr 2010 14:53:10 -0400
parents 1e99dc965b5b
children
comparison
equal deleted inserted replaced
374:846f0678ffe8 375:e36ccffb3870
271 f = open(data_path+'all/all_train_data.ft') 271 f = open(data_path+'all/all_train_data.ft')
272 g = open(data_path+'all/all_train_labels.ft') 272 g = open(data_path+'all/all_train_labels.ft')
273 h = open(data_path+'all/all_test_data.ft') 273 h = open(data_path+'all/all_test_data.ft')
274 i = open(data_path+'all/all_test_labels.ft') 274 i = open(data_path+'all/all_test_labels.ft')
275 275
276 train_set_x = theano.shared(ft.read(f)) 276 train_set_x_uint8 = theano.shared(ft.read(f))
277 test_set_x_uint8 = theano.shared(ft.read(h))
278
279
280 train_set_x = T.cast(train_set_x_uint8/255.,theano.config.floatX)
277 train_set_y = ft.read(g) 281 train_set_y = ft.read(g)
278 test_set_x = ft.read(h) 282 test_set_x = T.cast(test_set_x_uint8/255.,theano.config.floatX)
279 test_set_y = ft.read(i) 283 test_set_y = ft.read(i)
280 284
281 f.close() 285 f.close()
282 g.close() 286 g.close()
283 i.close() 287 i.close()
284 h.close() 288 h.close()
285 289
286 #t = len(train_set_x) 290 #t = len(train_set_x)
287 print train_set_x.value.shape
288 291
289 # revoir la recuperation des donnees 292 # revoir la recuperation des donnees
290 ## dataset = load_data(dataset) 293 ## dataset = load_data(dataset)
291 ## 294 ##
292 ## train_set_x, train_set_y = datasets[0] 295 ## train_set_x, train_set_y = datasets[0]
294 training_epochs = 1 # a determiner 297 training_epochs = 1 # a determiner
295 298
296 batch_size = b_size # size of the minibatch 299 batch_size = b_size # size of the minibatch
297 300
298 # compute number of minibatches for training, validation and testing 301 # compute number of minibatches for training, validation and testing
299 n_train_batches = train_set_x.value.shape[0] / batch_size 302 n_train_batches = train_set_x_uint8.value.shape[0] / batch_size
300 303
301 # allocate symbolic variables for the data 304 # allocate symbolic variables for the data
302 index = T.scalar() # index to a [mini]batch 305 index = T.lscalar() # index to a [mini]batch
303 x = T.matrix('x') # the data is presented as rasterized images 306 x = T.matrix('x') # the data is presented as rasterized images
304 307
305 rng = numpy.random.RandomState(123) 308 rng = numpy.random.RandomState(123)
306 theano_rng = RandomStreams( rng.randint(2**30)) 309 theano_rng = RandomStreams( rng.randint(2**30))
307 310
330 os.makedirs(dirname) 333 os.makedirs(dirname)
331 os.chdir(dirname) 334 os.chdir(dirname)
332 print 'yes' 335 print 'yes'
333 # it is ok for a theano function to have no output 336 # it is ok for a theano function to have no output
334 # the purpose of train_rbm is solely to update the RBM parameters 337 # the purpose of train_rbm is solely to update the RBM parameters
338 print type(batch_size)
339 print index.dtype
335 train_rbm = theano.function([index], cost, 340 train_rbm = theano.function([index], cost,
336 updates = updates, 341 updates = updates,
337 givens = { x: train_set_x[index*batch_size:(index+1)*batch_size]}) 342 givens = { x: train_set_x[index*batch_size:(index+1)*batch_size]})
338 343
339 print 'yep' 344 print 'yep'