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
42402df8
Commit
42402df8
authored
May 16, 2016
by
lucasb-eyer
Browse files
Utils example also store output.
So it can be used usefully without matplotlib.
parent
94d1cdda
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
10 deletions
+9
-10
examples/utils_example.py
examples/utils_example.py
+9
-10
No files found.
examples/utils_example.py
View file @
42402df8
...
@@ -6,18 +6,20 @@ import sys
...
@@ -6,18 +6,20 @@ import sys
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
import
pydensecrf.densecrf
as
dcrf
import
pydensecrf.densecrf
as
dcrf
import
matplotlib.pylab
as
plt
from
skimage.segmentation
import
relabel_sequential
from
skimage.segmentation
import
relabel_sequential
from
pydensecrf.utils
import
compute_unary
,
create_pairwise_bilateral
,
\
from
pydensecrf.utils
import
compute_unary
,
create_pairwise_bilateral
,
\
create_pairwise_gaussian
create_pairwise_gaussian
if
len
(
sys
.
argv
)
!=
3
:
if
len
(
sys
.
argv
)
!=
4
:
print
(
"Usage: python {} IMAGE ANNO"
.
format
(
sys
.
argv
[
0
]))
print
(
"Usage: python {} IMAGE ANNO OUTPUT"
.
format
(
sys
.
argv
[
0
]))
print
(
""
)
print
(
"IMAGE and ANNO are inputs and OUTPUT is where the result should be written."
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
fn_im
=
sys
.
argv
[
1
]
fn_im
=
sys
.
argv
[
1
]
fn_anno
=
sys
.
argv
[
2
]
fn_anno
=
sys
.
argv
[
2
]
fn_output
=
sys
.
argv
[
3
]
##################################
##################################
### Read images and annotation ###
### Read images and annotation ###
...
@@ -73,16 +75,13 @@ else:
...
@@ -73,16 +75,13 @@ else:
### Do inference and compute map ###
### Do inference and compute map ###
####################################
####################################
Q
=
d
.
inference
(
5
)
Q
=
d
.
inference
(
5
)
map
=
np
.
argmax
(
Q
,
axis
=
0
).
reshape
(
img
.
shape
[:
2
])
MAP
=
np
.
argmax
(
Q
,
axis
=
0
).
astype
(
'float32'
)
MAP
*=
255
/
MAP
.
max
()
res
=
map
.
astype
(
'float32'
)
*
255
/
map
.
max
()
MAP
=
MAP
.
reshape
(
img
.
shape
[:
2
])
plt
.
imshow
(
res
)
cv2
.
imwrite
(
fn_output
,
MAP
.
astype
(
'uint8'
))
plt
.
show
()
# Manually inference
# Manually inference
Q
,
tmp1
,
tmp2
=
d
.
startInference
()
Q
,
tmp1
,
tmp2
=
d
.
startInference
()
for
i
in
range
(
5
):
for
i
in
range
(
5
):
print
(
"KL-divergence at {}: {}"
.
format
(
i
,
d
.
klDivergence
(
Q
)))
print
(
"KL-divergence at {}: {}"
.
format
(
i
,
d
.
klDivergence
(
Q
)))
d
.
stepInference
(
Q
,
tmp1
,
tmp2
)
d
.
stepInference
(
Q
,
tmp1
,
tmp2
)
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