java根据数据生成畸形图_Tensorflow RNN输出张量形状

我对张量流非常陌生,我不知道如何塑造张量,以便我将输出作为单个数字 . 基本上,我的经常性网络应该猜测下一个数字 . 相反,对于每个预测,它返回一个包含五个数字的列表?我猜我的一个或多个张量都是畸形的 .

我的输入数据被格式化为大约2000个列表,其中包含5个功能,每个功能如下:

[

np.array ([

[1],[2],[3],[4],[5]

])

]

这是RNN的代码:

cell_units = 400

batch_size = 5

no_of_epochs = 500

data = tf.placeholder (tf.float32, [None, 5, 1])

target = tf.placeholder (tf.float32, [None, 1, 1])

weight = tf.Variable (tf.random_normal ([cell_units, 5, 1]))

bias = tf.Variable (tf.random_normal([1, 1]))

cell = tf.contrib.rnn.BasicRNNCell (num_units = cell_units)

output, states = tf.nn.dynamic_rnn (cell, data, dtype=tf.float32)

output = tf.transpose (output, [1, 0, 2])

activation = tf.matmul (output, weight) + bias

cost = tf.reduce_mean (

(

tf.log (tf.square (activation - target))

)

)

optimizer = tf.train.AdamOptimizer (learning_rate = 0.01).minimize(cost)

with tf.Session () as sess:

sess.run (tf.global_variables_initializer ())

no_of_batches = int (len (train_x) / batch_size)

for i in range(no_of_epochs):

start = 0

for j in range(no_of_batches):

inp = train_x [start:start+batch_size]

out = train_y [start:start+batch_size]

start += batch_size

sess.run (optimizer, {data: inp, target: out})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值