diff --git a/examples/YOLOv8-Segmentation-ONNXRuntime-Python/main.py b/examples/YOLOv8-Segmentation-ONNXRuntime-Python/main.py index f479d2ae28..6b57d473bb 100644 --- a/examples/YOLOv8-Segmentation-ONNXRuntime-Python/main.py +++ b/examples/YOLOv8-Segmentation-ONNXRuntime-Python/main.py @@ -79,9 +79,7 @@ class YOLOv8Seg: predictions = self.session.run(None, {self.session.get_inputs()[0].name: processed_image}) # Post-process - results = self.postprocess(im0, processed_image, predictions) - - return results + return self.postprocess(im0, processed_image, predictions) def preprocess(self, image, new_shape: Union[Tuple, List] = (640, 640)): """ @@ -99,8 +97,7 @@ class YOLOv8Seg: """ image, _, _ = self.__resize_and_pad_image(image=image, new_shape=new_shape) image = self.__reshape_image(image=image) - processed_image = image[None] if len(image.shape) == 3 else image - return processed_image + return image[None] if len(image.shape) == 3 else image def __reshape_image(self, image: np.ndarray) -> np.ndarray: """ @@ -117,8 +114,7 @@ class YOLOv8Seg: """ image = image.transpose([2, 0, 1]) image = image[np.newaxis, ...] - image = np.ascontiguousarray(image).astype(np.float32) / 255 - return image + return np.ascontiguousarray(image).astype(np.float32) / 255 def __resize_and_pad_image( self, image=np.ndarray, new_shape: Union[Tuple, List] = (640, 640), color: Union[Tuple, List] = (114, 114, 114) diff --git a/ultralytics/engine/exporter.py b/ultralytics/engine/exporter.py index f185d6a105..099ee45596 100644 --- a/ultralytics/engine/exporter.py +++ b/ultralytics/engine/exporter.py @@ -309,9 +309,8 @@ class Exporter: "WARNING ⚠️ INT8 export requires a missing 'data' arg for calibration. " f"Using default 'data={self.args.data}'." ) - if tfjs: - if ARM64 and LINUX: - raise SystemError("TensorFlow.js export not supported on ARM64 Linux") + if tfjs and (ARM64 and LINUX): + raise SystemError("TensorFlow.js export not supported on ARM64 Linux") # Input im = torch.zeros(self.args.batch, 3, *self.imgsz).to(self.device) diff --git a/ultralytics/nn/autobackend.py b/ultralytics/nn/autobackend.py index e563e06292..7629fb7ca8 100644 --- a/ultralytics/nn/autobackend.py +++ b/ultralytics/nn/autobackend.py @@ -197,12 +197,13 @@ class AutoBackend(nn.Module): import onnxruntime providers = ["CPUExecutionProvider"] - if cuda and "CUDAExecutionProvider" in onnxruntime.get_available_providers(): - providers.insert(0, "CUDAExecutionProvider") - elif cuda: # Only log warning if CUDA was requested but unavailable - LOGGER.warning("WARNING ⚠️ Failed to start ONNX Runtime with CUDA. Using CPU...") - device = torch.device("cpu") - cuda = False + if cuda: + if "CUDAExecutionProvider" in onnxruntime.get_available_providers(): + providers.insert(0, "CUDAExecutionProvider") + else: # Only log warning if CUDA was requested but unavailable + LOGGER.warning("WARNING ⚠️ Failed to start ONNX Runtime with CUDA. Using CPU...") + device = torch.device("cpu") + cuda = False LOGGER.info(f"Using ONNX Runtime {providers[0]}") if onnx: session = onnxruntime.InferenceSession(w, providers=providers) @@ -223,7 +224,7 @@ class AutoBackend(nn.Module): output_names = [x.name for x in session.get_outputs()] metadata = session.get_modelmeta().custom_metadata_map dynamic = isinstance(session.get_outputs()[0].shape[0], str) - fp16 = True if "float16" in session.get_inputs()[0].type else False + fp16 = "float16" in session.get_inputs()[0].type if not dynamic: io = session.io_binding() bindings = [] diff --git a/ultralytics/utils/torch_utils.py b/ultralytics/utils/torch_utils.py index 83eb303725..f2dbfbc64b 100644 --- a/ultralytics/utils/torch_utils.py +++ b/ultralytics/utils/torch_utils.py @@ -317,8 +317,7 @@ def model_info(model, detailed=False, verbose=True, imgsz=640): if len(m._parameters): for pn, p in m.named_parameters(): LOGGER.info( - f"{i:>5g}{mn + '.' + pn:>40}{mt:>20}{p.requires_grad!r:>10}{p.numel():>12g}" - f"{str(list(p.shape)):>20}{p.mean():>10.3g}{p.std():>10.3g}{str(p.dtype).replace('torch.', ''):>15}" + f"{i:>5g}{f'{mn}.{pn}':>40}{mt:>20}{p.requires_grad!r:>10}{p.numel():>12g}{str(list(p.shape)):>20}{p.mean():>10.3g}{p.std():>10.3g}{str(p.dtype).replace('torch.', ''):>15}" ) else: # layers with no learnable params LOGGER.info(f"{i:>5g}{mn:>40}{mt:>20}{False!r:>10}{0:>12g}{str([]):>20}{'-':>10}{'-':>10}{'-':>15}")