Skip to content

Commit 1b9b903

Browse files
committed
Adds SpatialSoftMaxCUDNN from VisualComputingInstitute/Beacon8#13.
Credit also goes to Ilya Kostrikov.
1 parent 15d0fbf commit 1b9b903

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from .Module import Module
2+
3+
import theano.sandbox.cuda.dnn as _dnn
4+
import theano.sandbox.cuda.basic_ops as _cuops
5+
6+
7+
def spatial_softmax(img, algo, mode):
8+
img = _cuops.gpu_contiguous(img)
9+
return _dnn.GpuDnnSoftmax(tensor_format='bc01', algo=algo, mode=mode)(img)
10+
11+
12+
class SpatialSoftMaxCUDNN(Module):
13+
def __init__(self, algo='accurate', mode='channel'):
14+
# algo: 'fast' is straightforward softmax, 'accurate' is shifting inputs to avoid overflow.
15+
# mode: 'instance' is a softmax per image (across C,W,H), 'channel' is a softmax per pixel per image (across C).
16+
Module.__init__(self)
17+
self.algo = algo
18+
self.mode = mode
19+
20+
def symb_forward(self, symb_input):
21+
return spatial_softmax(symb_input, self.algo, self.mode)

DeepFried2/layers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
from .SpatialMaxPooling import *
1313
from .SpatialConvolutionCUDNN import *
1414
from .SpatialMaxPoolingCUDNN import *
15+
from .SpatialSoftMaxCUDNN import *

0 commit comments

Comments
 (0)