(self, forward_fn, model_input, tile_size, tile_stride, tile_batch_size=1, tile_device="cpu", tile_dtype=torch.float32, border_width=None)
| 81 | |
| 82 | |
| 83 | def tiled_forward(self, forward_fn, model_input, tile_size, tile_stride, tile_batch_size=1, tile_device="cpu", tile_dtype=torch.float32, border_width=None): |
| 84 | # Prepare |
| 85 | inference_device, inference_dtype = model_input.device, model_input.dtype |
| 86 | height, width = model_input.shape[2], model_input.shape[3] |
| 87 | border_width = int(tile_stride*0.5) if border_width is None else border_width |
| 88 | |
| 89 | # tile |
| 90 | model_input = self.tile(model_input, tile_size, tile_stride, tile_device, tile_dtype) |
| 91 | |
| 92 | # inference |
| 93 | model_output = self.tiled_inference(forward_fn, model_input, tile_batch_size, inference_device, inference_dtype, tile_device, tile_dtype) |
| 94 | |
| 95 | # resize |
| 96 | io_scale = self.io_scale(model_output, tile_size) |
| 97 | height, width = int(height*io_scale), int(width*io_scale) |
| 98 | tile_size, tile_stride = int(tile_size*io_scale), int(tile_stride*io_scale) |
| 99 | border_width = int(border_width*io_scale) |
| 100 | |
| 101 | # untile |
| 102 | model_output = self.untile(model_output, height, width, tile_size, tile_stride, border_width, tile_device, tile_dtype) |
| 103 | |
| 104 | # Done! |
| 105 | model_output = model_output.to(device=inference_device, dtype=inference_dtype) |
| 106 | return model_output |
| 107 | |
| 108 | |
| 109 |
nothing calls this directly
no test coverage detected