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 (t
(data_xy, borrow=True)
| 220 | # to the example with the same index in the input. |
| 221 | |
| 222 | def shared_dataset(data_xy, borrow=True): |
| 223 | """ Function that loads the dataset into shared variables |
| 224 | |
| 225 | The reason we store our dataset in shared variables is to allow |
| 226 | Theano to copy it into the GPU memory (when code is run on GPU). |
| 227 | Since copying data into the GPU is slow, copying a minibatch everytime |
| 228 | is needed (the default behaviour if the data is not in a shared |
| 229 | variable) would lead to a large decrease in performance. |
| 230 | """ |
| 231 | data_x, data_y = data_xy |
| 232 | shared_x = theano.shared(numpy.asarray(data_x, |
| 233 | dtype=theano.config.floatX), |
| 234 | borrow=borrow) |
| 235 | shared_y = theano.shared(numpy.asarray(data_y, |
| 236 | dtype=theano.config.floatX), |
| 237 | borrow=borrow) |
| 238 | # When storing data on the GPU it has to be stored as floats |
| 239 | # therefore we will store the labels as ``floatX`` as well |
| 240 | # (``shared_y`` does exactly that). But during our computations |
| 241 | # we need them as ints (we use labels as index, and if they are |
| 242 | # floats it doesn't make sense) therefore instead of returning |
| 243 | # ``shared_y`` we will have to cast it to int. This little hack |
| 244 | # lets ous get around this issue |
| 245 | return shared_x, T.cast(shared_y, 'int32') |
| 246 | |
| 247 | test_set_x, test_set_y = shared_dataset(test_set) |
| 248 | valid_set_x, valid_set_y = shared_dataset(valid_set) |