Skip to content

Commit 1fb52f0

Browse files
committed
Remove .value in rbm
1 parent 72b5062 commit 1fb52f0

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

code/rbm.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def test_rbm(learning_rate=0.1, training_epochs = 15,
321321

322322

323323
# compute number of minibatches for training, validation and testing
324-
n_train_batches = train_set_x.value.shape[0] / batch_size
324+
n_train_batches = train_set_x.get_value(borrow=True).shape[0] / batch_size
325325

326326
# allocate symbolic variables for the data
327327
index = T.lscalar() # index to a [mini]batch
@@ -373,7 +373,8 @@ def test_rbm(learning_rate=0.1, training_epochs = 15,
373373
# Plot filters after each training epoch
374374
plotting_start = time.clock()
375375
# Construct image from the weight matrix
376-
image = PIL.Image.fromarray(tile_raster_images( X = rbm.W.value.T,
376+
image = PIL.Image.fromarray(tile_raster_images(
377+
X = rbm.W.get_value(borrow=True).T,
377378
img_shape = (28,28),tile_shape = (10,10),
378379
tile_spacing=(1,1)))
379380
image.save('filters_at_epoch_%i.png'%epoch)
@@ -393,12 +394,13 @@ def test_rbm(learning_rate=0.1, training_epochs = 15,
393394

394395

395396
# find out the number of test samples
396-
number_of_test_samples = test_set_x.value.shape[0]
397+
number_of_test_samples = test_set_x.get_value(borrow=True).shape[0]
397398

398399
# pick random test examples, with which to initialize the persistent chain
399400
test_idx = rng.randint(number_of_test_samples-n_chains)
400-
persistent_vis_chain = theano.shared(
401-
numpy.array(test_set_x.value[test_idx:test_idx+n_chains], dtype=theano.config.floatX))
401+
persistent_vis_chain = theano.shared(numpy.asarray(
402+
test_set_x.get_value(borrow=True)[test_idx:test_idx+n_chains],
403+
dtype=theano.config.floatX))
402404

403405
plot_every = 1000
404406
# define one step of Gibbs sampling (mf = mean-field)

doc/rbm.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ been shown to lead to a better generative model ([Tieleman08]_).
754754
# Plot filters after each training epoch
755755
plotting_start = time.clock()
756756
# Construct image from the weight matrix
757-
image = PIL.Image.fromarray(tile_raster_images( X = rbm.W.value.T,
757+
image = PIL.Image.fromarray(tile_raster_images(
758+
X = rbm.W.get_value(borrow=True).T,
758759
img_shape = (28,28),tile_shape = (10,10),
759760
tile_spacing=(1,1)))
760761
image.save('filters_at_epoch_%i.png'%epoch)
@@ -781,11 +782,13 @@ each plotting.
781782
#################################
782783

783784
# find out the number of test samples
784-
number_of_test_samples = test_set_x.value.shape[0]
785+
number_of_test_samples = test_set_x.get_value(borrow=True).shape[0]
785786

786787
# pick random test examples, with which to initialize the persistent chain
787788
test_idx = rng.randint(number_of_test_samples-20)
788-
persistent_vis_chain = theano.shared(test_set_x.value[test_idx:test_idx+20])
789+
persistent_vis_chain = theano.shared(numpy.asarray(
790+
test_set_x.get_value(borrow=True)[test_idx:test_idx+20],
791+
dtype=theano.config.floatX))
789792

790793
Next we create the 20 persistent chains in parallel to get our
791794
samples. To do so, we compile a theano function which performs one Gibbs step
@@ -797,12 +800,13 @@ samples at every 1000 steps.
797800

798801

799802
# find out the number of test
800-
number_of_test_samples = test_set_x.value.shape[0]
803+
number_of_test_samples = test_set_x.get_value(borrow=True).shape[0]
801804

802805
# pick random test examples, with which to initialize the persistent chain
803806
test_idx = rng.randint(number_of_test_samples-n_chains)
804-
persistent_vis_chain = theano.shared(
805-
numpy.array(test_set_x.value[test_idx:test_idx+100], dtype=theano.config.floatX))
807+
persistent_vis_chain = theano.shared(numpy.array(
808+
test_set_x.get_value(borrow=True)[test_idx:test_idx+100],
809+
dtype=theano.config.floatX))
806810

807811
plot_every = 1000
808812
# define one step of Gibbs sampling (mf = mean-field)

0 commit comments

Comments
 (0)