tflearn(神经网络)中的形状错误

时间:2017-02-18 16:18:46

标签: python-3.x tensorflow neural-network tflearn

我在我的数据测试中编写了一个代码,但是在形状上有错误。 我的矩阵“X”包含4列和3824行。 我想用4输入和1输出来预测某个地方的辐射剂量 将来我会增加条目,但我想先用这个数据库进行测试

使用示例:https://github.com/tflearn/tflearn/blob/master/examples/images/dnn.py

代码:

from __future__ import division, print_function, absolute_import

import tflearn
from sklearn import preprocessing
import Planilha as pl

X, Y = pl.dados('TR')
testX, testY = pl.dados('t')

scaler = preprocessing.StandardScaler()
X = scaler.fit_transform(X)
testX = scaler.fit_transform(testX)

m = X.shape[0]
n = X.shape[1]
print(X.shape)
print(Y.shape)

# Building deep neural network
input_layer = tflearn.input_data(shape=[None, 4]) 
dense1 = tflearn.fully_connected(input_layer, 1, activation='tanh',
                             regularizer='L2', weight_decay=0.001)
dropout1 = tflearn.dropout(dense1, 0.8)
dense2 = tflearn.fully_connected(dropout1, 1, activation='tanh',
                             regularizer='L2', weight_decay=0.001)
dropout2 = tflearn.dropout(dense2, 0.8)
softmax = tflearn.fully_connected(dropout2, 10, activation='softmax')

# Regression using SGD with learning rate decay and Top-3 accuracy
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')

# Training
model = tflearn.DNN(net, tensorboard_verbose=0)
model.fit(X, Y, n_epoch=20, validation_set=(testX, testY),
      show_metric=True, run_id="dense_model")
消息错误:

(3824, 4)
(3824, 1)
---------------------------------
Run id: dense_model  
Log directory: /tmp/tflearn_logs/
---------------------------------
Training samples: 3824
Validation samples: 2448
--
--
Traceback (most recent call last):
 File "Dose/Deep_MNIST.py", line 53, in <module>
   show_metric=True, run_id="dense_model")
 File "/home/filipe/.local/lib/python3.5/site-packages/tflearn/models/dnn.py", line 188, in fit run_id=run_id)
  File "/home/filipe/.local/lib/python3.5/site-packages/tflearn/helpers/trainer.py", line 277, in fit show_metric)
 File "/home/filipe/.local/lib/python3.5/site-packages/tflearn/helpers/trainer.py", line 684, in _train
feed_batch)
File "/home/filipe/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 710, in run run_metadata_ptr)
File "/home/filipe/.local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 887, in _run % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
 ValueError: Cannot feed value of shape (64, 4) for Tensor 'InputData/X:0', which has shape '(?, 3824, 4)'

请帮帮忙?

0 个答案:

没有答案