Skip to content

Commit

Permalink
fix: Display demo utils gallery with arbitrary number of images (#2479)
Browse files Browse the repository at this point in the history
* fix: Display gallery with arbitrary number of images

* fix: Reduce hardcoded if statements
  • Loading branch information
thomas-coldwell authored Aug 20, 2024
1 parent 7131e7f commit ba2556c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ wheels
.devcontainer/
.coverage
.history

# Common env config file use by pyenv
.python_version
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
keras
10 changes: 8 additions & 2 deletions examples/layers/preprocessing/bounding_box/demo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utility functions for preprocessing demos."""
import math

import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
Expand Down Expand Up @@ -84,9 +86,13 @@ def visualize_bounding_boxes(image, bounding_boxes, bounding_box_format):

def gallery_show(images):
images = images.astype(int)
for i in range(9):
image_count = len(images)
max_columns = 3
cols = min(image_count, max_columns)
rows = math.ceil(image_count / max_columns)
for i in range(len(images)):
image = images[i]
plt.subplot(3, 3, i + 1)
plt.subplot(rows, cols, i + 1)
plt.imshow(image.astype("uint8"))
plt.axis("off")
plt.show()

0 comments on commit ba2556c

Please sign in to comment.