From b95859da0bcb67c56e53633ef3da6567a68bad82 Mon Sep 17 00:00:00 2001 From: Rodrigo Berriel Date: Wed, 11 Jan 2023 11:37:04 -0300 Subject: [PATCH] Fix HRNet dimension error on images with alpha channel (#5570) This is pretty much the same fix applied to f-BRS in #5384. We've been using HRNet for a while and now an then we receive "500 errors" just as reported in #5299 when someone forgets to drop the alpha-channel from our images. ### Motivation and context The RuntimeError is a little bit different, but comes from the same issue: RGBA instead of RGB images: > RuntimeError: Given groups=1, weight of size [16, 3, 1, 1], expected input[*, 4, *, *] to have 3 channels, but got 4 channels instead. ### How has this been tested? I created a task with images with and w/o alpha channel, and the interactor works on both now. --- CHANGELOG.md | 1 + serverless/pytorch/saic-vul/hrnet/nuclio/main.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b8b48a2dae3..33f105e23e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Helm: Empty password for Redis () +- Fixed HRNet serverless function runtime error on images with alpha channel () - Preview & chunk cache settings are ignored () ### Security diff --git a/serverless/pytorch/saic-vul/hrnet/nuclio/main.py b/serverless/pytorch/saic-vul/hrnet/nuclio/main.py index 3ac93ae54a82..2968ccf7db29 100644 --- a/serverless/pytorch/saic-vul/hrnet/nuclio/main.py +++ b/serverless/pytorch/saic-vul/hrnet/nuclio/main.py @@ -24,7 +24,7 @@ def handler(context, event): neg_points = data["neg_points"] threshold = data.get("threshold", 0.5) buf = io.BytesIO(base64.b64decode(data["image"])) - image = Image.open(buf) + image = Image.open(buf).convert('RGB') mask, polygon = context.user_data.model.handle(image, pos_points, neg_points, threshold)