Skip to content

Commit

Permalink
fix PIL deprecation warning (#677)
Browse files Browse the repository at this point in the history
* fix PIL deprecation warning
  • Loading branch information
lanpa committed Dec 11, 2022
1 parent 52f8bd2 commit 9356270
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tensorboardX/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,20 @@ def draw_boxes(disp_image, boxes, labels=None):

def make_image(tensor, rescale=1, rois=None, labels=None):
"""Convert an numpy representation image to Image protobuf"""
import PIL
from PIL import Image
from packaging.version import parse
height, width, channel = tensor.shape
scaled_height = int(height * rescale)
scaled_width = int(width * rescale)
image = Image.fromarray(tensor)
if rois is not None:
image = draw_boxes(image, rois, labels=labels)
image = image.resize((scaled_width, scaled_height), Image.ANTIALIAS)
if parse(PIL.__version__) >= parse('9.1.0'):
image = image.resize((scaled_width, scaled_height), Image.Resampling.LANCZOS)
else:
image = image.resize((scaled_width, scaled_height), Image.LANCZOS)

import io
output = io.BytesIO()
image.save(output, format='PNG')
Expand Down

0 comments on commit 9356270

Please sign in to comment.