1

tflearnで提供されるDNNを使用して、データから学習します。これは私にエラーのカップルを与え形状はランク1でなければなりませんが、ランク2になります。エラー

# Target label used for training 
labels = np.array(data[label], dtype=np.float32) 

# Reshape target label from (6605,) to (6605, 1) 
labels = tf.reshape(labels, shape=[-1, 1]) 

# Data for training minus the target label. 
data = np.array(data.drop(label, axis=1), dtype=np.float32) 

# DNN 
net = tflearn.input_data(shape=[None, 32]) 
net = tflearn.fully_connected(net, 32) 
net = tflearn.fully_connected(net, 32) 
net = tflearn.fully_connected(net, 1, activation='softmax') 
net = tflearn.regression(net) 

# Define model. 
model = tflearn.DNN(net) 
model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True) 

、最初は...私のdata変数は(6605, 32)の形状をしており、私のlabelsデータは、私が(6605, 1)に以下のコードで作り直す(6605,)の形状をしています...

tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape must be rank 1 but is rank 2 for 'strided_slice' (op: 'StridedSlice') with input shapes: [6605,1], [1,16], [1,16], [1].

...第二は...

During handling of the above exception, another exception occurred:

ValueError: Shape must be rank 1 but is rank 2 for 'strided_slice' (op: 'StridedSlice') with input shapes: [6605,1], [1,16], [1,16], [1].

私は考えている何rank 1rank 2がありますので、この問題を解決する方法はありません。

+0

「ラベル」の形を変えてみてください。エラーは持続しますか?はい、あなたのデータのサンプルを提供しています(また、このモデルが提供されているリンクは、役に立つと思われます) – desertnaut

答えて

2

Tensorflowでは、rankはテンソルの次元数です(行列のランクには似ていません)。 tflearnは、Tensorflowの上に構築入力がないはずであるので、一例として、次テンソルはまた、テンソルを下記する3

t2 = np.array([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]]) 
print(t2.shape) # prints (2, 2, 3) 

のランクを2

t1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) 
print(t1.shape) # prints (3, 3) 

のランクを有していますテンソルである。私はあなたのコードを次のように変更し、必要なところにコメントしました。

# Target label used for training 
labels = np.array(data[label], dtype=np.float32) 

# Reshape target label from (6605,) to (6605, 1) 
labels =np.reshape(labels,(-1,1)) #makesure the labels has the shape of (?,1) 

# Data for training minus the target label. 
data = np.array(data.drop(label, axis=1), dtype=np.float32) 
data = np.reshape(data,(-1,32)) #makesure the data has the shape of (?,32) 

# DNN 
net = tflearn.input_data(shape=[None, 32]) 
net = tflearn.fully_connected(net, 32) 
net = tflearn.fully_connected(net, 32) 
net = tflearn.fully_connected(net, 1, activation='softmax') 
net = tflearn.regression(net) 

# Define model. 
model = tflearn.DNN(net) 
model.fit(data, labels, n_epoch=10, batch_size=16, show_metric=True) 

これが役に立ちます。

関連する問題