-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds SpatialSoftMaxCUDNN from VisualComputingInstitute/Beacon8#13.
Credit also goes to Ilya Kostrikov.
- Loading branch information
1 parent
15d0fbf
commit 1b9b903
Showing
2 changed files
with
22 additions
and
0 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 |
---|---|---|
@@ -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) |
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