无需使用 .pkl 文件即可将 Theano 教程中的代码改编为您自己的数据。你只需要模仿他们的数据结构。
快速解决
查找以下几行。这是第 303 行DBN.py.
datasets = load_data(dataset)
train_set_x, train_set_y = datasets[0]
替换成你自己的train_set_x
and train_set_y
.
my_x = []
my_y = []
with open('path_to_file', 'r') as f:
for line in f:
my_list = line.split(' ') # replace with your own separator instead
my_x.append(my_list[1:-1]) # omitting identifier in [0] and target in [-1]
my_y.append(my_list[-1])
train_set_x = theano.shared(numpy.array(my_x, dtype='float64'))
train_set_y = theano.shared(numpy.array(my_y, dtype='float64'))
使其适应您的输入数据和您正在使用的代码。
同样的事情适用于cA.py, dA.py and SdA.py但他们只使用train_set_x
.
寻找诸如以下的地方n_ins=28 * 28
其中 mnist 图像大小是硬编码的。代替28 * 28
用你自己的列数。
解释
您可以在此处以 Theano 可以使用的格式放置数据。
train_set_x = theano.shared(numpy.array(my_x, dtype='float64'))
train_set_y = theano.shared(numpy.array(my_y, dtype='float64'))
shared()
将 numpy 数组转换为 Theano 格式,旨在提高 GPU 效率。
dtype='float64'
预计在 Theano 数组中。
更多详情请参阅基本张量功能.
.pkl 文件
.pkl 文件是保存数据结构的一种方法。
您可以创建自己的。
import cPickle
f = file('my_data.pkl', 'wb')
cPickle.dump((train_set_x, train_set_y), f, protocol=cPickle.HIGHEST_PROTOCOL)
f.close()
更多详情请参阅加载和保存.