Reputation: 241
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)]
Thanks in advance
Upvotes: 2
Views: 1645
Reputation: 2201
The RepeatVector
is there for this purpose (see Keras documentation).
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
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))
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.
Upvotes: 2