From 539121aaf3b1e93188d6ad5253ecff3674dd92c5 Mon Sep 17 00:00:00 2001 From: wxywb Date: Thu, 7 Jul 2022 17:09:59 +0800 Subject: [PATCH] adjust for batch data. Signed-off-by: wxywb --- clipcap.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/clipcap.py b/clipcap.py index 635b5c9..7c7c5f9 100644 --- a/clipcap.py +++ b/clipcap.py @@ -59,15 +59,29 @@ class ClipCap(NNOperator): @arg(1, to_image_color('RGB')) - def __call__(self, data): - vec = self._inference_from_image(data) - return vec + def inference_single_data(self, data): + text = self._inference_from_image(data) + return text def _preprocess(self, img): img = to_pil(img) processed_img = self.clip_tfms(img).unsqueeze(0).to(self.device) return processed_img + def __call__(self, data): + if not isinstance(data, list): + data = [data] + else: + data = data + results = [] + for single_data in data: + result = self.inference_single_data(single_data) + results.append(result) + if len(data) == 1: + return results[0] + else: + return results + @arg(1, to_image_color('RGB')) def _inference_from_image(self, img): img = self._preprocess(img)