Skip to content

Commit ba2556c

Browse files
fix: Display demo utils gallery with arbitrary number of images (#2479)
* fix: Display gallery with arbitrary number of images * fix: Reduce hardcoded if statements
1 parent 7131e7f commit ba2556c

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ wheels
2323
.devcontainer/
2424
.coverage
2525
.history
26+
27+
# Common env config file use by pyenv
28+
.python_version

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
keras

examples/layers/preprocessing/bounding_box/demo_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"""Utility functions for preprocessing demos."""
15+
import math
16+
1517
import matplotlib.pyplot as plt
1618
import numpy as np
1719
import tensorflow as tf
@@ -84,9 +86,13 @@ def visualize_bounding_boxes(image, bounding_boxes, bounding_box_format):
8486

8587
def gallery_show(images):
8688
images = images.astype(int)
87-
for i in range(9):
89+
image_count = len(images)
90+
max_columns = 3
91+
cols = min(image_count, max_columns)
92+
rows = math.ceil(image_count / max_columns)
93+
for i in range(len(images)):
8894
image = images[i]
89-
plt.subplot(3, 3, i + 1)
95+
plt.subplot(rows, cols, i + 1)
9096
plt.imshow(image.astype("uint8"))
9197
plt.axis("off")
9298
plt.show()

0 commit comments

Comments
 (0)