Skip to content

Commit

Permalink
Adds SpatialSoftMaxCUDNN from VisualComputingInstitute/Beacon8#13.
Browse files Browse the repository at this point in the history
Credit also goes to Ilya Kostrikov.
  • Loading branch information
lucasb-eyer committed Aug 31, 2015
1 parent 15d0fbf commit 1b9b903
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions DeepFried2/layers/SpatialSoftMaxCUDNN.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from .Module import Module

import theano.sandbox.cuda.dnn as _dnn
import theano.sandbox.cuda.basic_ops as _cuops


def spatial_softmax(img, algo, mode):
img = _cuops.gpu_contiguous(img)
return _dnn.GpuDnnSoftmax(tensor_format='bc01', algo=algo, mode=mode)(img)


class SpatialSoftMaxCUDNN(Module):
def __init__(self, algo='accurate', mode='channel'):
# algo: 'fast' is straightforward softmax, 'accurate' is shifting inputs to avoid overflow.
# mode: 'instance' is a softmax per image (across C,W,H), 'channel' is a softmax per pixel per image (across C).
Module.__init__(self)
self.algo = algo
self.mode = mode

def symb_forward(self, symb_input):
return spatial_softmax(symb_input, self.algo, self.mode)
1 change: 1 addition & 0 deletions DeepFried2/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
from .SpatialMaxPooling import *
from .SpatialConvolutionCUDNN import *
from .SpatialMaxPoolingCUDNN import *
from .SpatialSoftMaxCUDNN import *

0 comments on commit 1b9b903

Please sign in to comment.