2016-10-10 86 views
0

我正在嘗試使用tflearn,受this紙張啓發的正弦函數的一種可笑的簡單逼近。用tflearn逼近正弦函數

import tflearn 
import tensorflow as tf 
import numpy as np 
import matplotlib.pyplot as plt 


# generate cosine function 
x = np.linspace(-np.pi,np.pi,10000) 
y = np.sin(x) 



# Network building 
net = tflearn.input_data(shape=[10,10000]) 
net = tflearn.fully_connected(net, 1000) 
net = tflearn.layers.core.activation (net, activation='relu') 
net = tflearn.regression(net) 


# Define model 
model = tflearn.DNN(net) 
# Start training (apply gradient descent algorithm) 
model.fit(x, y,batch_size=10) 

,但我一直運行到一個

ValueError: Cannot feed value of shape (10,) for Tensor u'InputData/X:0', which has shape '(?, 10, 10000)'

錯誤。

關於我要去哪裏的任何想法都是錯誤的?

謝謝!

+0

如果您在網絡建設的第一行切換10和10000,會發生什麼情況? – kpie

+0

完全一樣的錯誤恐怕 – hdhdhdhdhdh

+0

將'np.linspace(-np.pi,np.pi,10000)'改爲'np.linspace(-np.pi,np.pi,10000).reshape(-1 ,1)' – lejlot

回答

0

UPDATE:我沒有分配形狀與x = np.linspace(-np.pi,np.pi,10000)張量:

通過改變線np.linspace(-np.pi,np.pi,10000).reshape(-1, 1)

在訂單解決(@lejlot)input_data(shape=[10,10000])每個輸入張量的形狀實際上是[None,1],因此將此行更改爲net = tflearn.input_data(shape = [None,1])最終解決了問題。