Commit 42402df8 authored by lucasb-eyer's avatar lucasb-eyer
Browse files

Utils example also store output.

So it can be used usefully without matplotlib.
parent 94d1cdda
...@@ -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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment