![](https://csdnimg.cn/release/download_crawler_static/86342472/bg3.jpg)
def shared_dataset(data_xy):
""" Function that loads the dataset into shared variables
The reason we store our dataset in shared variables is to allow
Theano to copy it into the GPU memory (when code is run on GPU).
Since copying data into the GPU is slow, copying a minibatch
everytime
is needed (the default behaviour if the data is not in a shared
variable) would lead to a large decrease in performance.
"""
data_x, data_y = data_xy
shared_x = theano.shared(numpy.asarray(data_x,
dtype=theano.config.floatX))
shared_y = theano.shared(numpy.asarray(data_y,
dtype=theano.config.floatX))
# 往 GPU 中保存的数据必须是 floats 格式的,因此上面的数据都被转变成
floatX 格式的(data_x 和
# data_y 都是同样的操作),y 被处理后还要作为 index,因此还要把 y
变为整数(见下面的操作)。
return shared_x, T.cast(shared_y, 'int32')
test_set_x, test_set_y = shared_dataset(test_set)
valid_set_x, valid_set_y = shared_dataset(valid_set)
train_set_x, train_set_y = shared_dataset(train_set)
batch_size = 500 # size of the minibatch
# accessing the third minibatch of the training set
data = train_set_x[2 * 500: 3 * 500]
label = train_set_y[2 * 500: 3 * 500]
符号
数据集符号