Exemplo n.º 1
0
    def __init__(self, DATA_PATH, input_height, batch_size, num_threads,
                 device_id):
        super(SimCLRTrainDataTransform, self).__init__(batch_size,
                                                       num_threads,
                                                       device_id,
                                                       seed=12)

        self.COPIES = 3

        self.input_height = input_height
        self.input = ops.FileReader(file_root=DATA_PATH,
                                    random_shuffle=True,
                                    seed=12)

        self.coin = ops.CoinFlip(probability=0.5)
        self.uniform = ops.Uniform(range=[0.7, 1.3])  #-1 to 1
        #read image (I think that has to be cpu, do a mixed operation to decode into gpu)
        self.decode = ops.ImageDecoder(device='mixed', output_type=types.RGB)
        self.crop = ops.RandomResizedCrop(size=self.input_height, device="gpu")
        self.flip = ops.Flip(vertical=self.coin(),
                             horizontal=self.coin(),
                             device="gpu")
        self.colorjit_gray = ops.ColorTwist(brightness=self.uniform(),
                                            contrast=self.uniform(),
                                            hue=self.uniform(),
                                            saturation=self.uniform(),
                                            device="gpu")
        self.blur = ops.GaussianBlur(window_size=int(0.1 * self.input_height),
                                     device="gpu")
        self.swapaxes = ops.Transpose(perm=[2, 0, 1], device="gpu")

        self.to_int64 = ops.Cast(dtype=types.INT64, device="gpu")
    def __init__(self,
                 DATA_PATH,
                 input_height,
                 batch_size,
                 copies,
                 stage,
                 num_threads,
                 device_id,
                 seed=1729):
        super(SimCLRTransform, self).__init__(batch_size,
                                              num_threads,
                                              device_id,
                                              seed=seed)

        #this lets our pytorch compat function find the length of our dataset
        self.num_samples = len(ImageFolder(DATA_PATH))

        self.copies = copies
        self.input_height = input_height
        self.stage = stage

        self.input = ops.FileReader(file_root=DATA_PATH,
                                    random_shuffle=True,
                                    seed=seed)
        self.to_int64 = ops.Cast(dtype=types.INT64, device="gpu")
        self.to_int32_cpu = ops.Cast(dtype=types.INT32, device="cpu")

        self.coin = ops.random.CoinFlip(probability=0.5)
        self.uniform = ops.random.Uniform(range=[0.6, 0.9])
        self.blur_amt = ops.random.Uniform(values=[
            float(i) for i in range(1, int(0.1 * self.input_height), 2)
        ])
        self.angles = ops.random.Uniform(range=[0, 360])
        self.cast = ops.Cast(dtype=types.FLOAT, device='gpu')
        self.decode = ops.ImageDecoder(device='mixed', output_type=types.RGB)

        self.crop = ops.RandomResizedCrop(size=self.input_height,
                                          minibatch_size=batch_size,
                                          random_area=[0.75, 1.0],
                                          device="gpu")
        self.resize = ops.Resize(resize_x=self.input_height,
                                 resize_y=self.input_height,
                                 device="gpu")
        self.flip = ops.Flip(vertical=self.coin(),
                             horizontal=self.coin(),
                             device="gpu")
        self.colorjit_gray = ops.ColorTwist(brightness=self.uniform(),
                                            contrast=self.uniform(),
                                            hue=self.uniform(),
                                            saturation=self.uniform(),
                                            device="gpu")
        self.blur = ops.GaussianBlur(window_size=self.to_int32_cpu(
            self.blur_amt()),
                                     device="gpu")
        self.rotate = ops.Rotate(
            angle=self.angles(),
            keep_size=True,
            interp_type=types.DALIInterpType.INTERP_LINEAR,
            device="gpu")
        self.swapaxes = ops.Transpose(perm=[2, 0, 1], device="gpu")
Exemplo n.º 3
0
    def __new__(cls, sigma=None, window_size=None, dtype=None, **kwargs):
        """Create a ``GaussianBlur`` operator.

        Parameters
        ----------
        sigma : Union[float, Sequence[float]], optional
            The sigma value to gaussian kernel.
        window_size : Union[int, Sequence[int]], optional
            The window size to gaussian kernel.
        dtype : str, optional
            The output data type.

        Returns
        -------
        nvidia.dali.ops.GaussianBlur
            The operator.

        """
        if isinstance(dtype, six.string_types):
            dtype = getattr(types, dtype.upper())
        return ops.GaussianBlur(sigma=sigma,
                                window_size=window_size,
                                dtype=dtype,
                                device=context.get_device_type(),
                                **kwargs)
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.inp = ops.ExternalSource(num_outputs=num_outputs)
     self.gb = ops.GaussianBlur(window_size=3)