Esempio n. 1
0
 def getSubSample(self, idx, normImgPatch):
     imgPatch = self.imgData[:, :, idx[0]:idx[0] + idx[3],
                             idx[1]:idx[1] + idx[4], idx[2]:idx[2] + idx[5]]
     labelData = torch.empty(
         (1, self.imgData.shape[1], idx[3], idx[4], idx[5]),
         requires_grad=False)
     if normImgPatch:
         imgPatch = normalizeImg(imgPatch)
     if (self.labelData.dim() == self.imgData.dim()):
         labelData = self.labelData[:, :, idx[0]:idx[0] + idx[3],
                                    idx[1]:idx[1] + idx[4],
                                    idx[2]:idx[2] + idx[5]]
     return (imgPatch, labelData)
Esempio n. 2
0
    def getRandomSubSamples(self,
                            numberofSamplesPerRun,
                            idxs,
                            normImgPatch=False):

        imgDataNew = torch.empty(
            (numberofSamplesPerRun, self.imgData.shape[1], self.patchSizes[0],
             self.patchSizes[1], self.patchSizes[2]),
            requires_grad=False)
        if (self.labelData.dim() == self.imgData.dim()):
            labelDataNew = torch.empty(
                (numberofSamplesPerRun, self.imgData.shape[1],
                 self.patchSizes[0], self.patchSizes[1], self.patchSizes[2]),
                requires_grad=False)

        randSampleIdxs = np.random.randint(0, len(idxs[0]),
                                           (numberofSamplesPerRun, ))
        usedIdx = []
        for j in range(0, numberofSamplesPerRun):
            idx0 = idxs[0][randSampleIdxs[j]]
            idx2 = idxs[1][randSampleIdxs[j]]
            idx3 = idxs[2][randSampleIdxs[j]]
            idx4 = idxs[3][randSampleIdxs[j]]
            usedIdx.append((idx2, idx3, idx4, self.patchSizes[0],
                            self.patchSizes[1], self.patchSizes[2]))
            imgPatch = self.imgData[idx0, :, idx2:idx2 + self.patchSizes[0],
                                    idx3:idx3 + self.patchSizes[1],
                                    idx4:idx4 + self.patchSizes[2]]
            if normImgPatch:
                imgPatch = normalizeImg(imgPatch)
            imgDataNew[j, ] = imgPatch
            #     indexArrayTest[idx2:idx2 + patchSizes[0], idx3:idx3 + patchSizes[1], idx4:idx4 + patchSizes[2]] += 1
            if (self.labelData.dim() == self.imgData.dim()):
                labelDataNew[j, ] = self.labelData[idx0, :, idx2:idx2 +
                                                   self.patchSizes[0],
                                                   idx3:idx3 +
                                                   self.patchSizes[1],
                                                   idx4:idx4 +
                                                   self.patchSizes[2]]

        imgDataToWork = imgDataNew
        if (self.labelData.dim() == self.imgData.dim()):
            labelDataToWork = labelDataNew
        else:
            labelDataToWork = torch.Tensor()

        return (imgDataToWork, labelDataToWork, usedIdx)
Esempio n. 3
0
    def getUniformlyDistributedSubsamples(self,
                                          numberofSamplesPerRun,
                                          idxs,
                                          currIteration,
                                          normImgPatch=False):

        startIdx = currIteration % numberofSamplesPerRun

        imgDataNew = torch.empty(
            (numberofSamplesPerRun, self.imgData.shape[1], self.patchSizes[0],
             self.patchSizes[1], self.patchSizes[2]),
            requires_grad=False)
        if (self.labelData.dim() == self.imgData.dim()):
            labelDataNew = torch.empty(
                (numberofSamplesPerRun, self.imgData.shape[1],
                 self.patchSizes[0], self.patchSizes[1], self.patchSizes[2]),
                requires_grad=False)

        iterationRange = np.arange(startIdx, startIdx + numberofSamplesPerRun)
        iterationRange[iterationRange >= len(
            idxs)] = iterationRange[iterationRange >= len(idxs)] - len(idxs)
        j = 0
        for i in iterationRange:
            idx = idxs[i]
            imgPatch = self.imgData[:, :, idx[0]:idx[0] + idx[3],
                                    idx[1]:idx[1] + idx[4],
                                    idx[2]:idx[2] + idx[5]]
            if normImgPatch:
                imgPatch = normalizeImg(imgPatch)
            imgDataNew[j, ] = imgPatch
            if (self.labelData.dim() == self.imgData.dim()):
                labelDataNew[j, ] = self.labelData[:, :,
                                                   idx[0]:idx[0] + idx[3],
                                                   idx[1]:idx[1] + idx[4],
                                                   idx[2]:idx[2] + idx[5]]
            j = j + 1

        imgDataToWork = imgDataNew
        if (self.labelData.dim() == self.imgData.dim()):
            labelDataToWork = labelDataNew
        else:
            labelDataToWork = torch.Tensor()

        return (imgDataToWork, labelDataToWork)
Esempio n. 4
0
 def getSubSampleImg(self, idx, normImgPatch):
     imgPatch = self.imgData[:, :, idx[0]:idx[0] + idx[3],
                             idx[1]:idx[1] + idx[4], idx[2]:idx[2] + idx[5]]
     if normImgPatch:
         imgPatch = normalizeImg(imgPatch)
     return imgPatch