def _genDef(self, train_imgs, train_masks, attnlist, class_weight):
        """
		图片取块生成器模板
		:param train_imgs: 原始图
		:param train_masks:  原始图groundtruth
		:param attnlist:  目标区域list
		:return:  取出的训练样本
		"""
        while 1:
            Nimgs = train_imgs.shape[0]
            for t in range(
                    int(self.config.subsample * self.config.total_train /
                        self.config.batch_size)):
                if self.multi_proportion:
                    X = np.zeros([
                        self.config.batch_size, self.config.patch_height,
                        self.config.patch_width, 1
                    ])
                    Y = np.zeros([
                        self.config.batch_size,
                        self.config.patch_height * self.config.patch_width,
                        self.config.seg_num + 1
                    ])
                else:
                    X = np.zeros([
                        self.config.batch_size, self.config.patch_height,
                        self.config.patch_width, 3
                    ])
                    Y = np.zeros([
                        self.config.batch_size,
                        self.config.patch_height * self.config.patch_width,
                        self.config.seg_num + 1
                    ])
                for j in range(self.config.batch_size):
                    [i_center, x_center,
                     y_center] = self._CenterSampler(attnlist, class_weight,
                                                     Nimgs)
                    patch = train_imgs[
                        i_center,
                        int(y_center - self.config.patch_height /
                            2):int(y_center + self.config.patch_height / 2),
                        int(x_center - self.config.patch_width /
                            2):int(x_center + self.config.patch_width / 2), :]
                    patch_mask = train_masks[
                        i_center, :,
                        int(y_center - self.config.patch_height /
                            2):int(y_center + self.config.patch_height / 2),
                        int(x_center - self.config.patch_width /
                            2):int(x_center + self.config.patch_width / 2)]
                    X[j, :, :, :] = patch
                    Y[j, :, :] = genMasks(
                        np.reshape(patch_mask, [
                            1, self.config.seg_num, self.config.patch_height,
                            self.config.patch_width
                        ]), self.config.seg_num)
                yield (X, Y)
 def _genDef(self, train_imgs, train_masks, attnlist, class_weight):
     """
     Image block generator template
     :param train_imgs: The original image
     :param train_masks:  Original map groundtruth
     :param attnlist:  Target area list
     :return:  Take out training samples
     """
     while 1:
         Nimgs = train_imgs.shape[0]
         for t in range(
                 int(self.config.subsample * self.config.total_train /
                     self.config.batch_size)):
             X = np.zeros([
                 self.config.batch_size, self.config.patch_height,
                 self.config.patch_width, 1
             ])
             Y = np.zeros([
                 self.config.batch_size,
                 self.config.patch_height * self.config.patch_width,
                 self.config.seg_num + 1
             ])
             for j in range(self.config.batch_size):
                 [i_center, x_center,
                  y_center] = self._CenterSampler(attnlist, class_weight,
                                                  Nimgs)
                 patch = train_imgs[
                     i_center,
                     int(y_center - self.config.patch_height /
                         2):int(y_center + self.config.patch_height / 2),
                     int(x_center - self.config.patch_width /
                         2):int(x_center + self.config.patch_width / 2), :]
                 patch_mask = train_masks[
                     i_center, :,
                     int(y_center - self.config.patch_height /
                         2):int(y_center + self.config.patch_height / 2),
                     int(x_center - self.config.patch_width /
                         2):int(x_center + self.config.patch_width / 2)]
                 X[j, :, :, :] = patch
                 Y[j, :, :] = genMasks(
                     np.reshape(patch_mask, [
                         1, self.config.seg_num, self.config.patch_height,
                         self.config.patch_width
                     ]), self.config.seg_num)
             yield (X, Y)
Example #3
0
 def _genDef(self, train_imgs, train_masks, attnlist, class_weight):
     while 1:
         Nimgs = train_imgs.shape[0]
         for t in range(
                 int(self.config.subsample * self.config.total_train /
                     self.config.batch_size)):
             X = np.zeros([
                 self.config.batch_size, self.config.patch_height,
                 self.config.patch_width, 1
             ])
             Y = np.zeros([
                 self.config.batch_size,
                 self.config.patch_height * self.config.patch_width,
                 self.config.seg_num + 1
             ])
             for j in range(self.config.batch_size):
                 [i_center, x_center,
                  y_center] = self._CenterSampler(attnlist, class_weight,
                                                  Nimgs)
                 patch = train_imgs[
                     i_center,
                     int(y_center - self.config.patch_height /
                         2):int(y_center + self.config.patch_height / 2),
                     int(x_center - self.config.patch_width /
                         2):int(x_center + self.config.patch_width / 2), :]
                 patch_mask = train_masks[
                     i_center, :,
                     int(y_center - self.config.patch_height /
                         2):int(y_center + self.config.patch_height / 2),
                     int(x_center - self.config.patch_width /
                         2):int(x_center + self.config.patch_width / 2)]
                 X[j, :, :, :] = patch
                 Y[j, :, :] = genMasks(
                     np.reshape(patch_mask, [
                         1, self.config.seg_num, self.config.patch_height,
                         self.config.patch_width
                     ]), self.config.seg_num)
             yield (X, Y)