Example #1
0
 def __init__(self,mod_AE,ShapeData,NiterProjection,NiterGrad,GradType,OptimType,InterpFlag=False,periodicBnd=False,N_cov=0):
     super(Model_4DVarNN_GradFP, self).__init__()
     self.model_AE = mod_AE
     with torch.no_grad():
         print('Optim type %d'%OptimType)
         self.OptimType   = OptimType
         #self.NRes        = int(NiterResidual)
         self.NRes        = int(3)
         self.NProjFP     = int(NiterProjection)
         self.NGrad       = int(NiterGrad)
         self.Ncov        = N_cov
         self.InterpFlag  = InterpFlag
         self.periodicBnd = periodicBnd
         self.shape       = ShapeData
         # init median pooling
         self.median_pooling = MedianPool2d()
     # Define Solver type according to OptimType
     ## Gradient-based minimization using a fixed-step descent
     if OptimType == 0:
         self.model_Grad = model_GradUpdate0(replace_tup_at_idx(self.shape,0,int(self.shape[0]/(self.Ncov+1))),GradType)
     ## Gradient-based minimization using a CNN using a (sub)gradient as inputs 
     elif OptimType == 1:
         self.model_Grad = model_GradUpdate1(replace_tup_at_idx(self.shape,0,int(self.shape[0]/(self.Ncov+1))),GradType,self.periodicBnd)
     ## Gradient-based minimization using a LSTM using a (sub)gradient as inputs
     elif OptimType == 2:
         self.model_Grad = model_GradUpdate2(replace_tup_at_idx(self.shape,0,int(self.shape[0]/(self.Ncov+1))),GradType,self.periodicBnd)
     elif OptimType == 3:
         self.model_Grad = model_GradUpdate2(replace_tup_at_idx(self.shape,0,int(self.shape[0]/(self.Ncov+1))),GradType,30)
Example #2
0
 def __init__(self):
     super(PatchTransformer, self).__init__()
     self.min_contrast = 0.8
     self.max_contrast = 1.2
     self.min_brightness = -0.1
     self.max_brightness = 0.1
     self.noise_factor = 0.10
     self.minangle = -20 / 180 * math.pi
     self.maxangle = 20 / 180 * math.pi
     self.medianpooler = MedianPool2d(7, same=True)
     '''
 def __init__(self, config, width, height):
     super(AdvPatch, self).__init__()
     self.config = config
     self.model_width = width
     self.model_height = height
     self.min_contrast = 0.8
     self.max_contrast = 1.2
     self.min_brightness = -0.1
     self.max_brightness = 0.1
     self.noise_factor = 0.10
     self.medianpooler = MedianPool2d(3, same=True)
Example #4
0
    def __init__(self):
        super(PatchTransformer_glasses, self).__init__()

        self.min_contrast = 0.8
        self.max_contrast = 1.2
        self.min_brightness = -0.1
        self.max_brightness = 0.1
        self.noise_factor = 0.10
        self.minangle = -10 / 180 * math.pi
        self.maxangle = 10 / 180 * math.pi
        self.medianpooler = MedianPool2d(
            7, same=True)  # kernel_size = 7? see again
    def __init__(self):
        super(PatchTransformer, self).__init__()

        # os.environ['CUDA_VISIBLE_DEVICES'] = '3'
        # self.device = 'cuda:3' if torch.cuda.is_available() else 'cpu'

        self.min_contrast = 0.8
        self.max_contrast = 1.2
        self.min_brightness = -0.1
        self.max_brightness = 0.1
        self.noise_factor = 0.10
        self.minangle = -20 / 180 * math.pi
        self.maxangle = 20 / 180 * math.pi
        self.medianpooler = MedianPool2d(
            7, same=True)  # kernel_size = 7? see again
        '''
Example #6
0
 def __init__(self, config):
     super(RenderModel, self).__init__()
     self.config = config
     self.min_contrast = 0.8
     self.max_contrast = 1.2
     self.min_brightness = -0.1
     self.max_brightness = 0.1
     self.noise_factor = 0.10
     # if self.config.cuda is not '-1':
     #     torch.cuda.set_device(self.config.cuda)
     #     self.device = torch.device('cuda')
     # else:
     #     self.device = torch.device('cpu')
     # if self.config.consistent:
     #     self.grad_textures = grad_textutres.unsqueeze(-2).unsqueeze(-2).unsqueeze(-2)\
     #         .expand(self.config.depth * self.config.width * self.config.height, 4, 4, 4, 3)
     # else:
     #     self.grad_textures = grad_textutres
     # self.grad_textures = grad_textutres
     # self.grad_textures = grad_textutres.expand(self.config.depth * self.config.width * self.config.height,
     #                                            4, 4, 4, 3)
     self.darknet_model = Darknet(self.config.cfgfile)
     self.darknet_model.load_weights(self.config.weightfile)
     self.darknet_model = self.darknet_model.eval().cuda()
     # for p in self.darknet_model.parameters():
     #     p.requires_grad = False
     # self.cubic = nn.Parameter(torch.full((1, 4, 4, 4, 3), 0.5).cuda())
     # self.Xembedding = torch.nn.Embedding(100, 256)
     # self.Yembedding = torch.nn.Embedding(100, 256)
     # self.Zembedding = torch.nn.Embedding(100, 256)
     # self.linear1 = nn.Linear(768, 192)
     # self.linear2 = nn.Linear(256, 64)
     # self.linear3 = nn.Linear(256, 64)
     # self.linear4 = nn.Linear(192, 192)
     # self.softmax = nn.Softmax(dim=2)
     # self.convtranspose = nn.ConvTranspose3d(3, 3, (3, 3, 3), stride=1)
     self.prob_extractor = MaxProbExtractor(0, 80).cuda()
     self.nps_calculator = NPSCalculator(self.config.printfile,
                                         self.config.image_size).cuda()
     self.total_variation = TotalVariation().cuda()
     self.medianpooler = MedianPool2d(7, same=True)
     renderer = nr.Renderer(camera_mode='look_at')
     renderer.perspective = False
     renderer.light_intensity_directional = 0.0
     renderer.light_intensity_ambient = 1.0
     self.renderer = renderer