我正在尝试将一个非常大的数据集(在ndarray中的内存为28 of )分配到theano共享变量中,使用borrow=True来避免内存的复制。为了做到这一点,我使用以下函数:
def load_dataset(path):
# Load dataset from memory
data_f = np.load(path+'train_f.npy')
data_t = np.load(path+'train_t.npy')
# Split into training and validation
return (
(
theano.shared(data_f[:-1000, :], borrow=True),
theano.shared(data_t[:-1000, :], borrow=True)
), (
theano.shared(data_f[-1000:, :], borrow=True),
theano.shared(data_t[-1000:, :], borrow=True)
)
)为了避免数据转换,在将数组保存到磁盘之前,我已经将它们定义为正确的格式(然后填充它们并用np.save()将它们转储到磁盘中):
data_f = np.ndarray((len(rows), 250*250*3), dtype=theano.config.floatX)
data_t = np.ndarray((len(rows), 1), dtype=theano.config.floatX)不过,看来theano无论如何都要复制内存,抛出以下错误:
分配25594500000字节设备内存(内存不足)时出错。驱动程序报告3775729664字节空闲,4294639616字节总计。
Theano被配置为在GPU (GTX 970)上工作。
发布于 2015-04-15 12:41:20
不使用theano.shared,可以使用theano.tensor._shared强制将数据分配到CPU内存中。固定代码的结果如下:
def load_dataset(path):
# Load dataset from memory
data_f = np.load(path+'train_f.npy')
data_t = np.load(path+'train_t.npy')
# Split into training and validation
return (
(
theano.tensor._shared(data_f[:-1000, :], borrow=True),
theano.tensor._shared(data_t[:-1000, :], borrow=True)
), (
theano.tensor._shared(data_f[-1000:, :], borrow=True),
theano.tensor._shared(data_t[-1000:, :], borrow=True)
)
)https://stackoverflow.com/questions/29649623
复制相似问题