def _wrap_get_gd_image_multi_objs(mask_):
     # [h, w, 1]
     guide_image = array_kits.get_gd_image_multi_objs(
         mask_,
         obj_value=2,
         partial=False,
         with_fake_guides=False)[..., None]
     return guide_image.astype(np.float32)
Example #2
0
    def after_run(self, run_context, run_values):
        predictions = run_values.results

        try:
            self.features_val, self.labels_val = run_context.session.run(
                [self.features, self.labels])
        except errors_impl.OutOfRangeError:
            self._save_guide()
            self.guides.clear()
            return run_context.request_stop()
        else:
            new_case = self.features_val["names"][0].decode("utf-8")
            if self.cur_case != new_case:
                # Finish a case
                self._save_guide()
                self.guides.clear()
                # Update states with next case
                self.cur_case = new_case
                self.bbox = self.features_val["bboxes"][0]
                # Reinitialize TumorManager
                need_rev = self.cur_case.endswith("rev")
                self.id = self.id - 1 if need_rev else 0
                self.t_mgr.reset(direction=-1 if need_rev else 1)
                self.t_mgr.name = self.cur_case
                self.t_mgr.set_bbox(
                    self.bbox, shape=self.features_val["images"].shape[1:-1])
                self.features_val["sp_guide"] = self.t_mgr.get_guide_image(
                    self.features_val["sp_guide"][0], new_id=self.id)
                if self.t_mgr.direction == 1:
                    self.id += 1
                else:
                    self.id -= 1
            else:
                # Update guide with last prediction
                self.t_mgr.check_pred(predictions["TumorPred"][0, ..., 0])
                if self.cbn:
                    # self.features_val["sp_guide"][0, ..., 0] = np.maximum(
                    #     self.features_val["sp_guide"][0, ..., 0],
                    #     get_gd_image_multi_objs(corrective_tumor,
                    #                             center_perturb=0., stddev_perturb=0.))
                    self.features_val["sp_guide"] = self.t_mgr.get_guide_image(
                        self.features_val["sp_guide"][0], self.id)
                    if self.t_mgr.direction == 1:
                        self.id += 1
                    else:
                        self.id -= 1
                else:
                    self.features_val["images"][0, ..., -1] = np.maximum(
                        self.features_val["images"][0, ..., -1],
                        get_gd_image_multi_objs(self.t_mgr.pred,
                                                center_perturb=0.,
                                                stddev_perturb=0.))
            if self.cbn:
                self.guides.append(self.features_val["sp_guide"][0, ..., 0])
            else:
                self.guides.append(self.features_val["images"][0, ..., -1])
Example #3
0
 def _wrap_get_gd_image_multi_objs(mask):
     guide_image = array_kits.get_gd_image_multi_objs(
         mask,
         obj_value=2,
         center_perturb=0.,
         stddev_perturb=0.,
         partial=args.use_fewer_guide,
         with_fake_guides=False,
         partial_slice=args.guide)[..., None]
     return guide_image.astype(np.float32)
Example #4
0
 def _wrap_get_gd_image_multi_objs(mask_):
     guide_image = array_kits.get_gd_image_multi_objs(
         mask_,
         obj_value=2,
         center_perturb=args.center_perturb,
         stddev_perturb=args.stddev_perturb,
         partial=False,
         with_fake_guides=args.use_fake_guide,
         fake_rate=args.fake_rate,
         fake_range_value=1)[..., None]
     return guide_image.astype(np.float32)
Example #5
0
 def test_get_gd_image_multi_objs(self):
     for i in range(44, self.label.shape[0]):
         guide = array_kits.get_gd_image_multi_objs(self.label[i],
                                                    2,
                                                    with_fake_guides=True)
         plt.subplot(131)
         plt.imshow(self.image[i], cmap="gray")
         plt.subplot(132)
         plt.imshow(self.label[i], cmap="gray")
         plt.subplot(133)
         plt.imshow(guide, cmap="gray")
         plt.show()
    def get_guide_image(self, guide, new_id):
        self.set_guide_info(guide, new_id)

        if len(self.centers_yx) > 0:
            self.guides = arr_ops.create_gaussian_distribution(
                self.shape, self.centers_yx[0, ::-1], self.stddevs_yx[0, ::-1])
            for i in range(1, len(self.centers_yx)):
                self.guides = np.maximum(
                    self.guides,
                    arr_ops.create_gaussian_distribution(
                        self.shape, self.centers_yx[i, ::-1],
                        self.stddevs_yx[i, ::-1]))
        else:
            self.guides = np.zeros(self.shape, dtype=np.float32)

        if self.pred is None:
            return self.guides[None, ..., None]
        else:
            self.guides = np.maximum(
                self.guides,
                arr_ops.get_gd_image_multi_objs(self.pred,
                                                center_perturb=0.,
                                                stddev_perturb=0.))
            return self.guides[None, ..., None]