Using 8bit images
This commit is contained in:
@@ -72,8 +72,9 @@ def apply_ultralytics_16bit_tiff_patches(*, force: bool = False) -> None:
|
|||||||
# logger.info(f"Loading with monkey-patched imread: {filename}")
|
# logger.info(f"Loading with monkey-patched imread: {filename}")
|
||||||
arr = arr.astype(np.float32)
|
arr = arr.astype(np.float32)
|
||||||
arr /= arr.max()
|
arr /= arr.max()
|
||||||
arr *= 2**16 - 1
|
arr *= 2**8 - 1
|
||||||
arr = arr.astype(np.uint16)
|
arr = arr.astype(np.uint8)
|
||||||
|
# print(arr.shape, arr.dtype, any(np.isnan(arr).flatten()), np.where(np.isnan(arr)), arr.min(), arr.max())
|
||||||
return np.ascontiguousarray(arr)
|
return np.ascontiguousarray(arr)
|
||||||
|
|
||||||
# logger.info(f"Loading with original imread: {filename}")
|
# logger.info(f"Loading with original imread: {filename}")
|
||||||
@@ -105,7 +106,7 @@ def apply_ultralytics_16bit_tiff_patches(*, force: bool = False) -> None:
|
|||||||
def preprocess_batch_16bit(self, batch: dict) -> dict: # type: ignore[override]
|
def preprocess_batch_16bit(self, batch: dict) -> dict: # type: ignore[override]
|
||||||
# Start from upstream behavior to keep device placement + multiscale identical,
|
# Start from upstream behavior to keep device placement + multiscale identical,
|
||||||
# but replace the 255 division with dtype-aware scaling.
|
# but replace the 255 division with dtype-aware scaling.
|
||||||
logger.info(f"Preprocessing batch with monkey-patched preprocess_batch")
|
# logger.info(f"Preprocessing batch with monkey-patched preprocess_batch")
|
||||||
for k, v in batch.items():
|
for k, v in batch.items():
|
||||||
if isinstance(v, torch.Tensor):
|
if isinstance(v, torch.Tensor):
|
||||||
batch[k] = v.to(self.device, non_blocking=self.device.type == "cuda")
|
batch[k] = v.to(self.device, non_blocking=self.device.type == "cuda")
|
||||||
|
|||||||
Reference in New Issue
Block a user