0

我正在我的数据测试中编写代码,但形状有误。我的矩阵“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)'

请帮忙?

4

0 回答 0