Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
SparseConvNet
Commits
1eb86da8
Commit
1eb86da8
authored
Feb 19, 2018
by
Benjamin Thomas Graham
Browse files
Add Dropout and BatchwiseDropout
parent
829a655f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
PyTorch/sparseconvnet/dropout.py
PyTorch/sparseconvnet/dropout.py
+46
-0
No files found.
PyTorch/sparseconvnet/dropout.py
0 → 100644
View file @
1eb86da8
# Copyright 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
from
torch.autograd
import
Function
,
Variable
from
torch.nn
import
Module
from
.utils
import
*
from
.sparseConvNetTensor
import
SparseConvNetTensor
class
Dropout
(
Module
):
def
__init__
(
self
,
p
=
0.5
):
Module
.
__init__
(
self
)
self
.
p
=
p
def
forward
(
self
,
input
):
output
=
SparseConvNetTensor
()
i
=
input
.
features
if
self
.
training
:
m
=
i
.
new
().
resize_
(
1
).
expand_as
(
i
).
fill_
(
1
-
self
.
p
)
output
.
features
=
i
*
torch
.
bernoulli
(
m
)
else
:
output
.
features
=
i
*
(
1
-
self
.
p
)
output
.
metadata
=
input
.
metadata
output
.
spatial_size
=
input
.
spatial_size
return
output
def
input_spatial_size
(
self
,
out_size
):
return
out_size
class
BatchwiseDropout
(
Module
):
def
__init__
(
self
,
p
=
0.5
):
Module
.
__init__
(
self
)
self
.
p
=
p
def
forward
(
self
,
input
):
output
=
SparseConvNetTensor
()
i
=
input
.
features
if
self
.
training
:
m
=
i
.
new
().
resize_
(
1
).
expand
(
1
,
i
.
shape
[
1
]).
fill_
(
1
-
self
.
p
)
output
.
features
=
i
*
torch
.
bernoulli
(
m
)
else
:
output
.
features
=
i
*
(
1
-
self
.
p
)
output
.
metadata
=
input
.
metadata
output
.
spatial_size
=
input
.
spatial_size
return
output
def
input_spatial_size
(
self
,
out_size
):
return
out_size
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment