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
pydensecrf
Commits
9096c7bf
Commit
9096c7bf
authored
Apr 24, 2017
by
lucasb-eyer
Browse files
Fix segfault on wrong compat dtype.
The exception is now correctly propagated instead.
parent
1c40e00f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
2 deletions
+24
-2
pydensecrf/densecrf.pyx
pydensecrf/densecrf.pyx
+2
-1
pydensecrf/test.py
pydensecrf/test.py
+22
-1
No files found.
pydensecrf/densecrf.pyx
View file @
9096c7bf
...
@@ -8,7 +8,7 @@ import eigen
...
@@ -8,7 +8,7 @@ import eigen
cimport
eigen
cimport
eigen
cdef
LabelCompatibility
*
_labelcomp
(
compat
):
cdef
LabelCompatibility
*
_labelcomp
(
compat
)
except
NULL
:
if
isinstance
(
compat
,
Number
):
if
isinstance
(
compat
,
Number
):
return
new
PottsCompatibility
(
compat
)
return
new
PottsCompatibility
(
compat
)
elif
memoryview
(
compat
).
ndim
==
1
:
elif
memoryview
(
compat
).
ndim
==
1
:
...
@@ -17,6 +17,7 @@ cdef LabelCompatibility* _labelcomp(compat):
...
@@ -17,6 +17,7 @@ cdef LabelCompatibility* _labelcomp(compat):
return
new
MatrixCompatibility
(
eigen
.
c_matrixXf
(
compat
))
return
new
MatrixCompatibility
(
eigen
.
c_matrixXf
(
compat
))
else
:
else
:
raise
ValueError
(
"LabelCompatibility of dimension >2 not meaningful."
)
raise
ValueError
(
"LabelCompatibility of dimension >2 not meaningful."
)
return
NULL
# Important for the exception(s) to propagate!
cdef
class
Unary
:
cdef
class
Unary
:
...
...
pydensecrf/test.py
View file @
9096c7bf
import
numpy
as
np
import
numpy
as
np
import
densecrf
as
dcrf
import
pydensecrf.densecrf
as
dcrf
# TODO: Make this real unit-tests some time in the future...
# Tests for specific issues
###########################
# Via e-mail: crash when non-float32 compat
d
=
dcrf
.
DenseCRF2D
(
10
,
10
,
2
)
d
.
setUnaryEnergy
(
np
.
ones
((
2
,
10
*
10
),
dtype
=
np
.
float32
))
compat
=
np
.
array
([
1.0
,
2.0
])
try
:
d
.
addPairwiseBilateral
(
sxy
=
(
3
,
3
),
srgb
=
(
3
,
3
,
3
),
rgbim
=
np
.
zeros
((
10
,
10
,
3
),
np
.
uint8
),
compat
=
compat
)
d
.
inference
(
2
)
raise
TypeError
(
"Didn't raise an exception, but should because compat dtypes don't match!!"
)
except
ValueError
:
pass
# That's what we want!
# The following is not a really good unittest, but was the first tests.
###########################
# d = densecrf.PyDenseCRF2D(3, 2, 3)
# d = densecrf.PyDenseCRF2D(3, 2, 3)
# U = np.full((3,6), 0.1, dtype=np.float32)
# U = np.full((3,6), 0.1, dtype=np.float32)
...
@@ -25,3 +45,4 @@ d.setUnaryEnergy(-np.log(Up))
...
@@ -25,3 +45,4 @@ d.setUnaryEnergy(-np.log(Up))
d
.
addPairwiseBilateral
(
2
,
2
,
img
,
3
)
d
.
addPairwiseBilateral
(
2
,
2
,
img
,
3
)
# d.addPairwiseBilateral(2, 2, img, 3)
# d.addPairwiseBilateral(2, 2, img, 3)
np
.
argmax
(
d
.
inference
(
10
),
axis
=
0
).
reshape
(
10
,
10
)
np
.
argmax
(
d
.
inference
(
10
),
axis
=
0
).
reshape
(
10
,
10
)
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