gpt4 book ai didi

python - 如何用包含训练数据的矩阵替换输入数据

转载 作者:行者123 更新时间:2023-12-01 06:56:09 24 4
gpt4 key购买 nike

我有深度神经网络,它按以下方式进行训练:

# Training and testing phases
with tf.Session() as sess:
# Training
sess.run(init)
for epoch in range(1001):
avg_cost = 0.
for index_m in range(20):
input_samples = []
input_labels = []
for index_k in range(0, 1000):
bits = np.random.binomial(n=1, p=0.5, size=(10,))
input_data = input_funct(bits, SNR)
input_labels.append(input_data)
input_samples.append(input)

batch_x = np.asarray(input_samples)
batch_y = np.asarray(input_labels)

_, cs = sess.run([optimizer, cost], feed_dict={X: batch_x,
Y: batch_y,
learning_rate: l_rate})

我的问题是关于这个生成的数据input_data = input_funct(bits, SNR):它将生成多少次?正如我所见,它将在三个 for 循环 之后生成:1001*20*1000 = 20000000 次,对吗?假设列的大小 = 10;现在,如果我已经将数据作为相同大小的矩阵生成并导入为大小为 (20000000,10) 的文件,我需要将其放在 input_data 的位置并逐列进行训练。我怎样才能做到这一点?当然,bits = np.random.binomial(n=1, p=0.5, size=(10,)) 的命令将以类似的方式导入,而不是在这里随机生成。

通常我想为所有列添加新的 for 循环,但我不知道在哪里以及如何添加,因为我是 python 编程的新手。

谢谢

编辑:

这样怎么样,我添加了另一个总大小的循环,然后添加了其中的其他循环。

# Training and testing phases
#label is the imported matrix of size(10 x 20000000)
#data is the imported matrix of size(10 x 20000000)
with tf.Session() as sess:
# Training
sess.run(init)
for j in range(1001*20*1000)
for epoch in range(1001):
avg_cost = 0.
for index_m in range(20):
input_samples = []
input_labels = []
for index_k in range(0, 1000):
bits = label(:,j)
input_data = data(:,j)
input_labels.append(input_data)
input_samples.append(input)

batch_x = np.asarray(input_samples)
batch_y = np.asarray(input_labels)

_, cs = sess.run([optimizer, cost], feed_dict={X: batch_x,
Y: batch_y,
learning_rate: l_rate})

最佳答案

TWENTY_MILLION_TIMES_TEN_ARRAY = open('hi.txt','r').read()
np.reshape(TWENTY_MILLION_TIMES_TEN_ARRAY,(1001,20,1000))
# Training and testing phases
j = 0 # example
with tf.Session() as sess:
# Training
sess.run(init)
for epoch in list(TWENTY_MILLION_TIMES_TEN_ARRAY):
avg_cost = 0.
for index_m in list(epoch):
input_samples = []
input_labels = []
for index_k in list(index_m):
'''whatever you do with that data and label'''
# input[j] blah blah....
j += 1

batch_x = np.asarray(input_samples)
batch_y = np.asarray(input_labels)

_, cs = sess.run([optimizer, cost], feed_dict={X: batch_x,
Y: batch_y,
learning_rate: l_rate})

这就是我要做的, reshape 数组并将其传递下去。

您还可以首先以该格式生成数据,这样您甚至不必重新调整它的形状。

希望有帮助:)

关于python - 如何用包含训练数据的矩阵替换输入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58797572/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com