Skip to content
This repository was archived by the owner on Oct 14, 2023. It is now read-only.

Commit ceca157

Browse files
committed
Fix convert colorspace to support RGBA input (PNGs)
1 parent 92674f0 commit ceca157

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

v2functions/http-trigger-onnx-model/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ def run_inference(image, context):
3737
original_image_size = image.size[0], image.size[1]
3838
logging.info('Preprocessing image...')
3939
# Model expects a 224x224 shape input
40-
image = image.resize((224, 224), Image.ANTIALIAS)
40+
image = image.resize((224, 224), Image.LANCZOS)
41+
bands = image.getbands()
42+
if bands == ('R', 'G', 'B'):
43+
logging.info(f'Image is RGB. No conversion necessary.')
44+
else:
45+
logging.info(f'Image is {bands}, converting to RGB...')
46+
image = image.convert('RGB')
47+
4148
x = np.array(image).astype('float32')
4249
x = np.transpose(x, [2, 0, 1])
4350
x = np.expand_dims(x, axis=0)

0 commit comments

Comments
 (0)