Skip to content

Commit

Permalink
Merge pull request NVIDIA#1290 from gheinrich/dev/segmentation-extens…
Browse files Browse the repository at this point in the history
…ion-helpers

Add info to image segmentation data extension
  • Loading branch information
gheinrich committed Nov 22, 2016
2 parents c5fb49c + 7b13911 commit 1bce875
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions digits/extensions/data/imageSegmentation/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def __init__(self, **kwargs):
lines = f.read().splitlines()
for line in lines:
for val in line.split():
palette.append(int(val))
try:
palette.append(int(val))
except:
raise ValueError("Your color map file seems to "
"be badly formatted: '%s' is not "
"an integer" % val)
# fill rest with zeros
palette = palette + [0] * (256 * 3 - len(palette))
self.userdata[COLOR_PALETTE_ATTRIBUTE] = palette
Expand Down Expand Up @@ -189,11 +194,15 @@ def load_label(self, filename):
if self.userdata['colormap_method'] == "label":
if image.mode not in ['P', 'L', '1']:
raise ValueError("Labels are expected to be single-channel (paletted or "
" grayscale) images - %s mode is '%s'"
" grayscale) images - %s mode is '%s'. If your labels are "
"RGB images then set the 'Color Map Specification' field "
"to 'from text file' and provide a color map text file."
% (filename, image.mode))
else:
if image.mode not in ['RGB']:
raise ValueError("Labels are expected to be RGB images - %s mode is '%s'"
raise ValueError("Labels are expected to be RGB images - %s mode is '%s'. "
"If your labels are palette or grayscale images then set "
"the 'Color Map Specification' field to 'from label image'."
% (filename, image.mode))
image = image.quantize(palette=self.palette_img)

Expand Down
4 changes: 4 additions & 0 deletions digits/extensions/data/imageSegmentation/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@
$("#colormap_method").click(hasColorMapMethodChanged);
hasColorMapMethodChanged();
</script>

<div>
Note: the recommended label encoding is PNG.
</div>

0 comments on commit 1bce875

Please sign in to comment.