问题
I'm write a code in my data test, but have error in shape. my matrix "X" contains 4 columns and 3824 lines. I want to predict the dose of radiation in a certain place with 4 inputs and 1 output In the future I will increase the entries but I want to do a test with this database first
using example: https://github.com/tflearn/tflearn/blob/master/examples/images/dnn.py
code:
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")
messager error:
(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)'
Please help?
来源:https://stackoverflow.com/questions/42317586/error-with-shape-in-tflearnneural-network