'Lazy initialization of preprocessor model in case we don\'t need any image preprocessing.'

def init_cnn(self):

    try:
        import torch
    except ModuleNotFoundError:
        raise ModuleNotFoundError('Need    to    install    Pytorch:    go    to    pytorch.org')
    from torch.autograd import Variable
    import torchvision
    import torchvision.transforms as transforms
    import torch.nn as nn
    opt = self.opt
    self.image_size = opt['image_size']
    self.crop_size = opt['image_cropsize']
    self.datatype = opt['datatype']
    self.image_mode = opt['image_mode']
    opt['cuda'] = ((not opt['no_cuda']) and torch.cuda.is_available())
    self.use_cuda = opt['cuda']
    if self.use_cuda:
        print '[    Using    CUDA    ]'
        torch.cuda.set_device(opt['gpu'])
    (cnn_type, layer_num) = self.image_mode_switcher()
    CNN = getattr(torchvision.models, cnn_type)
    self.netCNN = nn.Sequential(*list(CNN(pretrained=True).children())[:layer_num])
    self.transform = transforms.Compose([transforms.Scale(self.image_size), transforms.CenterCrop(self.crop_size), transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])
    self.xs = torch.FloatTensor(1, 3, self.crop_size, self.crop_size).fill_(0)
    if self.use_cuda:
        self.cuda()
        self.xs = self.xs.cuda()
    self.xs = Variable(self.xs)
