Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ReLU6.lua - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: be8985bb5de1b58fc6fc1c77ffeb2e27c932afcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
local ReLU6, parent = torch.class('nn.ReLU6', 'nn.Module')

function ReLU6:__init(inplace)
   parent.__init(self)
   
   if inplace == nil then
      self.inplace = false
   else
      self.inplace = inplace
   end

   if (inplace and type(inplace) ~= 'boolean') then
      error('in-place flag must be boolean')
   end
end

function ReLU6:updateOutput(input)
   input.THNN.HardTanh_updateOutput(
      input:cdata(),
      self.output:cdata(),
      0, 6, self.inplace)
   return self.output
end

function ReLU6:updateGradInput(input, gradOutput)
   input.THNN.HardTanh_updateGradInput(
      input:cdata(),
      gradOutput:cdata(),
      self.gradInput:cdata(),
      0, 6, self.inplace)
   return self.gradInput
end