[英]Approximating a sine function with tflearn
I am attempting a ridiculously simplistic approximation of a sine function using tflearn, inspired by this paper. 我试图用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)
But I keep running into a 但我一直遇到
ValueError: Cannot feed value of shape (10,) for Tensor u'InputData/X:0', which has shape '(?, 10, 10000)'
ValueError:无法为形状为'(?,10,10000)'的Tensor u'InputData / X:0'输入形状(10,)的值
error. 错误。
Any ideas on where I am going wrong? 关于我要去哪里的任何想法?
Thank you! 谢谢!
UPDATE : I was not assigning a shape to the x = np.linspace(-np.pi,np.pi,10000)
tensor: 更新 :我没有为
x = np.linspace(-np.pi,np.pi,10000)
张量分配形状:
Solved (@lejlot) by changing the line to np.linspace(-np.pi,np.pi,10000).reshape(-1, 1)
通过将行更改为
np.linspace(-np.pi,np.pi,10000).reshape(-1, 1)
(-1,1)来解决(@lejlot np.linspace(-np.pi,np.pi,10000).reshape(-1, 1)
In the line input_data(shape=[10,10000])
the shape of each input tensor is actually [None,1] and so changing this line to net = tflearn.input_data(shape=[None,1]) solved the issue in the end. 在
input_data(shape=[10,10000])
行中,每个输入张量的形状实际上为[None,1],因此将该行更改为net = tflearn.input_data(shape = [None,1])解决了以下问题:结束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.