This pipeline results in images looking like images downsampled with INTERP_NN:
from nvidia.dali.pipeline import Pipeline
import nvidia.dali.ops as ops
import nvidia.dali.types as types
class LanczosPipeline(Pipeline):
def __init__(self, batch_size, num_threads, device_id, file_root):
super().__init__(batch_size, num_threads, device_id)
self.input = ops.FileReader(file_root=file_root)
self.decoder = ops.ImageDecoder(device='mixed')
self.resize = ops.Resize(
device='gpu',
resize_longer=224,
interp_type=types.DALIInterpType.INTERP_LANCZOS3,
)
def define_graph(self):
images, labels = self.input()
images = self.decoder(images)
images = self.resize(images)
return images
dali=0.22.0 installed with pip
We use Lanczos filter as an interpolation filter, not a low-pass filter, and therefore the behavior is more or less expected. Current solution would be to use a different filter (e.g. Gaussian) for downscaling than upscaling, which can be done with:
min_flter=types.INTERP_GAUSSIAN, mag_filter=types.INTERP_LANCZOS3.
We can think about changing how INTERP_LANCZOS3 behaves when downscaling, since now it's admittedly not very useful for that purpose.
We use PIL.Image resize with Image.LANCZOS (==Image.ANTIALIAS) interpolation type, and it gives a way better results applying to image features calculation. With INTERP_GAUSSIAN the edges in downsampled image are significantly blurried, resulting images are visually less detailed than images resized by PIL with lanczos.
We'll look into it, but the earliest possible release with Lanczos downsampling fixed is 0.24, if we scope it for the release.
@ei-grad The fix is already on master branch, it should be there in release 0.24 and, of course, next nightly build.
0.24 has been released. Please check if that works for you.
Thanks! We now using DALI for inference, works like a charm. Images are visually identical with PIL, though it gives some difference on pixel values.
@ei-grad - we are happy that it works as you like!