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
d77687a6
Commit
d77687a6
authored
Mar 04, 2018
by
Benjamin Graham
Committed by
Benjamin Thomas Graham
Mar 05, 2018
Browse files
Rename ValidConvolutions to SubmanifoldConvolutions, update for PyTorch 0.4 Tensor/Variable merge
parent
297e04c0
Changes
82
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
80 additions
and
67 deletions
+80
-67
Torch/JoinTable.lua
Torch/JoinTable.lua
+1
-1
Torch/Metadata.lua
Torch/Metadata.lua
+1
-1
Torch/NetworkArchitectures.lua
Torch/NetworkArchitectures.lua
+14
-14
Torch/SubmanifoldConvolution.lua
Torch/SubmanifoldConvolution.lua
+4
-4
Torch/init.lua
Torch/init.lua
+1
-1
examples/Assamese_handwriting/DenseNet.lua
examples/Assamese_handwriting/DenseNet.lua
+1
-1
examples/Assamese_handwriting/DenseNet.py
examples/Assamese_handwriting/DenseNet.py
+1
-1
examples/Assamese_handwriting/ResNet.lua
examples/Assamese_handwriting/ResNet.lua
+1
-1
examples/Assamese_handwriting/ResNet.py
examples/Assamese_handwriting/ResNet.py
+21
-17
examples/Assamese_handwriting/ResNet_legacy.py
examples/Assamese_handwriting/ResNet_legacy.py
+1
-1
examples/Assamese_handwriting/VGGplus.py
examples/Assamese_handwriting/VGGplus.py
+14
-12
examples/Assamese_handwriting/VGGplus_legacy.py
examples/Assamese_handwriting/VGGplus_legacy.py
+7
-3
examples/Assamese_handwriting/data.py
examples/Assamese_handwriting/data.py
+6
-3
examples/Chinese_handwriting/DenseNet-A-VSC.lua
examples/Chinese_handwriting/DenseNet-A-VSC.lua
+1
-1
examples/Chinese_handwriting/DenseNet-A-VSC.py
examples/Chinese_handwriting/DenseNet-A-VSC.py
+1
-1
examples/Chinese_handwriting/DenseNet-B-VSC.lua
examples/Chinese_handwriting/DenseNet-B-VSC.lua
+1
-1
examples/Chinese_handwriting/ResNet-A-VSC.lua
examples/Chinese_handwriting/ResNet-A-VSC.lua
+1
-1
examples/Chinese_handwriting/ResNet-A-VSC.py
examples/Chinese_handwriting/ResNet-A-VSC.py
+1
-1
examples/Chinese_handwriting/ResNet-B-VSC.lua
examples/Chinese_handwriting/ResNet-B-VSC.lua
+1
-1
examples/Chinese_handwriting/ResNet-C-VSC.lua
examples/Chinese_handwriting/ResNet-C-VSC.lua
+1
-1
No files found.
Torch/JoinTable.lua
View file @
d77687a6
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
--[[
--[[
Assume all the inputs have identical SparseGrids and input[i].features:size(1)
Assume all the inputs have identical SparseGrids and input[i].features:size(1)
Assume input[1].features:size(2) >= input[i].features:size(2) for all i=1,#input
Assume input[1].features:size(2) >= input[i].features:size(2) for all i=1,#input
output.
vali
dRules is taken from input[1].
vali
dRules (could do set union?)
output.
submanifol
dRules is taken from input[1].
submanifol
dRules (could do set union?)
(for resnets, make sure the residual link is input[2])
(for resnets, make sure the residual link is input[2])
]]
]]
...
...
Torch/Metadata.lua
View file @
d77687a6
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
Store Metadata relating to which spatial locations are active at each scale.
Store Metadata relating to which spatial locations are active at each scale.
Convolutions and 'convolution reversing' deconvolutions
Convolutions and 'convolution reversing' deconvolutions
all coexist within the same MetaData object as long as each spatial size
all coexist within the same MetaData object as long as each spatial size
only occurs once.
Vali
d convolutions do not change the spatial structure.
only occurs once.
Submanifol
d convolutions do not change the spatial structure.
Serialization is emulated by storing the pointer as an integer.
Serialization is emulated by storing the pointer as an integer.
This is sufficient for mutithreaded batch preparation: each 'serialized'
This is sufficient for mutithreaded batch preparation: each 'serialized'
...
...
Torch/NetworkArchitectures.lua
View file @
d77687a6
...
@@ -45,7 +45,7 @@ return function(sparseconvnet)
...
@@ -45,7 +45,7 @@ return function(sparseconvnet)
function
sparseconvnet
.
SparseVggNet
(
dimension
,
nInputPlanes
,
layers
,
opts
)
function
sparseconvnet
.
SparseVggNet
(
dimension
,
nInputPlanes
,
layers
,
opts
)
--[[
--[[
VGG style nets
VGG style nets
Use
vali
d convolutions
Use
submanifol
d convolutions
Also implements 'Plus'-augmented nets
Also implements 'Plus'-augmented nets
]]
]]
local
nPlanes
=
nInputPlanes
local
nPlanes
=
nInputPlanes
...
@@ -57,20 +57,20 @@ return function(sparseconvnet)
...
@@ -57,20 +57,20 @@ return function(sparseconvnet)
elseif
x
[
1
]
==
'MP'
then
elseif
x
[
1
]
==
'MP'
then
m
:
add
(
sparseconvnet
.
MaxPooling
(
dimension
,
x
[
2
],
x
[
3
]))
m
:
add
(
sparseconvnet
.
MaxPooling
(
dimension
,
x
[
2
],
x
[
3
]))
elseif
x
[
1
]
==
'C'
and
#
x
==
2
then
elseif
x
[
1
]
==
'C'
and
#
x
==
2
then
m
:
add
(
sparseconvnet
.
Vali
dConvolution
(
dimension
,
nPlanes
,
x
[
2
],
3
,
false
))
m
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
nPlanes
,
x
[
2
],
3
,
false
))
nPlanes
=
x
[
2
]
nPlanes
=
x
[
2
]
m
:
add
(
sparseconvnet
.
BatchNormReLU
(
nPlanes
))
m
:
add
(
sparseconvnet
.
BatchNormReLU
(
nPlanes
))
elseif
x
[
1
]
==
'C'
and
#
x
==
3
then
elseif
x
[
1
]
==
'C'
and
#
x
==
3
then
m
:
add
(
sparseconvnet
.
ConcatTable
()
m
:
add
(
sparseconvnet
.
ConcatTable
()
:
add
(
:
add
(
sparseconvnet
.
Sequential
()
sparseconvnet
.
Sequential
()
:
add
(
sparseconvnet
.
Vali
dConvolution
(
dimension
,
nPlanes
,
x
[
2
],
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
nPlanes
,
x
[
2
],
3
,
false
))
)
)
:
add
(
:
add
(
sparseconvnet
.
Sequential
()
sparseconvnet
.
Sequential
()
:
add
(
sparseconvnet
.
Convolution
(
dimension
,
nPlanes
,
x
[
3
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
Convolution
(
dimension
,
nPlanes
,
x
[
3
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
3
]))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
3
]))
:
add
(
sparseconvnet
.
Vali
dConvolution
(
dimension
,
x
[
3
],
x
[
3
],
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
x
[
3
],
x
[
3
],
3
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
3
]))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
3
]))
:
add
(
sparseconvnet
.
Deconvolution
(
dimension
,
x
[
3
],
x
[
3
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
Deconvolution
(
dimension
,
x
[
3
],
x
[
3
],
3
,
2
,
false
))
))
))
...
@@ -81,28 +81,28 @@ return function(sparseconvnet)
...
@@ -81,28 +81,28 @@ return function(sparseconvnet)
m
:
add
(
sparseconvnet
.
ConcatTable
()
m
:
add
(
sparseconvnet
.
ConcatTable
()
:
add
(
:
add
(
sparseconvnet
.
Sequential
()
sparseconvnet
.
Sequential
()
:
add
(
sparseconvnet
.
Vali
dConvolution
(
dimension
,
nPlanes
,
x
[
2
],
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
nPlanes
,
x
[
2
],
3
,
false
))
)
)
:
add
(
:
add
(
sparseconvnet
.
Sequential
()
sparseconvnet
.
Sequential
()
:
add
(
sparseconvnet
.
Convolution
(
dimension
,
nPlanes
,
x
[
3
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
Convolution
(
dimension
,
nPlanes
,
x
[
3
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
3
]))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
3
]))
:
add
(
sparseconvnet
.
Vali
dConvolution
(
dimension
,
x
[
3
],
x
[
3
],
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
x
[
3
],
x
[
3
],
3
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
3
]))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
3
]))
:
add
(
sparseconvnet
.
Deconvolution
(
dimension
,
x
[
3
],
x
[
3
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
Deconvolution
(
dimension
,
x
[
3
],
x
[
3
],
3
,
2
,
false
))
)
)
:
add
(
sparseconvnet
.
Sequential
()
:
add
(
sparseconvnet
.
Sequential
()
:
add
(
sparseconvnet
.
Convolution
(
dimension
,
nPlanes
,
x
[
4
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
Convolution
(
dimension
,
nPlanes
,
x
[
4
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
Vali
dConvolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
Convolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
Convolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
Vali
dConvolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
Deconvolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
Deconvolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
Vali
dConvolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
BatchNormReLU
(
x
[
4
]))
:
add
(
sparseconvnet
.
Deconvolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
2
,
false
))
:
add
(
sparseconvnet
.
Deconvolution
(
dimension
,
x
[
4
],
x
[
4
],
3
,
2
,
false
))
))
))
...
@@ -138,10 +138,10 @@ return function(sparseconvnet)
...
@@ -138,10 +138,10 @@ return function(sparseconvnet)
:
add
(
--convolutional connection
:
add
(
--convolutional connection
sparseconvnet
.
Sequential
()
sparseconvnet
.
Sequential
()
:
add
(
stride
==
1
and
:
add
(
stride
==
1
and
sparseconvnet
.
Vali
dConvolution
(
dimension
,
nPlanes
,
n
,
3
,
false
)
or
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
nPlanes
,
n
,
3
,
false
)
or
sparseconvnet
.
Convolution
(
dimension
,
nPlanes
,
n
,
3
,
stride
,
false
))
sparseconvnet
.
Convolution
(
dimension
,
nPlanes
,
n
,
3
,
stride
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
n
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
n
))
:
add
(
sparseconvnet
.
Vali
dConvolution
(
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
n
,
n
,
3
,
false
)))
dimension
,
n
,
n
,
3
,
false
)))
:
add
(
residual
(
nPlanes
,
n
,
stride
))
:
add
(
residual
(
nPlanes
,
n
,
stride
))
)
)
...
@@ -150,10 +150,10 @@ return function(sparseconvnet)
...
@@ -150,10 +150,10 @@ return function(sparseconvnet)
:
add
(
--convolutional connection
:
add
(
--convolutional connection
sparseconvnet
.
Sequential
()
sparseconvnet
.
Sequential
()
:
add
(
sparseconvnet
.
BatchNormReLU
(
n
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
n
))
:
add
(
sparseconvnet
.
Vali
dConvolution
(
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
nPlanes
,
n
,
3
,
false
))
dimension
,
nPlanes
,
n
,
3
,
false
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
n
))
:
add
(
sparseconvnet
.
BatchNormReLU
(
n
))
:
add
(
sparseconvnet
.
Vali
dConvolution
(
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
dimension
,
n
,
n
,
3
,
false
))
dimension
,
n
,
n
,
3
,
false
))
)
)
:
add
(
sparseconvnet
.
Identity
())
:
add
(
sparseconvnet
.
Identity
())
...
@@ -169,7 +169,7 @@ return function(sparseconvnet)
...
@@ -169,7 +169,7 @@ return function(sparseconvnet)
end
end
function
sparseconvnet
.
SparseDenseNet
(
dimension
,
nInputPlanes
,
layers
)
function
sparseconvnet
.
SparseDenseNet
(
dimension
,
nInputPlanes
,
layers
)
--[[
--[[
SparseConvNet meets DenseNets using
vali
d convolutions
SparseConvNet meets DenseNets using
submanifol
d convolutions
Could do with a less confusing name
Could do with a less confusing name
]]
]]
local
nPlanes
=
nInputPlanes
local
nPlanes
=
nInputPlanes
...
...
Torch/
Vali
dConvolution.lua
→
Torch/
Submanifol
dConvolution.lua
View file @
d77687a6
...
@@ -8,7 +8,7 @@ return function(sparseconvnet)
...
@@ -8,7 +8,7 @@ return function(sparseconvnet)
local
C
=
sparseconvnet
.
C
local
C
=
sparseconvnet
.
C
local
Convolution
,
parent
=
torch
.
class
(
local
Convolution
,
parent
=
torch
.
class
(
'sparseconvnet.
Vali
dConvolution'
,
'nn.Module'
,
sparseconvnet
)
'sparseconvnet.
Submanifol
dConvolution'
,
'nn.Module'
,
sparseconvnet
)
function
Convolution
:
__init
(
dimension
,
nInputPlanes
,
nOutputPlanes
,
function
Convolution
:
__init
(
dimension
,
nInputPlanes
,
nOutputPlanes
,
filterSize
,
bias
)
filterSize
,
bias
)
...
@@ -52,7 +52,7 @@ return function(sparseconvnet)
...
@@ -52,7 +52,7 @@ return function(sparseconvnet)
self
.
output
.
spatialSize
=
input
.
spatialSize
self
.
output
.
spatialSize
=
input
.
spatialSize
self
.
shared
.
forwardPassMultiplyAddCount
=
self
.
shared
.
forwardPassMultiplyAddCount
=
self
.
shared
.
forwardPassMultiplyAddCount
+
self
.
shared
.
forwardPassMultiplyAddCount
+
C
.
dimTypedFn
(
self
.
dimension
,
self
.
_type
,
'
Vali
dConvolution_updateOutput'
)(
C
.
dimTypedFn
(
self
.
dimension
,
self
.
_type
,
'
Submanifol
dConvolution_updateOutput'
)(
input
.
spatialSize
:
cdata
(),
input
.
spatialSize
:
cdata
(),
self
.
filterSize
:
cdata
(),
self
.
filterSize
:
cdata
(),
input
.
metadata
.
ffi
,
input
.
metadata
.
ffi
,
...
@@ -68,7 +68,7 @@ return function(sparseconvnet)
...
@@ -68,7 +68,7 @@ return function(sparseconvnet)
end
end
function
Convolution
:
backward
(
input
,
gradOutput
)
function
Convolution
:
backward
(
input
,
gradOutput
)
C
.
dimTypedFn
(
self
.
dimension
,
self
.
_type
,
'
Vali
dConvolution_backward'
)(
C
.
dimTypedFn
(
self
.
dimension
,
self
.
_type
,
'
Submanifol
dConvolution_backward'
)(
input
.
spatialSize
:
cdata
(),
input
.
spatialSize
:
cdata
(),
self
.
filterSize
:
cdata
(),
self
.
filterSize
:
cdata
(),
input
.
metadata
.
ffi
,
input
.
metadata
.
ffi
,
...
@@ -100,7 +100,7 @@ return function(sparseconvnet)
...
@@ -100,7 +100,7 @@ return function(sparseconvnet)
end
end
function
Convolution
:
__tostring
()
function
Convolution
:
__tostring
()
local
s
=
'
Vali
dConvolution '
..
self
.
nInputPlanes
..
'->'
..
self
.
nOutputPlanes
..
' C'
local
s
=
'
Submanifol
dConvolution '
..
self
.
nInputPlanes
..
'->'
..
self
.
nOutputPlanes
..
' C'
if
self
.
filterSize
:
max
()
==
self
.
filterSize
:
min
()
and
if
self
.
filterSize
:
max
()
==
self
.
filterSize
:
min
()
and
self
.
filterStride
:
max
()
==
self
.
filterStride
:
min
()
then
self
.
filterStride
:
max
()
==
self
.
filterStride
:
min
()
then
s
=
s
..
self
.
filterSize
[
1
]
..
(
self
.
filterStride
[
1
]
==
1
and
s
=
s
..
self
.
filterSize
[
1
]
..
(
self
.
filterStride
[
1
]
==
1
and
...
...
Torch/init.lua
View file @
d77687a6
...
@@ -35,7 +35,7 @@ for _,module in ipairs({
...
@@ -35,7 +35,7 @@ for _,module in ipairs({
'sparseconvnet.ReLU'
,
'sparseconvnet.ReLU'
,
'sparseconvnet.Sequential'
,
'sparseconvnet.Sequential'
,
'sparseconvnet.SparseToDense'
,
'sparseconvnet.SparseToDense'
,
'sparseconvnet.
Vali
dConvolution'
,
'sparseconvnet.
Submanifol
dConvolution'
,
})
do
})
do
require
(
module
)(
sparseconvnet
)
require
(
module
)(
sparseconvnet
)
end
end
...
...
examples/Assamese_handwriting/DenseNet.lua
View file @
d77687a6
...
@@ -14,7 +14,7 @@ local sparseModel = sparseconvnet.Sequential()
...
@@ -14,7 +14,7 @@ local sparseModel = sparseconvnet.Sequential()
local
denseModel
=
nn
.
Sequential
()
local
denseModel
=
nn
.
Sequential
()
model
:
add
(
sparseModel
):
add
(
denseModel
)
model
:
add
(
sparseModel
):
add
(
denseModel
)
sparseModel
sparseModel
:
add
(
sparseconvnet
.
Vali
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
SparseDenseNet
(
2
,
16
,{
:
add
(
sparseconvnet
.
SparseDenseNet
(
2
,
16
,{
{
'MP'
,
compression
=
0
},
{
'MP'
,
compression
=
0
},
{
nExtraLayers
=
2
,
growthRate
=
16
},
{
nExtraLayers
=
2
,
growthRate
=
16
},
...
...
examples/Assamese_handwriting/DenseNet.py
View file @
d77687a6
...
@@ -17,7 +17,7 @@ model = nn.Sequential()
...
@@ -17,7 +17,7 @@ model = nn.Sequential()
sparseModel
=
scn
.
Sequential
()
sparseModel
=
scn
.
Sequential
()
denseModel
=
nn
.
Sequential
()
denseModel
=
nn
.
Sequential
()
model
.
add
(
sparseModel
).
add
(
denseModel
)
model
.
add
(
sparseModel
).
add
(
denseModel
)
sparseModel
.
add
(
scn
.
Vali
dConvolution
(
2
,
3
,
8
,
3
,
False
))
\
sparseModel
.
add
(
scn
.
Submanifol
dConvolution
(
2
,
3
,
8
,
3
,
False
))
\
.
add
(
scn
.
SparseDenseNet
(
2
,
8
,
[
.
add
(
scn
.
SparseDenseNet
(
2
,
8
,
[
{
'pool'
:
'MP'
,
'compression'
:
0
},
{
'pool'
:
'MP'
,
'compression'
:
0
},
{
'nExtraLayers'
:
2
,
'growthRate'
:
8
},
{
'nExtraLayers'
:
2
,
'growthRate'
:
8
},
...
...
examples/Assamese_handwriting/ResNet.lua
View file @
d77687a6
...
@@ -14,7 +14,7 @@ local sparseModel = sparseconvnet.Sequential()
...
@@ -14,7 +14,7 @@ local sparseModel = sparseconvnet.Sequential()
local
denseModel
=
nn
.
Sequential
()
local
denseModel
=
nn
.
Sequential
()
model
:
add
(
sparseModel
):
add
(
denseModel
)
model
:
add
(
sparseModel
):
add
(
denseModel
)
sparseModel
sparseModel
:
add
(
sparseconvnet
.
Vali
dConvolution
(
2
,
3
,
8
,
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
2
,
3
,
8
,
3
,
false
))
:
add
(
sparseconvnet
.
MaxPooling
(
2
,
3
,
2
))
:
add
(
sparseconvnet
.
MaxPooling
(
2
,
3
,
2
))
:
add
(
sparseconvnet
.
SparseResNet
(
:
add
(
sparseconvnet
.
SparseResNet
(
2
,
8
,{
2
,
8
,{
...
...
examples/Assamese_handwriting/ResNet.py
View file @
d77687a6
...
@@ -10,11 +10,13 @@ import sparseconvnet as scn
...
@@ -10,11 +10,13 @@ import sparseconvnet as scn
from
data
import
getIterators
from
data
import
getIterators
# two-dimensional SparseConvNet
# two-dimensional SparseConvNet
class
Model
(
nn
.
Module
):
class
Model
(
nn
.
Module
):
def
__init__
(
self
):
def
__init__
(
self
):
nn
.
Module
.
__init__
(
self
)
nn
.
Module
.
__init__
(
self
)
self
.
sparseModel
=
scn
.
Sequential
(
self
.
sparseModel
=
scn
.
Sequential
(
).
add
(
scn
.
Vali
dConvolution
(
2
,
3
,
8
,
3
,
False
)
).
add
(
scn
.
Submanifol
dConvolution
(
2
,
3
,
8
,
3
,
False
)
).
add
(
scn
.
MaxPooling
(
2
,
3
,
2
)
).
add
(
scn
.
MaxPooling
(
2
,
3
,
2
)
).
add
(
scn
.
SparseResNet
(
2
,
8
,
[
).
add
(
scn
.
SparseResNet
(
2
,
8
,
[
[
'b'
,
8
,
2
,
1
],
[
'b'
,
8
,
2
,
1
],
...
@@ -23,15 +25,17 @@ class Model(nn.Module):
...
@@ -23,15 +25,17 @@ class Model(nn.Module):
[
'b'
,
32
,
2
,
2
]])
[
'b'
,
32
,
2
,
2
]])
).
add
(
scn
.
Convolution
(
2
,
32
,
64
,
5
,
1
,
False
)
).
add
(
scn
.
Convolution
(
2
,
32
,
64
,
5
,
1
,
False
)
).
add
(
scn
.
BatchNormReLU
(
64
)
).
add
(
scn
.
BatchNormReLU
(
64
)
).
add
(
scn
.
SparseToDense
(
2
,
64
))
).
add
(
scn
.
SparseToDense
(
2
,
64
))
self
.
linear
=
nn
.
Linear
(
64
,
183
)
self
.
linear
=
nn
.
Linear
(
64
,
183
)
def
forward
(
self
,
x
):
def
forward
(
self
,
x
):
x
=
self
.
sparseModel
(
x
)
x
=
self
.
sparseModel
(
x
)
x
=
x
.
view
(
-
1
,
64
)
x
=
x
.
view
(
-
1
,
64
)
x
=
self
.
linear
(
x
)
x
=
self
.
linear
(
x
)
return
x
return
x
model
=
Model
()
model
=
Model
()
spatial_size
=
model
.
sparseModel
.
input_spatial_size
(
torch
.
LongTensor
([
1
,
1
]))
spatial_size
=
model
.
sparseModel
.
input_spatial_size
(
torch
.
LongTensor
([
1
,
1
]))
print
(
'Input spatial size:'
,
spatial_size
)
print
(
'Input spatial size:'
,
spatial_size
)
dataset
=
getIterators
(
spatial_size
,
63
,
3
)
dataset
=
getIterators
(
spatial_size
,
63
,
3
)
...
@@ -42,4 +46,4 @@ scn.ClassificationTrainValidate(
...
@@ -42,4 +46,4 @@ scn.ClassificationTrainValidate(
'lr_decay'
:
0.05
,
'lr_decay'
:
0.05
,
'weight_decay'
:
1e-4
,
'weight_decay'
:
1e-4
,
'use_gpu'
:
torch
.
cuda
.
is_available
(),
'use_gpu'
:
torch
.
cuda
.
is_available
(),
'check_point'
:
True
,})
'check_point'
:
True
,
})
examples/Assamese_handwriting/ResNet_legacy.py
View file @
d77687a6
...
@@ -17,7 +17,7 @@ model = nn.Sequential()
...
@@ -17,7 +17,7 @@ model = nn.Sequential()
sparseModel
=
scn
.
Sequential
()
sparseModel
=
scn
.
Sequential
()
denseModel
=
nn
.
Sequential
()
denseModel
=
nn
.
Sequential
()
model
.
add
(
sparseModel
).
add
(
denseModel
)
model
.
add
(
sparseModel
).
add
(
denseModel
)
sparseModel
.
add
(
scn
.
Vali
dConvolution
(
2
,
3
,
8
,
3
,
False
))
sparseModel
.
add
(
scn
.
Submanifol
dConvolution
(
2
,
3
,
8
,
3
,
False
))
sparseModel
.
add
(
scn
.
MaxPooling
(
2
,
3
,
2
))
sparseModel
.
add
(
scn
.
MaxPooling
(
2
,
3
,
2
))
sparseModel
.
add
(
scn
.
SparseResNet
(
2
,
8
,
[
sparseModel
.
add
(
scn
.
SparseResNet
(
2
,
8
,
[
[
'b'
,
8
,
2
,
1
],
[
'b'
,
8
,
2
,
1
],
...
...
examples/Assamese_handwriting/VGGplus.py
View file @
d77687a6
...
@@ -16,19 +16,21 @@ class Model(nn.Module):
...
@@ -16,19 +16,21 @@ class Model(nn.Module):
self
.
sparseModel
=
scn
.
SparseVggNet
(
2
,
3
,
[
self
.
sparseModel
=
scn
.
SparseVggNet
(
2
,
3
,
[
[
'C'
,
8
,
],
[
'C'
,
8
],
'MP'
,
[
'C'
,
8
,
],
[
'C'
,
8
],
'MP'
,
[
'C'
,
16
],
[
'C'
,
16
],
'MP'
,
[
'C'
,
16
],
[
'C'
,
16
],
'MP'
,
[
'C'
,
16
,
8
],
[
'C'
,
16
,
8
],
'MP'
,
[
'C'
,
16
+
8
],
[
'C'
,
16
+
8
],
'MP'
,
[
'C'
,
24
,
8
],
[
'C'
,
24
,
8
],
'MP'
]
[
'C'
,
24
+
8
],
[
'C'
,
24
+
8
],
'MP'
]
).
add
(
scn
.
Convolution
(
2
,
32
,
64
,
5
,
1
,
False
)
).
add
(
scn
.
Convolution
(
2
,
32
,
64
,
5
,
1
,
False
)
).
add
(
scn
.
BatchNormReLU
(
64
)
).
add
(
scn
.
BatchNormReLU
(
64
)
).
add
(
scn
.
SparseToDense
(
2
,
64
))
).
add
(
scn
.
SparseToDense
(
2
,
64
))
self
.
linear
=
nn
.
Linear
(
64
,
183
)
self
.
linear
=
nn
.
Linear
(
64
,
183
)
def
forward
(
self
,
x
):
def
forward
(
self
,
x
):
x
=
self
.
sparseModel
(
x
)
x
=
self
.
sparseModel
(
x
)
x
=
x
.
view
(
-
1
,
64
)
x
=
x
.
view
(
-
1
,
64
)
x
=
self
.
linear
(
x
)
x
=
self
.
linear
(
x
)
return
x
return
x
model
=
Model
()
model
=
Model
()
spatial_size
=
model
.
sparseModel
.
input_spatial_size
(
torch
.
LongTensor
([
1
,
1
]))
spatial_size
=
model
.
sparseModel
.
input_spatial_size
(
torch
.
LongTensor
([
1
,
1
]))
print
(
'Input spatial size:'
,
spatial_size
)
print
(
'Input spatial size:'
,
spatial_size
)
dataset
=
getIterators
(
spatial_size
,
63
,
3
)
dataset
=
getIterators
(
spatial_size
,
63
,
3
)
...
@@ -39,4 +41,4 @@ scn.ClassificationTrainValidate(
...
@@ -39,4 +41,4 @@ scn.ClassificationTrainValidate(
'lr_decay'
:
0.05
,
'lr_decay'
:
0.05
,
'weight_decay'
:
1e-4
,
'weight_decay'
:
1e-4
,
'use_gpu'
:
torch
.
cuda
.
is_available
(),
'use_gpu'
:
torch
.
cuda
.
is_available
(),
'check_point'
:
True
,})
'check_point'
:
True
,
})
examples/Assamese_handwriting/VGGplus_legacy.py
View file @
d77687a6
...
@@ -33,6 +33,10 @@ print(model)
...
@@ -33,6 +33,10 @@ print(model)
spatial_size
=
sparseModel
.
suggestInputSize
(
torch
.
LongTensor
([
1
,
1
]))
spatial_size
=
sparseModel
.
suggestInputSize
(
torch
.
LongTensor
([
1
,
1
]))
print
(
'input spatial size'
,
spatial_size
)
print
(
'input spatial size'
,
spatial_size
)
dataset
=
getIterators
(
spatial_size
,
63
,
3
)
dataset
=
getIterators
(
spatial_size
,
63
,
3
)
scn
.
ClassificationTrainValidate
(
scn
.
ClassificationTrainValidate
(
model
,
model
,
dataset
,
dataset
,
{
'nEpochs'
:
100
,
'initial_LR'
:
0.1
,
'LR_decay'
:
0.05
,
'weightDecay'
:
1e-4
,
'checkPoint'
:
False
})
{
'nEpochs'
:
100
,
'initial_LR'
:
0.1
,
'LR_decay'
:
0.05
,
'weightDecay'
:
1e-4
,
'checkPoint'
:
False
})
examples/Assamese_handwriting/data.py
View file @
d77687a6
...
@@ -10,7 +10,7 @@ import sparseconvnet.legacy as scn
...
@@ -10,7 +10,7 @@ import sparseconvnet.legacy as scn
import
pickle
import
pickle
import
math
import
math
import
random
import
random
import
numpy
import
numpy
as
np
import
os
import
os
if
not
os
.
path
.
exists
(
'pickle/'
):
if
not
os
.
path
.
exists
(
'pickle/'
):
...
@@ -25,6 +25,8 @@ def train(spatial_size, Scale, precomputeStride):
...
@@ -25,6 +25,8 @@ def train(spatial_size, Scale, precomputeStride):
for
i
in
range
(
9
):
for
i
in
range
(
9
):
for
j
in
range
(
6588
):
for
j
in
range
(
6588
):
d
.
append
(
d
[
j
])
d
.
append
(
d
[
j
])
for
i
,
x
in
enumerate
(
d
):
x
[
'idx'
]
=
i
d
=
torchnet
.
dataset
.
ListDataset
(
d
)
d
=
torchnet
.
dataset
.
ListDataset
(
d
)
randperm
=
torch
.
randperm
(
len
(
d
))
randperm
=
torch
.
randperm
(
len
(
d
))
...
@@ -36,10 +38,11 @@ def train(spatial_size, Scale, precomputeStride):
...
@@ -36,10 +38,11 @@ def train(spatial_size, Scale, precomputeStride):
center
=
spatial_size
.
float
().
view
(
1
,
2
)
/
2
center
=
spatial_size
.
float
().
view
(
1
,
2
)
/
2
p
=
torch
.
LongTensor
(
2
)
p
=
torch
.
LongTensor
(
2
)
v
=
torch
.
FloatTensor
([
1
,
0
,
0
])
v
=
torch
.
FloatTensor
([
1
,
0
,
0
])
np_random
=
np
.
random
.
RandomState
(
tbl
[
'idx'
])
for
char
in
tbl
[
'input'
]:
for
char
in
tbl
[
'input'
]:
inp
.
addSample
()
inp
.
addSample
()
m
=
torch
.
eye
(
2
)
m
=
torch
.
eye
(
2
)
r
=
random
.
randint
(
1
,
3
)
r
=
np_
random
.
randint
(
1
,
3
)
alpha
=
random
.
uniform
(
-
0.2
,
0.2
)
alpha
=
random
.
uniform
(
-
0.2
,
0.2
)
if
alpha
==
1
:
if
alpha
==
1
:
m
[
0
][
1
]
=
alpha
m
[
0
][
1
]
=
alpha
...
@@ -74,7 +77,7 @@ def train(spatial_size, Scale, precomputeStride):
...
@@ -74,7 +77,7 @@ def train(spatial_size, Scale, precomputeStride):
# v[1]=(x2-x1)/l
# v[1]=(x2-x1)/l
# v[2]=(y2-y1)/l
# v[2]=(y2-y1)/l
# l=max(x2-x1,y2-y1,x1-x2,y1-y2,0.9)
# l=max(x2-x1,y2-y1,x1-x2,y1-y2,0.9)
# for j in n
umpy
.arange(0,1,1/l):
# for j in n
p
.arange(0,1,1/l):
# p[0]=math.floor(x1*j+x2*(1-j))
# p[0]=math.floor(x1*j+x2*(1-j))
# p[1]=math.floor(y1*j+y2*(1-j))
# p[1]=math.floor(y1*j+y2*(1-j))
# inp.setLocation(p,v,False)
# inp.setLocation(p,v,False)
...
...
examples/Chinese_handwriting/DenseNet-A-VSC.lua
View file @
d77687a6
...
@@ -14,7 +14,7 @@ local denseModel = nn.Sequential()
...
@@ -14,7 +14,7 @@ local denseModel = nn.Sequential()
local
model
=
nn
.
Sequential
():
add
(
sparseModel
):
add
(
denseModel
)
local
model
=
nn
.
Sequential
():
add
(
sparseModel
):
add
(
denseModel
)
sparseModel
sparseModel
:
add
(
sparseconvnet
.
Vali
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
SparseDenseNet
(
2
,
16
,{
:
add
(
sparseconvnet
.
SparseDenseNet
(
2
,
16
,{
{
'MP'
,
compression
=
0
},
{
'MP'
,
compression
=
0
},
{
nExtraLayers
=
2
,
growthRate
=
16
},
{
nExtraLayers
=
2
,
growthRate
=
16
},
...
...
examples/Chinese_handwriting/DenseNet-A-VSC.py
View file @
d77687a6
...
@@ -17,7 +17,7 @@ model = nn.Sequential()
...
@@ -17,7 +17,7 @@ model = nn.Sequential()
sparseModel
=
scn
.
Sequential
()
sparseModel
=
scn
.
Sequential
()
denseModel
=
nn
.
Sequential
()
denseModel
=
nn
.
Sequential
()
model
.
add
(
sparseModel
).
add
(
denseModel
)
model
.
add
(
sparseModel
).
add
(
denseModel
)
sparseModel
.
add
(
scn
.
Vali
dConvolution
(
2
,
3
,
16
,
3
,
False
))
\
sparseModel
.
add
(
scn
.
Submanifol
dConvolution
(
2
,
3
,
16
,
3
,
False
))
\
.
add
(
scn
.
SparseDenseNet
(
2
,
16
,
[
.
add
(
scn
.
SparseDenseNet
(
2
,
16
,
[
{
'pool'
:
'MP'
,
'compression'
:
0
},
{
'pool'
:
'MP'
,
'compression'
:
0
},
{
'nExtraLayers'
:
2
,
'growthRate'
:
16
},
{
'nExtraLayers'
:
2
,
'growthRate'
:
16
},
...
...
examples/Chinese_handwriting/DenseNet-B-VSC.lua
View file @
d77687a6
...
@@ -14,7 +14,7 @@ local denseModel = nn.Sequential()
...
@@ -14,7 +14,7 @@ local denseModel = nn.Sequential()
local
model
=
nn
.
Sequential
():
add
(
sparseModel
):
add
(
denseModel
)
local
model
=
nn
.
Sequential
():
add
(
sparseModel
):
add
(
denseModel
)
sparseModel
sparseModel
:
add
(
sparseconvnet
.
Vali
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
SparseDenseNet
(
2
,
16
,{
:
add
(
sparseconvnet
.
SparseDenseNet
(
2
,
16
,{
{
'MP'
,
compression
=
0
},
{
'MP'
,
compression
=
0
},
{
nExtraLayers
=
4
,
growthRate
=
16
},
{
nExtraLayers
=
4
,
growthRate
=
16
},
...
...
examples/Chinese_handwriting/ResNet-A-VSC.lua
View file @
d77687a6
...
@@ -24,7 +24,7 @@ local denseModel = nn.Sequential()
...
@@ -24,7 +24,7 @@ local denseModel = nn.Sequential()
local
model
=
nn
.
Sequential
():
add
(
sparseModel
):
add
(
denseModel
)
local
model
=
nn
.
Sequential
():
add
(
sparseModel
):
add
(
denseModel
)
sparseModel
sparseModel
:
add
(
sparseconvnet
.
Vali
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
MaxPooling
(
2
,
2
,
2
))
:
add
(
sparseconvnet
.
MaxPooling
(
2
,
2
,
2
))
:
add
(
sparseconvnet
.
SparseResNet
(
:
add
(
sparseconvnet
.
SparseResNet
(
2
,
16
,{
2
,
16
,{
...
...
examples/Chinese_handwriting/ResNet-A-VSC.py
View file @
d77687a6
...
@@ -17,7 +17,7 @@ model = nn.Sequential()
...
@@ -17,7 +17,7 @@ model = nn.Sequential()
sparseModel
=
scn
.
Sequential
()
sparseModel
=
scn
.
Sequential
()
denseModel
=
nn
.
Sequential
()
denseModel
=
nn
.
Sequential
()
model
.
add
(
sparseModel
).
add
(
denseModel
)
model
.
add
(
sparseModel
).
add
(
denseModel
)
sparseModel
.
add
(
scn
.
Vali
dConvolution
(
2
,
3
,
16
,
3
,
False
))
sparseModel
.
add
(
scn
.
Submanifol
dConvolution
(
2
,
3
,
16
,
3
,
False
))
sparseModel
.
add
(
scn
.
MaxPooling
(
2
,
3
,
2
))
sparseModel
.
add
(
scn
.
MaxPooling
(
2
,
3
,
2
))
sparseModel
.
add
(
scn
.
SparseResNet
(
2
,
16
,
[
sparseModel
.
add
(
scn
.
SparseResNet
(
2
,
16
,
[
[
'b'
,
16
,
2
,
1
],
[
'b'
,
16
,
2
,
1
],
...
...
examples/Chinese_handwriting/ResNet-B-VSC.lua
View file @
d77687a6
...
@@ -14,7 +14,7 @@ local denseModel = nn.Sequential()
...
@@ -14,7 +14,7 @@ local denseModel = nn.Sequential()
local
model
=
nn
.
Sequential
():
add
(
sparseModel
):
add
(
denseModel
)
local
model
=
nn
.
Sequential
():
add
(
sparseModel
):
add
(
denseModel
)
sparseModel
sparseModel
:
add
(
sparseconvnet
.
Vali
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
MaxPooling
(
2
,
2
,
2
))
:
add
(
sparseconvnet
.
MaxPooling
(
2
,
2
,
2
))
:
add
(
sparseconvnet
.
SparseResNet
(
:
add
(
sparseconvnet
.
SparseResNet
(
2
,
16
,{
2
,
16
,{
...
...
examples/Chinese_handwriting/ResNet-C-VSC.lua
View file @
d77687a6
...
@@ -24,7 +24,7 @@ local denseModel = nn.Sequential()
...
@@ -24,7 +24,7 @@ local denseModel = nn.Sequential()
local
model
=
nn
.
Sequential
():
add
(
sparseModel
):
add
(
denseModel
)
local
model
=
nn
.
Sequential
():
add
(
sparseModel
):
add
(
denseModel
)
sparseModel
sparseModel
:
add
(
sparseconvnet
.
Vali
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
Submanifol
dConvolution
(
2
,
3
,
16
,
3
,
false
))
:
add
(
sparseconvnet
.
MaxPooling
(
2
,
2
,
2
))
:
add
(
sparseconvnet
.
MaxPooling
(
2
,
2
,
2
))
:
add
(
sparseconvnet
.
SparseResNet
(
:
add
(
sparseconvnet
.
SparseResNet
(
2
,
16
,{
2
,
16
,{
...
...
Prev
1
2
3
4
5
Next
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