-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced CRLF with LF line endings. All other files use UNIX style line endings.
- Loading branch information
Showing
3 changed files
with
239 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
local Power, parent = torch.class('nn.Power','nn.Module') | ||
|
||
function Power:__init(p) | ||
parent.__init(self) | ||
self.pow = p | ||
if not p then | ||
error('nn.Power(power)') | ||
end | ||
end | ||
|
||
function Power:updateOutput(input) | ||
self.output:resizeAs(input):copy(input) | ||
self.output:pow(self.pow) | ||
return self.output | ||
end | ||
|
||
function Power:updateGradInput(input, gradOutput) | ||
self.gradInput:resizeAs(input):copy(input) | ||
self.gradInput:pow(self.pow - 1) | ||
self.gradInput:cmul(gradOutput):mul(self.pow) | ||
return self.gradInput | ||
end | ||
local Power, parent = torch.class('nn.Power','nn.Module') | ||
|
||
function Power:__init(p) | ||
parent.__init(self) | ||
self.pow = p | ||
if not p then | ||
error('nn.Power(power)') | ||
end | ||
end | ||
|
||
function Power:updateOutput(input) | ||
self.output:resizeAs(input):copy(input) | ||
self.output:pow(self.pow) | ||
return self.output | ||
end | ||
|
||
function Power:updateGradInput(input, gradOutput) | ||
self.gradInput:resizeAs(input):copy(input) | ||
self.gradInput:pow(self.pow - 1) | ||
self.gradInput:cmul(gradOutput):mul(self.pow) | ||
return self.gradInput | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
local SpatialUpSamplingNearest, parent = torch.class('nn.SpatialUpSamplingNearest', 'nn.Module') | ||
|
||
--[[ | ||
Applies a 2D up-sampling over an input image composed of several input planes. | ||
The upsampling is done using the simple nearest neighbor technique. | ||
The Y and X dimensions are assumed to be the last 2 tensor dimensions. For | ||
instance, if the tensor is 4D, then dim 3 is the y dimension and dim 4 is the x. | ||
owidth = width*scale_factor | ||
oheight = height*scale_factor | ||
--]] | ||
|
||
function SpatialUpSamplingNearest:__init(scale) | ||
parent.__init(self) | ||
|
||
self.scale_factor = scale | ||
if self.scale_factor < 1 then | ||
error('scale_factor must be greater than 1') | ||
end | ||
if math.floor(self.scale_factor) ~= self.scale_factor then | ||
error('scale_factor must be integer') | ||
end | ||
self.inputSize = torch.LongStorage(4) | ||
self.outputSize = torch.LongStorage(4) | ||
self.usage = nil | ||
end | ||
|
||
function SpatialUpSamplingNearest:updateOutput(input) | ||
if input:dim() ~= 4 and input:dim() ~= 3 then | ||
error('SpatialUpSamplingNearest only support 3D or 4D tensors') | ||
end | ||
-- Copy the input size | ||
local xdim = input:dim() | ||
local ydim = input:dim() - 1 | ||
for i = 1, input:dim() do | ||
self.inputSize[i] = input:size(i) | ||
self.outputSize[i] = input:size(i) | ||
end | ||
self.outputSize[ydim] = self.outputSize[ydim] * self.scale_factor | ||
self.outputSize[xdim] = self.outputSize[xdim] * self.scale_factor | ||
-- Resize the output if needed | ||
if input:dim() == 3 then | ||
self.output:resize(self.outputSize[1], self.outputSize[2], | ||
self.outputSize[3]) | ||
else | ||
self.output:resize(self.outputSize) | ||
end | ||
input.nn.SpatialUpSamplingNearest_updateOutput(self, input) | ||
return self.output | ||
end | ||
|
||
function SpatialUpSamplingNearest:updateGradInput(input, gradOutput) | ||
self.gradInput:resizeAs(input) | ||
input.nn.SpatialUpSamplingNearest_updateGradInput(self, input, gradOutput) | ||
return self.gradInput | ||
end | ||
local SpatialUpSamplingNearest, parent = torch.class('nn.SpatialUpSamplingNearest', 'nn.Module') | ||
|
||
--[[ | ||
Applies a 2D up-sampling over an input image composed of several input planes. | ||
The upsampling is done using the simple nearest neighbor technique. | ||
The Y and X dimensions are assumed to be the last 2 tensor dimensions. For | ||
instance, if the tensor is 4D, then dim 3 is the y dimension and dim 4 is the x. | ||
owidth = width*scale_factor | ||
oheight = height*scale_factor | ||
--]] | ||
|
||
function SpatialUpSamplingNearest:__init(scale) | ||
parent.__init(self) | ||
|
||
self.scale_factor = scale | ||
if self.scale_factor < 1 then | ||
error('scale_factor must be greater than 1') | ||
end | ||
if math.floor(self.scale_factor) ~= self.scale_factor then | ||
error('scale_factor must be integer') | ||
end | ||
self.inputSize = torch.LongStorage(4) | ||
self.outputSize = torch.LongStorage(4) | ||
self.usage = nil | ||
end | ||
|
||
function SpatialUpSamplingNearest:updateOutput(input) | ||
if input:dim() ~= 4 and input:dim() ~= 3 then | ||
error('SpatialUpSamplingNearest only support 3D or 4D tensors') | ||
end | ||
-- Copy the input size | ||
local xdim = input:dim() | ||
local ydim = input:dim() - 1 | ||
for i = 1, input:dim() do | ||
self.inputSize[i] = input:size(i) | ||
self.outputSize[i] = input:size(i) | ||
end | ||
self.outputSize[ydim] = self.outputSize[ydim] * self.scale_factor | ||
self.outputSize[xdim] = self.outputSize[xdim] * self.scale_factor | ||
-- Resize the output if needed | ||
if input:dim() == 3 then | ||
self.output:resize(self.outputSize[1], self.outputSize[2], | ||
self.outputSize[3]) | ||
else | ||
self.output:resize(self.outputSize) | ||
end | ||
input.nn.SpatialUpSamplingNearest_updateOutput(self, input) | ||
return self.output | ||
end | ||
|
||
function SpatialUpSamplingNearest:updateGradInput(input, gradOutput) | ||
self.gradInput:resizeAs(input) | ||
input.nn.SpatialUpSamplingNearest_updateGradInput(self, input, gradOutput) | ||
return self.gradInput | ||
end |
Oops, something went wrong.