Skip to content

Commit

Permalink
Fix visualization when palette is None (#1177)
Browse files Browse the repository at this point in the history
The palette may be `None`when working with grayscale labels.
Fix #1147
  • Loading branch information
gheinrich authored and lukeyeager committed Oct 18, 2016
1 parent d14960f commit 79619d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion digits/dataset/generic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ def explore():
db_path = job.path(db)
labels = []

if COLOR_PALETTE_ATTRIBUTE in job.extension_userdata:
if COLOR_PALETTE_ATTRIBUTE in job.extension_userdata \
and job.extension_userdata[COLOR_PALETTE_ATTRIBUTE]:
# assume single-channel 8-bit palette
palette = job.extension_userdata[COLOR_PALETTE_ATTRIBUTE]
palette = np.array(palette).reshape((len(palette)/3,3)) / 255.
Expand Down
5 changes: 3 additions & 2 deletions digits/extensions/view/imageSegmentation/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def __init__(self, dataset, **kwargs):

# view options
if kwargs['colormap'] == 'dataset':
if not COLOR_PALETTE_ATTRIBUTE in dataset.extension_userdata:
raise ValueError("Palette not found in dataset")
if not COLOR_PALETTE_ATTRIBUTE in dataset.extension_userdata or \
not dataset.extension_userdata[COLOR_PALETTE_ATTRIBUTE]:
raise ValueError("No palette found in dataset - choose other colormap")
palette = dataset.extension_userdata[COLOR_PALETTE_ATTRIBUTE]
# assume 8-bit RGB palette and convert to N*3 numpy array
palette = np.array(palette).reshape((len(palette)/3,3)) / 255.
Expand Down

0 comments on commit 79619d9

Please sign in to comment.