Skip to content

Commit

Permalink
Fix single channel plotting (#631)
Browse files Browse the repository at this point in the history
* Fix single channel plotting

* Improve test_plot covering 1 and 3 channel images
  • Loading branch information
mastercaution committed Jun 4, 2021
1 parent cbad38f commit cc7499c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion foolbox/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ def images(
ax.axis("off")
i = row * ncols + col
if i < len(x):
ax.imshow(x[i])
if x.shape[-1] == 1:
ax.imshow(x[i][:, :, 0])
else:
ax.imshow(x[i])
3 changes: 3 additions & 0 deletions tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def test_plot(dummy: ep.Tensor) -> None:
fbn.plot.images(images, ncols=3)
fbn.plot.images(images, nrows=2, ncols=6)
fbn.plot.images(images, nrows=2, ncols=4)
# test for single channel images
images = ep.zeros(dummy, (10, 32, 32, 1))
fbn.plot.images(images)
with pytest.raises(ValueError):
images = ep.zeros(dummy, (10, 3, 3, 3))
fbn.plot.images(images)
Expand Down

0 comments on commit cc7499c

Please sign in to comment.