Esempio n. 1
0
    def setSource(self, Is_org):

        with torch.no_grad():
            IsList = []
            for i in range(len(self.scaleList)):
                IsList.append(
                    self.ResizeMinSize(Is_org,
                                       int(self.minSize * self.scaleList[i])))

            self.Is = IsList[len(self.scaleList) // 2]
            if self.use_cuda:
                self.IsTensor = self.toTensor(self.Is).unsqueeze(0).cuda()
            else:
                self.IsTensor = self.toTensor(self.Is).unsqueeze(0)

            self.featsMultiScale = []
            self.WMultiScale = []
            self.HMultiScale = []
            for i in range(len(self.scaleList)):
                if self.use_cuda:
                    feat = F.normalize(
                        self.net(self.preproc(IsList[i]).unsqueeze(0).cuda()))
                else:
                    feat = F.normalize(
                        self.net(self.preproc(IsList[i]).unsqueeze(0)))

                Ws, Hs = outil.getWHTensor(feat)
                self.featsMultiScale.append(feat.contiguous().view(1024, -1))
                self.WMultiScale.append(Ws)
                self.HMultiScale.append(Hs)

            self.featsMultiScale = torch.cat(self.featsMultiScale, dim=1)
            self.WMultiScale = torch.cat(self.WMultiScale)
            self.HMultiScale = torch.cat(self.HMultiScale)
Esempio n. 2
0
 def setTarget(self, It_org):
     with torch.no_grad():
         self.It = self.ResizeMaxSize(It_org, self.minSize)
         self.ItTensor = self.toTensor(self.It).unsqueeze(0).cuda()
         self.featt = F.normalize(
             self.net(self.preproc(self.It).unsqueeze(0).cuda()))
         self.Wt, self.Ht = outil.getWHTensor(self.featt)
    def setPair(self, Is_org, It_org):

        with torch.no_grad():
            IsList = []
            for i in range(len(self.scaleList)):
                IsList.append(
                    self.ResizeMinSize(Is_org,
                                       int(self.minSize * self.scaleList[i])))

            self.Is = IsList[len(self.scaleList) // 2]
            self.IsTensor = self.toTensor(self.Is).unsqueeze(0).cuda()

            featsMultiScale = []
            WMultiScale = []
            HMultiScale = []
            for i in range(len(self.scaleList)):
                feat = F.normalize(
                    self.net(self.preproc(IsList[i]).unsqueeze(0).cuda()))
                Ws, Hs = outil.getWHTensor(feat)
                featsMultiScale.append(feat.contiguous().view(1024, -1))
                WMultiScale.append(Ws)
                HMultiScale.append(Hs)
                torch.cuda.empty_cache()

            featsMultiScale = torch.cat(featsMultiScale, dim=1)
            WMultiScale = torch.cat(WMultiScale)
            HMultiScale = torch.cat(HMultiScale)
            torch.cuda.empty_cache()
            self.It = self.ResizeMinSize(It_org, self.minSize)
            self.ItTensor = self.toTensor(self.It).unsqueeze(0).cuda()
            featt = F.normalize(
                self.net(self.preproc(self.It).unsqueeze(0).cuda()))
            Wt, Ht = outil.getWHTensor(featt)
            WtInt, HtInt = outil.getWHTensor_Int(featt)

            self.W2, self.H2 = featt.size()[2], featt.size()[3]
            featt = featt.contiguous().view(1024, -1)

            index1, index2 = outil.mutualMatching(featsMultiScale, featt)
            self.W1MutualMatch = WMultiScale[index1]
            self.H1MutualMatch = HMultiScale[index1]

            self.W2MutualMatch = Wt[index2]
            self.H2MutualMatch = Ht[index2]

            self.W2MutualMatchInt = WtInt[index2]
            self.H2MutualMatchInt = HtInt[index2]