Skip to content

Commit b6c9302

Browse files
committed
Add more logging
Signed-off-by: M Q <[email protected]>
1 parent 33db3c5 commit b6c9302

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

monai/deploy/operators/decoder_nvimgcodec.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def _decode_frame(src: bytes, runner: DecodeRunner) -> bytearray | bytes
5959

6060
import inspect
6161
import logging
62+
import numpy as np
6263
import sys
6364
from pathlib import Path
6465
from typing import Any, Callable, Iterable
@@ -184,16 +185,52 @@ def _decode_frame(src: bytes, runner: DecodeRunner) -> bytearray | bytes:
184185

185186
# Double check if the transfer syntax is supported although the runner should be correct.
186187
tsyntax = runner.transfer_syntax
188+
_logger.info(f"transfer_syntax: {tsyntax}")
189+
187190
if not is_available(tsyntax):
188191
raise ValueError(f"Transfer syntax {tsyntax} not supported; see details in the debug log.")
189192

190-
nvimgcodec_decoder = nvimgcodec.Decoder()
191-
decode_params = nvimgcodec.DecodeParams(allow_any_depth=True, color_spec=nvimgcodec.ColorSpec.UNCHANGED)
193+
# Source image frame attributes
194+
rows = getattr(runner, 'rows', None)
195+
columns = getattr(runner, 'columns', None)
196+
samples_per_pixel = getattr(runner, 'samples_per_pixel', None)
197+
192198

193-
decoded_data = nvimgcodec_decoder.decode(src, params=decode_params)
194-
return bytearray(decoded_data.cpu()) # HWC layout, interleaved format, and contiguous array in C-style
199+
_logger.info("Source image frame attributes from DecodeRunner:")
200+
_logger.info(f"rows: {rows}")
201+
_logger.info(f"columns: {columns}")
202+
_logger.info(f"samples_per_pixel: {samples_per_pixel}")
203+
_logger.info(f"number_of_frames: {getattr(runner, 'number_of_frames', None)}") # Multi frame image, but one frame at a time
204+
_logger.info(f"index: {getattr(runner, 'index', None)}") # Current frame index in the image
205+
_logger.info(f"frame_length: {runner.frame_length()}") # Multi frame image, but one frame at a time
206+
_logger.info(f"extended_offsets: {getattr(runner, 'extended_offsets', None)}") # Multi frame image, but one frame at a time
207+
_logger.info(f"pixel_representation: {getattr(runner, 'pixel_representation', None)}")
208+
_logger.info(f"bits_allocated: {getattr(runner, 'bits_allocated', None)}")
209+
_logger.info(f"bits_stored: {getattr(runner, 'bits_stored', None)}")
210+
_logger.info(f"photometric_interpretation: {getattr(runner, 'photometric_interpretation', None)}")
211+
_logger.info(f"pixel_representation: {getattr(runner, 'pixel_representation', None)}")
212+
_logger.info(f"planar_configuration: {getattr(runner, 'planar_configuration', None)}")
195213

196214

215+
nvimgcodec_decoder = nvimgcodec.Decoder()
216+
decode_params = nvimgcodec.DecodeParams(allow_any_depth=True, color_spec=nvimgcodec.ColorSpec.UNCHANGED)
217+
decoded_data = nvimgcodec_decoder.decode(src, params=decode_params) # HWC layout, interleaved format, and contiguous array in C-style
218+
219+
_logger.info("Decoded data attributes:")
220+
_logger.info(f"decoded_data shape: {decoded_data.shape}")
221+
_logger.info(f"decoded_data dtype: {decoded_data.dtype}")
222+
_logger.info(f"decoded_data strides: {decoded_data.strides}")
223+
_logger.info(f"decoded_data width: {decoded_data.width}")
224+
_logger.info(f"decoded_data height: {decoded_data.height}")
225+
_logger.info(f"decoded_data ndim: {decoded_data.ndim}")
226+
_logger.info(f"decoded_data precision: {decoded_data.precision}")
227+
_logger.info(f"decoded_data buffer_kind: {decoded_data.buffer_kind}")
228+
229+
_logger.info("Decoded data copied to system memory:")
230+
superface = np.asarray(decoded_data.cpu())
231+
np.ascontiguousarray(superface)
232+
return superface.tobytes()
233+
197234
def _is_nvimgcodec_available() -> bool:
198235
"""Return ``True`` if nvimgcodec is available, ``False`` otherwise."""
199236

@@ -209,7 +246,6 @@ def _is_nvimgcodec_available() -> bool:
209246

210247
# Helper functions for an application to register this decoder plugin with Pydicom at application startup.
211248

212-
213249
def register_as_decoder_plugin(module_path: str | None = None) -> bool:
214250
"""Register as a preferred decoder plugin with supported decoder classes.
215251

monai/deploy/operators/monai_seg_inference_operator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,10 @@ def _get_meta_dict(self, img: Image) -> Dict:
576576

577577
# Referring to the MONAI ITKReader, the spacing is simply a NumPy array from the ITK image
578578
# GetSpacing, in WHD.
579+
img_meta_dict["row_pixel_spacing"] = img_meta_dict.get("row_pixel_spacing", 1.0)
580+
img_meta_dict["col_pixel_spacing"] = img_meta_dict.get("col_pixel_spacing", 1.0)
581+
img_meta_dict["depth_pixel_spacing"] = img_meta_dict.get("depth_pixel_spacing", 1.0)
582+
579583
meta_dict["spacing"] = np.asarray(
580584
[
581585
img_meta_dict["row_pixel_spacing"],

0 commit comments

Comments
 (0)