def prepareDataThread(self, dataQueue, numpyImages, numpyGT): nr_iter = self.params['ModelParams']['numIterations'] batchsize = self.params['ModelParams']['batchsize'] keysIMG = numpyImages.keys() nr_iter_dataAug = nr_iter * batchsize np.random.seed() whichDataList = np.random.randint( len(keysIMG), size=int(nr_iter_dataAug / self.params['ModelParams']['nProc'])) whichDataForMatchingList = np.random.randint( len(keysIMG), size=int(nr_iter_dataAug / self.params['ModelParams']['nProc'])) for whichData, whichDataForMatching in zip(whichDataList, whichDataForMatchingList): filename, ext = splitext(keysIMG[whichData]) currGtKey = filename + '_segmentation' + ext currImgKey = filename + ext # data agugumentation through hist matching across different examples... ImgKeyMatching = keysIMG[whichDataForMatching] defImg = numpyImages[currImgKey] defLab = numpyGT[currGtKey] # print "is image binary:" # print ((defLab.astype(int)==0) | (defLab.astype(int)==1)).all() defImg = utilities.hist_match(defImg, numpyImages[ImgKeyMatching]) if (np.random.rand(1)[0] > 0.5): #do not apply deformations always, just sometimes defImg, defLab = utilities.produceRandomlyDeformedImage( defImg, defLab, self.params['ModelParams']['numcontrolpoints'], self.params['ModelParams']['sigma']) weightData = np.zeros_like(defLab, dtype=float) weightData[defLab == 1] = np.prod(defLab.shape) / np.sum( (defLab == 1).astype(dtype=np.float32)) weightData[defLab == 0] = np.prod(defLab.shape) / np.sum( (defLab == 0).astype(dtype=np.float32)) dataQueue.put(tuple((defImg, defLab, weightData)))
def prepareDataThread(self, dataQueue, numpyImages, numpyGT): nr_iter = self.params['ModelParams']['numIterations'] batchsize = self.params['ModelParams']['batchsize'] keysIMG = numpyImages.keys() nr_iter_dataAug = nr_iter*batchsize np.random.seed() whichDataList = np.random.randint(1,int(self.params['ModelParams']['TrainSize'])+1, size=int(nr_iter_dataAug/self.params['ModelParams']['nProc'])) whichDataForMatchingList = np.random.randint(1,int(self.params['ModelParams']['TrainSize'])+1, size=int(nr_iter_dataAug/self.params['ModelParams']['nProc'])) for p,whichDataForMatching in zip(whichDataList,whichDataForMatchingList): currGtKey = str(p) + '_segmentation' + '.nii' currImgKey1 = str(p) +'_'+ self.params['ModelParams']['mod1'] + self.params['ModelParams']['format'] currImgKey2 = str(p) +'_'+ self.params['ModelParams']['mod2'] + self.params['ModelParams']['format'] currImgKey3 = str(p) +'_'+ self.params['ModelParams']['mod3'] + self.params['ModelParams']['format'] currImgKey4 = str(p) +'_'+ self.params['ModelParams']['mod4'] + self.params['ModelParams']['format'] defImg1= numpyImages[currImgKey1] defImg2= numpyImages[currImgKey2] defImg3= numpyImages[currImgKey3] defImg4= numpyImages[currImgKey4] defLab = numpyGT[currGtKey] ImgKeyMatching = keysIMG[whichDataForMatching] defImg1 = utilities.hist_match(defImg1, numpyImages[ImgKeyMatching]) defImg2 = utilities.hist_match(defImg2, numpyImages[ImgKeyMatching]) defImg3 = utilities.hist_match(defImg3, numpyImages[ImgKeyMatching]) defImg4 = utilities.hist_match(defImg4, numpyImages[ImgKeyMatching]) if(np.random.rand(1)[0]>0.5): defImg1,defImg2,defImg3,defImg4,defLab = utilities.produceRandomlyDeformedImage(defImg1,defImg2,defImg3,defImg4,defLab,self.params['ModelParams']['numcontrolpoints'],self.params['ModelParams']['sigma']) weightData = np.zeros_like(defLab,dtype=float) weightData[defLab == 1] = np.prod(defLab.shape) / np.sum((defLab==1).astype(dtype=np.float32)) weightData[defLab == 0] = np.prod(defLab.shape) / np.sum((defLab == 0).astype(dtype=np.float32)) dataQueue.put(tuple((defImg1,defImg2,defImg3,defImg4,defLab,weightData)))
def prepareDataThread(self, dataQueue, numpyImages, numpyGT): nr_iter = self.params['ModelParams']['numIterations'] batchsize = self.params['ModelParams']['batchsize'] keysIMG = numpyImages.keys() keysGT = numpyGT.keys() nr_iter_dataAug = nr_iter*batchsize np.random.seed() whichDataList = np.random.randint(len(keysIMG), size=int(nr_iter_dataAug/self.params['ModelParams']['nProc'])) whichDataForMatchingList = np.random.randint(len(keysIMG), size=int(nr_iter_dataAug/self.params['ModelParams']['nProc'])) for whichData,whichDataForMatching in zip(whichDataList,whichDataForMatchingList): filename, ext = splitext(keysIMG[whichData]) gtname, ext = splitext(keysGT[whichData]) currGtKey = gtname + ext currImgKey = filename + ext # data agugumentation through hist matching across different examples... ImgKeyMatching = keysIMG[whichDataForMatching] defImg = numpyImages[currImgKey] defLab = numpyGT[currGtKey] defImg = utilities.hist_match(defImg, numpyImages[ImgKeyMatching]) if(np.random.rand(1)[0]>0.5): #do not apply deformations always, just sometimes defImg, defLab = utilities.produceRandomlyDeformedImage(defImg, defLab, self.params['ModelParams']['numcontrolpoints'], self.params['ModelParams']['sigma']) weightData = np.zeros_like(defLab,dtype=float) for label in np.unique(defLab): weightData[defLab == label] = np.prod(defLab.shape) / np.sum((defLab==label).astype(dtype=np.float32)) dataQueue.put(tuple((defImg,defLab, weightData)))
def prepareDataThread(self, dataQueue, numpyImages, numpyGT, numpyDmap=None, numpyPmap=None): nr_iter = self.params['ModelParams']['numIterations'] batchsize = self.params['ModelParams']['batchsize'] keys = numpyImages.keys() nr_iter_dataAug = nr_iter * batchsize np.random.seed() whichDataList = np.random.randint( len(keys), size=int(nr_iter_dataAug / self.params['ModelParams']['nProc'])) whichDataForMatchingList = np.random.randint( len(keys), size=int(nr_iter_dataAug / self.params['ModelParams']['nProc'])) for whichData, whichDataForMatching in zip(whichDataList, whichDataForMatchingList): filename, ext = splitext(keys[whichData]) currKey = keys[whichData] #currImgKey = filename + ext #currGtKey = filename + '_segmented' + ext # data augmentation through hist matching across different examples... ImgKeyMatching = keys[whichDataForMatching] defImg = numpyImages[currKey] defLab = numpyGT[currKey] if self.params['DataManagerParams']['dmap']: defDmap = numpyDmap[currKey] else: defDmap = None if self.params['DataManagerParams']['ProbabilityMap']: defPmap = numpyPmap[currKey] else: defPmap = None if self.params['ModelParams']['histmatching']: defImg = utilities.hist_match(defImg, numpyImages[ImgKeyMatching]) if (np.random.rand(1)[0] < self.params['ModelParams']['RandomDeform'] ): #do not apply deformations always, just sometimes defImg, defLab, defDmap = utilities.produceRandomlyDeformedImage( defImg, defLab, defDmap, self.params['ModelParams']['numcontrolpoints'], self.params['ModelParams']['sigma'], self.params['DataManagerParams']['dmap']) weightData = np.zeros_like(defLab, dtype=float) weightData[defLab == 1] = np.prod(defLab.shape) / np.sum( (defLab == 1).astype(dtype=np.float32)) weightData[defLab == 0] = np.prod(defLab.shape) / np.sum( (defLab == 0).astype(dtype=np.float32)) dataQueue.put(tuple((defImg, defLab, defDmap, defPmap, currKey)))