Accessing Anano Shared Variable Data

I successfully loaded the MNIST dataset into Theano shared variables as follows

# Read MNIST dataset from gzipped file as binary
f = gzip.open('mnist.pkl.gz', 'rb')
# Store dataset into variable
train_set = cPickle.load(f)
# Close zipped file
f.close()
# Store data in Theano shared variable
train_set_x = theano.shared(numpy.asarray(train_set, dtype=theano.config.floatX)) # Data
train_set_y = theano.shared(numpy.asarray(train_set, dtype=theano.config.floatX)) # Labels
# Cast labels into int
train_set_y = theano.tensor.cast(train_set_y, 'int32')

My question is: how do I access data in train_set_x and train_set_y. Each image in the data set is 28 * 28 pixels. This is a vector of length 784 with all the elements in the vector as floating values ​​representing values ​​from 0.0 to 1.0 inclusive. Labels are embedded in int because it represents a label associated with each vector image and represents a value from 0 to 9. I want to be able to iterate through the images of the train_set_x matrix and the train_set_y labels to view the data of each image and its label separately and ultimately display images on the screen.

+4
2

-, train_set_x train_set_y ( ) train_set . , , , train_set_x - , train_set_y - , .

mnist.pkl.gz. ? Deep Learning? , train_set 2d numpy ndarray. mnist.pkl.gz, DLT.

train_set_x.get_value(), ndarray . , train_set_x.get_value(borrow=True), . , CPU, , CPU.

train_set_y Theano, Theano shared. get_value() . , train_set_y. , train_set_y.eval() , , .

, :

for x,y in zip(train_set_x.get_value(), train_set_y.eval()):
   print x, y
+3

@Nouiz train_set_x, train_set_y. "DYLD_FALLBACK_LIBRARY_PATH", . python Mac. , XCode. , python.org, , anaconda. python anaconda c- theanano. - , python. , .bash_profile . , anaconda, DYLD_FALLBACK_LIBRARY_PATH = "/Users/Me/anaconda/lib". , .

+1

All Articles