ultralytics 8.3.230 Fix color conversion for Tensor inputs and PIL plots (#22734)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
2ee91e432a
commit
389b87f8cb
@ -1,6 +1,6 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
__version__ = "8.3.229"
|
||||
__version__ = "8.3.230"
|
||||
|
||||
import importlib
|
||||
import os
|
||||
|
||||
@ -589,7 +589,7 @@ class Results(SimpleClass, DataExportMixin):
|
||||
if save:
|
||||
annotator.save(filename or f"results_{Path(self.path).name}")
|
||||
|
||||
return annotator.im if pil else annotator.result()
|
||||
return annotator.result(pil)
|
||||
|
||||
def show(self, *args, **kwargs):
|
||||
"""Display the image with annotated inference results.
|
||||
|
||||
@ -55,7 +55,7 @@ class RTDETRPredictor(BasePredictor):
|
||||
bboxes, scores = preds[0].split((4, nd - 4), dim=-1)
|
||||
|
||||
if not isinstance(orig_imgs, list): # input images are a torch.Tensor, not a list
|
||||
orig_imgs = ops.convert_torch2numpy_batch(orig_imgs)
|
||||
orig_imgs = ops.convert_torch2numpy_batch(orig_imgs)[..., ::-1]
|
||||
|
||||
results = []
|
||||
for bbox, score, orig_img, img_path in zip(bboxes, scores, orig_imgs, self.batch[0]): # (300, 4)
|
||||
|
||||
@ -502,7 +502,7 @@ class Predictor(BasePredictor):
|
||||
names = dict(enumerate(str(i) for i in range(pred_masks.shape[0])))
|
||||
|
||||
if not isinstance(orig_imgs, list): # input images are a torch.Tensor, not a list
|
||||
orig_imgs = ops.convert_torch2numpy_batch(orig_imgs)
|
||||
orig_imgs = ops.convert_torch2numpy_batch(orig_imgs)[..., ::-1]
|
||||
|
||||
results = []
|
||||
for masks, orig_img, img_path in zip([pred_masks], orig_imgs, self.batch[0]):
|
||||
|
||||
@ -81,7 +81,7 @@ class ClassificationPredictor(BasePredictor):
|
||||
(list[Results]): List of Results objects containing classification results for each image.
|
||||
"""
|
||||
if not isinstance(orig_imgs, list): # Input images are a torch.Tensor, not a list
|
||||
orig_imgs = ops.convert_torch2numpy_batch(orig_imgs)
|
||||
orig_imgs = ops.convert_torch2numpy_batch(orig_imgs)[..., ::-1]
|
||||
|
||||
preds = preds[0] if isinstance(preds, (list, tuple)) else preds
|
||||
return [
|
||||
|
||||
@ -65,7 +65,7 @@ class DetectionPredictor(BasePredictor):
|
||||
)
|
||||
|
||||
if not isinstance(orig_imgs, list): # input images are a torch.Tensor, not a list
|
||||
orig_imgs = ops.convert_torch2numpy_batch(orig_imgs)
|
||||
orig_imgs = ops.convert_torch2numpy_batch(orig_imgs)[..., ::-1]
|
||||
|
||||
if save_feats:
|
||||
obj_feats = self.get_obj_feats(self._feats, preds[1])
|
||||
|
||||
@ -207,7 +207,7 @@ class Annotator:
|
||||
elif im.shape[2] > 3: # multispectral
|
||||
im = np.ascontiguousarray(im[..., :3])
|
||||
if self.pil: # use PIL
|
||||
self.im = im if input_is_pil else Image.fromarray(im)
|
||||
self.im = im if input_is_pil else Image.fromarray(im) # stay in BGR since color palette is in BGR
|
||||
if self.im.mode not in {"RGB", "RGBA"}: # multispectral
|
||||
self.im = self.im.convert("RGB")
|
||||
self.draw = ImageDraw.Draw(self.im, "RGBA")
|
||||
@ -515,9 +515,10 @@ class Annotator:
|
||||
self.im = im if isinstance(im, Image.Image) else Image.fromarray(im)
|
||||
self.draw = ImageDraw.Draw(self.im)
|
||||
|
||||
def result(self):
|
||||
"""Return annotated image as array."""
|
||||
return np.asarray(self.im)
|
||||
def result(self, pil=False):
|
||||
"""Return annotated image as array or PIL image."""
|
||||
im = np.asarray(self.im) # self.im is in BGR
|
||||
return Image.fromarray(im[..., ::-1]) if pil else im
|
||||
|
||||
def show(self, title: str | None = None):
|
||||
"""Show the annotated image."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user