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
062f0665
Commit
062f0665
authored
Nov 28, 2018
by
Benjamin Thomas Graham
Browse files
at:: to torch::
parent
9aea4e05
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12 additions
and
31 deletions
+12
-31
README.md
README.md
+0
-8
examples/hello-world.py
examples/hello-world.py
+0
-8
sparseconvnet/SCN/Metadata/Metadata.cpp
sparseconvnet/SCN/Metadata/Metadata.cpp
+9
-10
sparseconvnet/SCN/Metadata/Metadata.h
sparseconvnet/SCN/Metadata/Metadata.h
+2
-3
sparseconvnet/sparseConvNetTensor.py
sparseconvnet/sparseConvNetTensor.py
+1
-2
No files found.
README.md
View file @
062f0665
...
@@ -94,14 +94,6 @@ locations = torch.LongTensor(locations)
...
@@ -94,14 +94,6 @@ locations = torch.LongTensor(locations)
features
=
torch
.
FloatTensor
(
features
)
features
=
torch
.
FloatTensor
(
features
)
input
.
set_locations
(
locations
,
features
,
0
)
input
.
set_locations
(
locations
,
features
,
0
)
#
Optional
:
allow
metadata
preprocessing
to
be
done
in
batch
preparation
threads
#
to
improve
GPU
utilization
.
#
#
Parameter
:
#
3
if
using
MP3
/
2
pooling
or
C3
/
2
convolutions
for
downsizing
,
#
2
if
using
MP2
pooling
for
downsizing
.
input
.
precomputeMetadata
(
3
)
model
.
train
()
model
.
train
()
if
use_gpu
:
if
use_gpu
:
input
.
cuda
()
input
.
cuda
()
...
...
examples/hello-world.py
View file @
062f0665
...
@@ -58,14 +58,6 @@ locations = torch.LongTensor(locations)
...
@@ -58,14 +58,6 @@ locations = torch.LongTensor(locations)
features
=
torch
.
FloatTensor
(
features
)
features
=
torch
.
FloatTensor
(
features
)
input
.
set_locations
(
locations
,
features
,
0
)
input
.
set_locations
(
locations
,
features
,
0
)
# Optional: allow metadata preprocessing to be done in batch preparation threads
# to improve GPU utilization.
#
# Parameter:
# 3 if using MP3/2 pooling or C3/2 convolutions for downsizing,
# 2 if using MP2 pooling for downsizing.
input
.
precomputeMetadata
(
3
)
model
.
train
()
model
.
train
()
if
use_cuda
:
if
use_cuda
:
input
.
cuda
()
input
.
cuda
()
...
...
sparseconvnet/SCN/Metadata/Metadata.cpp
View file @
062f0665
...
@@ -145,15 +145,13 @@ void Metadata<dimension>::setInputSpatialLocations(
...
@@ -145,15 +145,13 @@ void Metadata<dimension>::setInputSpatialLocations(
}
}
template
<
Int
dimension
>
template
<
Int
dimension
>
void
Metadata
<
dimension
>::
getSpatialLocations
(
/*long*/
at
::
Tensor
spatialSize
,
at
::
Tensor
/*long*/
at
::
Tensor
locations
)
{
Metadata
<
dimension
>::
getSpatialLocations
(
/*long*/
at
::
Tensor
spatialSize
)
{
Int
nActive
=
getNActive
(
spatialSize
);
Int
nActive
=
getNActive
(
spatialSize
);
auto
&
SGs
=
getSparseGrid
(
spatialSize
);
auto
&
SGs
=
getSparseGrid
(
spatialSize
);
Int
batchSize
=
SGs
.
size
();
Int
batchSize
=
SGs
.
size
();
locations
.
resize_
({(
int
)
nActive
,
dimension
+
1
});
auto
locations
=
torch
::
zeros
({(
int
)
nActive
,
dimension
+
1
},
at
::
kLong
);
locations
.
zero_
();
auto
lD
=
locations
.
data
<
long
>
();
auto
lD
=
locations
.
data
<
long
>
();
for
(
Int
i
=
0
;
i
<
batchSize
;
i
++
)
{
for
(
Int
i
=
0
;
i
<
batchSize
;
i
++
)
{
...
@@ -166,6 +164,7 @@ void Metadata<dimension>::getSpatialLocations(/*long*/ at::Tensor spatialSize,
...
@@ -166,6 +164,7 @@ void Metadata<dimension>::getSpatialLocations(/*long*/ at::Tensor spatialSize,
lD
[(
it
->
second
+
offset
)
*
(
dimension
+
1
)
+
dimension
]
=
i
;
lD
[(
it
->
second
+
offset
)
*
(
dimension
+
1
)
+
dimension
]
=
i
;
}
}
}
}
return
locations
;
}
}
template
<
Int
dimension
>
template
<
Int
dimension
>
void
Metadata
<
dimension
>::
createMetadataForDenseToSparse
(
void
Metadata
<
dimension
>::
createMetadataForDenseToSparse
(
...
@@ -260,7 +259,7 @@ Metadata<dimension>::sparsifyCompare(Metadata<dimension> &mReference,
...
@@ -260,7 +259,7 @@ Metadata<dimension>::sparsifyCompare(Metadata<dimension> &mReference,
Metadata
<
dimension
>
&
mSparsified
,
Metadata
<
dimension
>
&
mSparsified
,
/*long*/
at
::
Tensor
spatialSize
)
{
/*long*/
at
::
Tensor
spatialSize
)
{
auto
p
=
LongTensorToPoint
<
dimension
>
(
spatialSize
);
auto
p
=
LongTensorToPoint
<
dimension
>
(
spatialSize
);
at
::
Tensor
delta
=
a
t
::
zeros
({
nActive
[
p
]},
at
::
kFloat
);
at
::
Tensor
delta
=
t
orch
::
zeros
({
nActive
[
p
]},
at
::
kFloat
);
float
*
deltaPtr
=
delta
.
data
<
float
>
();
float
*
deltaPtr
=
delta
.
data
<
float
>
();
auto
&
sgsReference
=
mReference
.
grids
[
p
];
auto
&
sgsReference
=
mReference
.
grids
[
p
];
auto
&
sgsFull
=
grids
[
p
];
auto
&
sgsFull
=
grids
[
p
];
...
@@ -588,13 +587,13 @@ Metadata<dimension>::compareSparseHelper(Metadata<dimension> &mR,
...
@@ -588,13 +587,13 @@ Metadata<dimension>::compareSparseHelper(Metadata<dimension> &mR,
}
}
}
}
}
}
at
::
Tensor
cL_
=
a
t
::
empty
({(
long
)
cL
.
size
()},
at
::
CPU
(
at
::
kLong
));
at
::
Tensor
cL_
=
t
orch
::
empty
({(
long
)
cL
.
size
()},
at
::
CPU
(
at
::
kLong
));
std
::
memcpy
(
cL_
.
data
<
long
>
(),
&
cL
[
0
],
cL
.
size
()
*
sizeof
(
long
));
std
::
memcpy
(
cL_
.
data
<
long
>
(),
&
cL
[
0
],
cL
.
size
()
*
sizeof
(
long
));
at
::
Tensor
cR_
=
a
t
::
empty
({(
long
)
cR
.
size
()},
at
::
CPU
(
at
::
kLong
));
at
::
Tensor
cR_
=
t
orch
::
empty
({(
long
)
cR
.
size
()},
at
::
CPU
(
at
::
kLong
));
std
::
memcpy
(
cR_
.
data
<
long
>
(),
&
cR
[
0
],
cR
.
size
()
*
sizeof
(
long
));
std
::
memcpy
(
cR_
.
data
<
long
>
(),
&
cR
[
0
],
cR
.
size
()
*
sizeof
(
long
));
at
::
Tensor
L_
=
a
t
::
empty
({(
long
)
L
.
size
()},
at
::
CPU
(
at
::
kLong
));
at
::
Tensor
L_
=
t
orch
::
empty
({(
long
)
L
.
size
()},
at
::
CPU
(
at
::
kLong
));
std
::
memcpy
(
L_
.
data
<
long
>
(),
&
L
[
0
],
L
.
size
()
*
sizeof
(
long
));
std
::
memcpy
(
L_
.
data
<
long
>
(),
&
L
[
0
],
L
.
size
()
*
sizeof
(
long
));
at
::
Tensor
R_
=
a
t
::
empty
({(
long
)
R
.
size
()},
at
::
CPU
(
at
::
kLong
));
at
::
Tensor
R_
=
t
orch
::
empty
({(
long
)
R
.
size
()},
at
::
CPU
(
at
::
kLong
));
std
::
memcpy
(
R_
.
data
<
long
>
(),
&
R
[
0
],
R
.
size
()
*
sizeof
(
long
));
std
::
memcpy
(
R_
.
data
<
long
>
(),
&
R
[
0
],
R
.
size
()
*
sizeof
(
long
));
return
{
cL_
,
cR_
,
L_
,
R_
};
return
{
cL_
,
cR_
,
L_
,
R_
};
}
}
...
...
sparseconvnet/SCN/Metadata/Metadata.h
View file @
062f0665
...
@@ -92,8 +92,7 @@ public:
...
@@ -92,8 +92,7 @@ public:
/*long*/
at
::
Tensor
locations
,
/*long*/
at
::
Tensor
locations
,
/*float*/
at
::
Tensor
vecs
,
bool
overwrite
);
/*float*/
at
::
Tensor
vecs
,
bool
overwrite
);
void
getSpatialLocations
(
/*long*/
at
::
Tensor
spatialSize
,
at
::
Tensor
getSpatialLocations
(
/*long*/
at
::
Tensor
spatialSize
);
/*long*/
at
::
Tensor
locations
);
void
createMetadataForDenseToSparse
(
/*long*/
at
::
Tensor
spatialSize
,
void
createMetadataForDenseToSparse
(
/*long*/
at
::
Tensor
spatialSize
,
/*long*/
at
::
Tensor
nz_
,
long
batchSize
);
/*long*/
at
::
Tensor
nz_
,
long
batchSize
);
...
@@ -153,7 +152,7 @@ public:
...
@@ -153,7 +152,7 @@ public:
std
::
vector
<
at
::
Tensor
>
std
::
vector
<
at
::
Tensor
>
compareSparseHelper
(
Metadata
<
dimension
>
&
mR
,
compareSparseHelper
(
Metadata
<
dimension
>
&
mR
,
/* long */
at
::
Tensor
spatialSize
);
/* long */
at
::
Tensor
spatialSize
);
};
};
template
<
typename
T
>
T
*
OptionalTensorData
(
at
::
Tensor
tensor
);
template
<
typename
T
>
T
*
OptionalTensorData
(
at
::
Tensor
tensor
);
...
...
sparseconvnet/sparseConvNetTensor.py
View file @
062f0665
...
@@ -19,8 +19,7 @@ class SparseConvNetTensor(object):
...
@@ -19,8 +19,7 @@ class SparseConvNetTensor(object):
"Coordinates and batch index for the active spatial locations"
"Coordinates and batch index for the active spatial locations"
if
spatial_size
is
None
:
if
spatial_size
is
None
:
spatial_size
=
self
.
spatial_size
spatial_size
=
self
.
spatial_size
t
=
torch
.
LongTensor
()
t
=
self
.
metadata
.
getSpatialLocations
(
spatial_size
)
self
.
metadata
.
getSpatialLocations
(
spatial_size
,
t
)
return
t
return
t
def
type
(
self
,
t
=
None
):
def
type
(
self
,
t
=
None
):
...
...
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