2016-10-10 76 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])最终解决了问题。