如何用2D输出训练网络? (蟒蛇,凯拉斯) [英] How to train network with 2D output? (python,Keras)
问题描述
我想训练一个回归网络,其输出是两个坐标(x1,y1)和(x2,y2). 我的问题是:如果我想训练网络,我的输出应该分开吗? 我的意思是我的输出应该像这样:
I want to train a regression network which its outputs are two coordinates (x1,y1) and (x2,y2). my question is: if I want to train network should my output be separated? I mean should my output like this:
[x1,y1,x2,y2]
或者有没有办法像这样堆叠它们:
or is there a way to stack them like:
[(x1,y1),(x2,y2)]
预先感谢
推荐答案
The RepeatVector
is there for this purpose (see Keras documentation).
您希望输出形状为(2, 2)
,或者是两个坐标且每个都有两个条目的数组.
You want your output shape to be (2, 2)
, or an array of two coordinates with two entries each.
num_outputs = 2
num_elements = 2
添加用于处理网络输入的图层后,添加RepeatVector
.这样就可以获取数据数组作为输出.最后一层需要输出num_elements
,例如:
After you have added layers for processing input to your network, add a RepeatVector
. This will make it possible to get an array of data as output. Your final layer needs to output num_elements
so for example:
model.add(RepeatVector(num_outputs))
# Optional layers can be inserted here
model.add(Dense(num_elements))
简而言之,重复矢量将复制要发送到其他节点的上一层的内容,每个路径将输出一个num_elements
数组,从而为您提供所需的输出形状.请注意,您的训练数据(标签)也必须由形状(2, 2)
数组组成.
In a nutshell, repeat vectors copy the content of the previous layer to be sent to further nodes, and each path will output an array of num_elements
, giving you the desired output shape. Note that your training data (labels) has to consist of shape (2, 2)
arrays also.
这篇关于如何用2D输出训练网络? (蟒蛇,凯拉斯)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!