Tensorflow/TFLearn 中的数据结构差异
Data Structure Discrepancy in Tensorflow/TFLearn
我有两个数据集,就像:
input:
array([[[ 0.99309823],
...
[ 0. ]]])
shape : (1, 2501)
output:
array([[0, 0, 0, ..., 0, 0, 1],
...,
[0, 0, 0, ..., 0, 0, 0]])
shape : (2501, 9)
然后我用TFLearn处理了它;作为
input_layer = tflearn.input_data(shape=[None,2501])
hidden1 = tflearn.fully_connected(input_layer,1205,activation='ReLU', regularizer='L2', weight_decay=0.001)
dropout1 = tflearn.dropout(hidden1,0.8)
hidden2 = tflearn.fully_connected(dropout1,1205,activation='ReLU', regularizer='L2', weight_decay=0.001)
dropout2 = tflearn.dropout(hidden2,0.8)
softmax = tflearn.fully_connected(dropout2,9,activation='softmax')
# Regression with SGD
sgd = tflearn.SGD(learning_rate=0.1,lr_decay=0.96, decay_step=1000)
top_k=tflearn.metrics.Top_k(3)
net = tflearn.regression(softmax,optimizer=sgd,metric=top_k,loss='categorical_crossentropy')
model = tflearn.DNN(net)
model.fit(input,output,n_epoch=10,show_metric=True, run_id='dense_model')
它有效,但不是我想要的方式。这是一个 DNN 模型。我希望当我输入 0.95 时,模型必须给我相应的预测,例如 [0,0,0,0,0,0,0,0,1]。但是,当我想输入0.95时,它说,
ValueError: Cannot feed value of shape (1,) for Tensor 'InputData/X:0', which has shape '(?, 2501)'
当我试图理解时,我意识到我需要 (1,2501) 形状的数据来预测我基于错误的模型。
我想要的是针对输入中的每个元素,预测输出中对应的元素。可以看到,在实例数据集中,
对于[0.99309823],对应的输出为[0,0,0,0,0,0,0,0,1]。我想让 tflearn 像这样训练自己。
我可能有错误的结构化数据或模型(可能是数据集),我解释了所有事情,我需要帮助我真的疯了。
您的输入数据应为 Nx1(N = 样本数)维以存档此转换([0.99309823] --> [0,0, 0,0,0,0,0,0,1])。根据您的输入数据形状,它看起来更有可能包含 1 个 2501 维的样本。
ValueError: Cannot feed value of shape (1,) for Tensor 'InputData/X:0', which has shape '(?, 2501)'
此错误意味着 tensorflow 期望您提供形状为 (,2501) 的向量,但您正在为网络提供形状为 (1,).
的向量
带有虚拟数据的示例修改代码:
import numpy as np
import tflearn
#creating dummy data
input_data = np.random.rand(1, 2501)
input_data = np.transpose(input_data) # now shape is (2501,1)
output_data = np.random.randint(8, size=2501)
n_values = 9
output_data = np.eye(n_values)[output_data]
# checking the shapes
print input_data.shape #(2501,1)
print output_data.shape #(2501,9)
input_layer = tflearn.input_data(shape=[None,1]) # now network is expecting ( Nx1 )
hidden1 = tflearn.fully_connected(input_layer,1205,activation='ReLU', regularizer='L2', weight_decay=0.001)
dropout1 = tflearn.dropout(hidden1,0.8)
hidden2 = tflearn.fully_connected(dropout1,1205,activation='ReLU', regularizer='L2', weight_decay=0.001)
dropout2 = tflearn.dropout(hidden2,0.8)
softmax = tflearn.fully_connected(dropout2,9,activation='softmax')
# Regression with SGD
sgd = tflearn.SGD(learning_rate=0.1,lr_decay=0.96, decay_step=1000)
top_k=tflearn.metrics.Top_k(3)
net = tflearn.regression(softmax,optimizer=sgd,metric=top_k,loss='categorical_crossentropy')
model = tflearn.DNN(net)
model.fit(input_data, output_data, n_epoch=10,show_metric=True, run_id='dense_model')
我的朋友也警告过我关于 rcmalli 的同样事情。他说
重塑:
input = tf.reshape(input, (2501,1))
改变
input_layer = tflearn.input_data(shape=[None,2501])
到
input_layer = tflearn.input_data(shape=[None, 1])
可变维度必须是 "None"。在你的错误情况下,2501 是你的数据集的幅度(或其他东西,我从另一个语言翻译而来,但你明白了)。 1 是恒定输入幅度。
我有两个数据集,就像:
input:
array([[[ 0.99309823],
...
[ 0. ]]])
shape : (1, 2501)
output:
array([[0, 0, 0, ..., 0, 0, 1],
...,
[0, 0, 0, ..., 0, 0, 0]])
shape : (2501, 9)
然后我用TFLearn处理了它;作为
input_layer = tflearn.input_data(shape=[None,2501])
hidden1 = tflearn.fully_connected(input_layer,1205,activation='ReLU', regularizer='L2', weight_decay=0.001)
dropout1 = tflearn.dropout(hidden1,0.8)
hidden2 = tflearn.fully_connected(dropout1,1205,activation='ReLU', regularizer='L2', weight_decay=0.001)
dropout2 = tflearn.dropout(hidden2,0.8)
softmax = tflearn.fully_connected(dropout2,9,activation='softmax')
# Regression with SGD
sgd = tflearn.SGD(learning_rate=0.1,lr_decay=0.96, decay_step=1000)
top_k=tflearn.metrics.Top_k(3)
net = tflearn.regression(softmax,optimizer=sgd,metric=top_k,loss='categorical_crossentropy')
model = tflearn.DNN(net)
model.fit(input,output,n_epoch=10,show_metric=True, run_id='dense_model')
它有效,但不是我想要的方式。这是一个 DNN 模型。我希望当我输入 0.95 时,模型必须给我相应的预测,例如 [0,0,0,0,0,0,0,0,1]。但是,当我想输入0.95时,它说,
ValueError: Cannot feed value of shape (1,) for Tensor 'InputData/X:0', which has shape '(?, 2501)'
当我试图理解时,我意识到我需要 (1,2501) 形状的数据来预测我基于错误的模型。
我想要的是针对输入中的每个元素,预测输出中对应的元素。可以看到,在实例数据集中,
对于[0.99309823],对应的输出为[0,0,0,0,0,0,0,0,1]。我想让 tflearn 像这样训练自己。
我可能有错误的结构化数据或模型(可能是数据集),我解释了所有事情,我需要帮助我真的疯了。
您的输入数据应为 Nx1(N = 样本数)维以存档此转换([0.99309823] --> [0,0, 0,0,0,0,0,0,1])。根据您的输入数据形状,它看起来更有可能包含 1 个 2501 维的样本。
ValueError: Cannot feed value of shape (1,) for Tensor 'InputData/X:0', which has shape '(?, 2501)'
此错误意味着 tensorflow 期望您提供形状为 (,2501) 的向量,但您正在为网络提供形状为 (1,). 的向量
带有虚拟数据的示例修改代码:
import numpy as np
import tflearn
#creating dummy data
input_data = np.random.rand(1, 2501)
input_data = np.transpose(input_data) # now shape is (2501,1)
output_data = np.random.randint(8, size=2501)
n_values = 9
output_data = np.eye(n_values)[output_data]
# checking the shapes
print input_data.shape #(2501,1)
print output_data.shape #(2501,9)
input_layer = tflearn.input_data(shape=[None,1]) # now network is expecting ( Nx1 )
hidden1 = tflearn.fully_connected(input_layer,1205,activation='ReLU', regularizer='L2', weight_decay=0.001)
dropout1 = tflearn.dropout(hidden1,0.8)
hidden2 = tflearn.fully_connected(dropout1,1205,activation='ReLU', regularizer='L2', weight_decay=0.001)
dropout2 = tflearn.dropout(hidden2,0.8)
softmax = tflearn.fully_connected(dropout2,9,activation='softmax')
# Regression with SGD
sgd = tflearn.SGD(learning_rate=0.1,lr_decay=0.96, decay_step=1000)
top_k=tflearn.metrics.Top_k(3)
net = tflearn.regression(softmax,optimizer=sgd,metric=top_k,loss='categorical_crossentropy')
model = tflearn.DNN(net)
model.fit(input_data, output_data, n_epoch=10,show_metric=True, run_id='dense_model')
我的朋友也警告过我关于 rcmalli 的同样事情。他说 重塑:
input = tf.reshape(input, (2501,1))
改变
input_layer = tflearn.input_data(shape=[None,2501])
到
input_layer = tflearn.input_data(shape=[None, 1])
可变维度必须是 "None"。在你的错误情况下,2501 是你的数据集的幅度(或其他东西,我从另一个语言翻译而来,但你明白了)。 1 是恒定输入幅度。