Example #1
0
 def __init__(self, base, linthresh, linscale):
     Transform.__init__(self)
     self.base = base
     self.linthresh = linthresh
     self.linscale = linscale
     self._linscale_adj = (linscale / (1.0 - self.base ** -1))
     self._log_base = np.log(base)
Example #2
0
 def __init__(self, base, linthresh):
     Transform.__init__(self)
     self.base = base
     self.linthresh = linthresh
     log_base = np.log(base)
     logb_linthresh = np.log(linthresh) / log_base
     self._linadjust = 1.0 - logb_linthresh
Example #3
0
    def prepTransformation(self):
        """
        Setup of the view and model matrices are done
        """
        BufferHelper.sendUniformToShaders('projection', self.projection_mat,
                                          'm4')

        # setup view matrix
        view_mat = np.array(
            Transform.lookat(Global.EYE, Global.LOOKAT, Global.UP))
        BufferHelper.sendUniformToShaders('view', view_mat, 'm4')

        # setup model matrix
        model_mat = np.matrix(np.identity(4, dtype=np.float32))
        # note that because GLSL uses row major, need to do SRT (instead of TRS)

        # scale
        model_mat *= Transform.scale(self.scale, self.scale, self.scale)

        # rotations
        model_mat *= self.rotationMatrix

        # transform
        model_mat *= self.translationMatrix
        BufferHelper.sendUniformToShaders('model', model_mat, 'm4')
Example #4
0
 def __init__(self, base, linthresh):
     Transform.__init__(self)
     self.base = base
     self.linthresh = linthresh
     self._log_base = np.log(base)
     self._log_linthresh = np.log(linthresh) / self._log_base
     self._linadjust = linthresh / (np.log(linthresh) / self._log_base)
Example #5
0
 def __init__(self, base, linthresh):
     Transform.__init__(self)
     self.base = base
     self.linthresh = linthresh
     self._log_base = np.log(base)
     self._log_linthresh = np.log(linthresh) / self._log_base
     self._linadjust = linthresh / (np.log(linthresh) / self._log_base)
Example #6
0
 def __init__(self, base, nonpos):
     Transform.__init__(self)
     self.base = base
     if nonpos == 'mask':
         self._handle_nonpos = _mask_non_positives
     else:
         self._handle_nonpos = _clip_non_positives
Example #7
0
 def __init__(self, base, linthresh):
     Transform.__init__(self)
     self.base = base
     self.linthresh = linthresh
     log_base = np.log(base)
     logb_linthresh = np.log(linthresh) / log_base
     self._linadjust = 1.0 - logb_linthresh
Example #8
0
 def __init__(self, base, nonpos):
     Transform.__init__(self)
     self.base = base
     if nonpos == 'mask':
         self._handle_nonpos = _mask_non_positives
     else:
         self._handle_nonpos = _clip_non_positives
Example #9
0
 def __init__(self, base, linthresh, linscale):
     Transform.__init__(self)
     symlog = SymmetricalLogScale.SymmetricalLogTransform(base, linthresh, linscale)
     self.base = base
     self.linthresh = linthresh
     self.invlinthresh = symlog.transform(linthresh)
     self.linscale = linscale
     self._linscale_adj = (linscale / (1.0 - self.base ** -1))
Example #10
0
 def __init__(self, base, linthresh):
     Transform.__init__(self)
     self.base = base
     self.linthresh = abs(linthresh)
     self._log_base = np.log(base)
     logb_linthresh = np.log(linthresh) / self._log_base
     self._linadjust = 1.0 - logb_linthresh
     self._linscale = 1.0 / linthresh
Example #11
0
 def __init__(self, base, linthresh):
     Transform.__init__(self)
     self.base = base
     self.linthresh = abs(linthresh)
     self._log_base = np.log(base)
     logb_linthresh = np.log(linthresh) / self._log_base
     self._linadjust = 1.0 - logb_linthresh
     self._linscale = 1.0 / linthresh
Example #12
0
 def __init__(self, base, linthresh):
     Transform.__init__(self)
     self.base = base
     self.linthresh = abs(linthresh)
     self._log_base = np.log(base)
     self._logb_linthresh = np.log(linthresh) / self._log_base
     self._logb_minlog = np.floor(self._logb_linthresh - 1e-10)
     self._linadjust = np.abs((np.log(linthresh) - self._logb_minlog) /
                              linthresh)
Example #13
0
 def __init__(self, base, linthresh):
     Transform.__init__(self)
     self.base = base
     self.linthresh = abs(linthresh)
     self._log_base = np.log(base)
     self._logb_linthresh = np.log(linthresh) / self._log_base
     self._logb_minlog = np.floor(self._logb_linthresh - 1e-10)
     self._linadjust = np.abs((np.log(linthresh) - self._logb_minlog) /
                              linthresh)
Example #14
0
    def glutMouseMoveEvent(self, x, y):
        if hasattr(self, 'ctrlDown') and self.ctrlDown:
            self.translationMatrix *= Transform.translate(
                (self.xorigpos - x) * -0.01, (self.yorigpos - y) * 0.01, 0)
        else:
            self.rotationMatrix *= Transform.yrotate(
                (self.xorigpos - x) * -0.01)
            self.rotationMatrix *= Transform.xrotate(
                (self.yorigpos - y) * -0.01)

        self.xorigpos, self.yorigpos = x, y
Example #15
0
    def __init__(self, *args, **kwargs):
        """Create a Vega Line Chart"""

        super(Line, self).__init__(*args, **kwargs)

        #Line Updates
        self.scales['x'].type = 'linear'
        self.scales['y'].type = 'linear'
        if self._is_datetime:
            self.scales['x'].type = 'time'

        self.scales['color'] = Scale(name='color', type='ordinal',
                                     domain=DataRef(data='table', field='data.col'),
                                     range='category20')

        del self.marks[0]
        transform = MarkRef(data='table',
                            transform=[Transform(type='facet', keys=['data.col'])])
        enter_props = PropertySet(x=ValueRef(scale='x', field="data.idx"),
                                  y=ValueRef(scale='y', field="data.val"),
                                  stroke=ValueRef(scale="color", field='data.col'),
                                  stroke_width=ValueRef(value=2))
        new_mark = Mark(type='group', from_=transform,
                        marks=[Mark(type='line',
                                    properties=MarkProperties(enter=enter_props))])
        self.marks.append(new_mark)
Example #16
0
    def __init__(self, *args, **kwargs):
        """Create a Vega Stacked Area Chart"""

        super(StackedArea, self).__init__(*args, **kwargs)

        facets = Transform(type='facet', keys=['data.idx'])
        stats = Transform(type='stats', value='data.val')
        stat_dat = Data(name='stats', source='table', transform=[facets, stats])
        self.data['stats'] = stat_dat

        self.scales['x'].zero = False
        self.scales['y'].domain = DataRef(field='sum', data='stats')

        stackit = Transform(type='stack', point='data.idx', height='data.val')
        self.marks[0].from_.transform.append(stackit)
        self.marks[0].marks[0].properties.enter.y.scale = 'y'
        self.marks[0].marks[0].properties.enter.y.field = 'y'
        del self.marks[0].marks[0].properties.enter.y2.value
        self.marks[0].marks[0].properties.enter.y2.field = 'y2'
Example #17
0
    def __getitem__(self, item):
        # type: (int) -> Tuple(Tensor, Tensor)

        image = Image.open(self.images_list[item]).convert('RGB')
        mask = np.load(self.masks_list[item])
        mask = Image.fromarray(mask)

        #Apply data augmentation in TRAIN mode
        augment = self.mode == DSMode.TRAIN
        image, mask = Transform(flip_prob=0.5,
                                degrees=10,
                                minscale=0.6,
                                augment=augment)(image, mask)

        return image, mask
Example #18
0
    def reshape(self, width, height):
        """
        GLUT reshape function with the addition of defining the projection matrix

        Parameters
        ----------
        width : int
        height : int

        Note
        ----
        You may need to call this class if is not automatically called by the GLUT function:
        If it is not called, the projection frustum is not created.
        """
        gl.glViewport(0, 0, width, height)

        self.projection_mat = Transform.perspective(Global.FOVY,
                                                    width / height,
                                                    Global.ZNEAR, Global.ZFAR)
Example #19
0
def transform_file(filename, output="out.f90",
                   dim=1, interleave=False, compress=True, row_major=False):
    """Apply tfortran source code transformations.

    :param filename: input file name
    :param dim:      dimension
    :param output:   output file name
    """

    template = None
    with open(filename, 'r') as f:
        template = f.read()

    transform = Transform()
    transform.dim = dim
    transform.compress = compress
    transform.interleave = interleave
    transform.row_major = row_major

    transformed = transform.transform(template)

    with open(output, 'w') as f:
        f.write(transformed)
Example #20
0
 def __init__(self, base):
     Transform.__init__(self)
     self.base = base
Example #21
0
    def __init__(self, net, cfg):

        self.cfg = cfg

        self.net = net
        self.anchors = generate_anchors(cfg)

        if torch.cuda.is_available():
            self.net.cuda()
            self.anchors = self.anchors.cuda()

        # Dataset transform
        transform = [
            Transform(context_amount=cfg.TRAIN.CROP_CONTEXT_AMOUNT_Z, size=cfg.MODEL.Z_SIZE),
            Transform(context_amount=cfg.TRAIN.CROP_CONTEXT_AMOUNT_X, size=cfg.MODEL.X_SIZE,
                      random_translate=True, random_resize=True, motion_blur=True,
                      random_translate_range=cfg.TRAIN.DATA_AUG_TRANSLATE_RANGE,
                      random_resize_scale_min=cfg.TRAIN.DATA_AUG_RESIZE_SCALE_MIN,
                      random_resize_scale_max=cfg.TRAIN.DATA_AUG_RESIZE_SCALE_MAX
                      )
        ]

        # Training dataset
        trackingnet = TrackingNet(cfg.PATH.TRACKINGNET, subset="train", debug_seq=cfg.TRAIN.DEBUG_SEQ)
        imagenet = ImageNetVID(cfg.PATH.ILSVRC, subset="train")
        sampler = PairSampler([trackingnet, imagenet], cfg=cfg, transform=transform, pairs_per_video=cfg.TRAIN.PAIRS_PER_VIDEO,
                              frame_range=cfg.TRAIN.FRAME_RANGE)
        # Distractor dataset
        coco = CocoDetection(cfg.PATH.COCO, cfg.PATH.COCO_ANN_FILE)
        # coco_distractor = COCODistractor(coco, 4000)
        coco_positive = COCOPositivePair(coco, 4000, cfg=cfg, transform=transform)
        coco_negative = COCONegativePair(coco, 12000, cfg=cfg, transform=transform)

        dataset = ConcatDataset([sampler, coco_positive, coco_negative])
        self.dataloader = DataLoader(dataset, batch_size=cfg.TRAIN.BATCH_SIZE, num_workers=4, shuffle=True,
                                     pin_memory=True, drop_last=True)

        # Validation dataset
        val_trackingnet = TrackingNet(cfg.PATH.TRACKINGNET, subset="val")
        val_imagenet = ImageNetVID(cfg.PATH.ILSVRC, subset="val")
        validation_sampler = PairSampler([val_trackingnet, val_imagenet], cfg=cfg, transform=transform,
                                         pairs_per_video=1, frame_range=cfg.TRAIN.FRAME_RANGE)
        val_coco_positive = COCOPositivePair(coco, 100, cfg=cfg, transform=transform)
        val_dataset = ConcatDataset([validation_sampler, val_coco_positive])

        if cfg.TRAIN.DEBUG_SEQ >= 0:  # When debugging on a single sequence, the validation is performed on the same one
            val_dataset = PairSampler([trackingnet], cfg=cfg, transform=transform, pairs_per_video=200)

        self.validation_dataloader = DataLoader(val_dataset, batch_size=min(cfg.TRAIN.BATCH_SIZE, 20), num_workers=4,
                                                shuffle=True, pin_memory=True, drop_last=False)

        # Loss
        self.criterion = MultiBoxLoss(self.anchors, cfg)

        self.optimizer = optim.Adam(self.net.parameters(), lr=cfg.TRAIN.LR, weight_decay=cfg.TRAIN.WEIGHT_DECAY)
        self.scheduler = optim.lr_scheduler.StepLR(self.optimizer, step_size=cfg.TRAIN.SCHEDULER_STEP_SIZE,
                                                   gamma=cfg.TRAIN.SCHEDULER_GAMMA)

        # Summary Writer
        self.run_id = datetime.now().strftime('%b%d_%H-%M-%S')
        if not cfg.DEBUG:
            self.save_config()
            self.save_code()
            self.writer = SummaryWriter(log_dir=os.path.join(cfg.PATH.DATA_DIR, "runs", self.run_id))

        self.start_epoch = 0

        if cfg.TRAIN.RESUME_CHECKPOINT:
            self.start_epoch = utils.load_checkpoint(cfg.TRAIN.RESUME_CHECKPOINT, self.net, self.optimizer)

        if torch.cuda.is_available():
            self.net = nn.DataParallel(self.net)

        self.best_IOU = 0.
Example #22
0
 def __init__(self, base):
     Transform.__init__(self)
     self.base = base