0

My network have N layers, and I want the last layer simply construct last output as previous layers' output multiply like below. Suppose my the N-1 layer has a 3-d output, the last has a has a 2-d output. the last_output[1] = previous_output[1]*previous_output[2], last_output[2] = previous_output[3]. And I want to use a CrossEntropyCriterion on this 2-d last_output. Now I achieve this by construct the N-1 network model and get the last output as below:

local last_output = torch.ones(previous_output:size()[1], 2)
last_output[{{}, {1}}] = torch.cmul(previous_output[{{},{1}}], previous_output[{{},{2}}])
last_output[{{}, {2}}] = previous_output[{{}, {3}}]

So the last layer are not in the modle, and when simply run

loss = criterion:forward(last_output, target)

Error occur. Is there any trick to achieve the purpose?

Shai
  • 111,146
  • 38
  • 238
  • 371
ZT.Zhu
  • 11
  • 1

1 Answers1

1

The best way to do that is to write a customized layer. See more from torch developer docs.

Chen
  • 64
  • 1
  • 1
  • 3