Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions CIFAR_10/models/nin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import torch.nn.functional as F

class BinActive(torch.autograd.Function):
'''
Binarize the input activations and calculate the mean across channel dimension.
'''
@staticmethod
def forward(self, input):
self.save_for_backward(input)
size = input.size()
mean = torch.mean(input.abs(), 1, keepdim=True)
input = input.sign()
return input, mean

@staticmethod
def backward(self, grad_output, grad_output_mean):
input, = self.saved_tensors
grad_input = grad_output.clone()
Expand Down Expand Up @@ -40,7 +38,7 @@ def __init__(self, input_channels, output_channels,

def forward(self, x):
x = self.bn(x)
x, mean = BinActive()(x)
x, mean = BinActive.apply(x)
if self.dropout_ratio!=0:
x = self.dropout(x)
x = self.conv(x)
Expand Down
Loading