(self, image, swapped_image, bbox_model_name, bbox_threshold, bbox_dilation, bbox_crop_factor, bbox_drop_size, sam_model_name, sam_dilation, sam_threshold, bbox_expansion, mask_hint_threshold, mask_hint_use_negative, morphology_operation, morphology_distance, blur_radius, sigma_factor, mask_optional=None)
| 733 | CATEGORY = "🌌 ReActor" |
| 734 | |
| 735 | def execute(self, image, swapped_image, bbox_model_name, bbox_threshold, bbox_dilation, bbox_crop_factor, bbox_drop_size, sam_model_name, sam_dilation, sam_threshold, bbox_expansion, mask_hint_threshold, mask_hint_use_negative, morphology_operation, morphology_distance, blur_radius, sigma_factor, mask_optional=None): |
| 736 | |
| 737 | # images = [image[i:i + 1, ...] for i in range(image.shape[0])] |
| 738 | |
| 739 | images = image |
| 740 | |
| 741 | if mask_optional is None: |
| 742 | |
| 743 | bbox_model_path = folder_paths.get_full_path("ultralytics", bbox_model_name) |
| 744 | bbox_model = subcore.load_yolo(bbox_model_path) |
| 745 | bbox_detector = subcore.UltraBBoxDetector(bbox_model) |
| 746 | |
| 747 | segs = bbox_detector.detect(images, bbox_threshold, bbox_dilation, bbox_crop_factor, bbox_drop_size, self.detailer_hook) |
| 748 | |
| 749 | if isinstance(self.labels, list): |
| 750 | self.labels = str(self.labels[0]) |
| 751 | |
| 752 | if self.labels is not None and self.labels != '': |
| 753 | self.labels = self.labels.split(',') |
| 754 | if len(self.labels) > 0: |
| 755 | segs, _ = masking_segs.filter(segs, self.labels) |
| 756 | # segs, _ = masking_segs.filter(segs, "all") |
| 757 | |
| 758 | sam_modelname = folder_paths.get_full_path("sams", sam_model_name) |
| 759 | |
| 760 | if 'vit_h' in sam_model_name: |
| 761 | model_kind = 'vit_h' |
| 762 | elif 'vit_l' in sam_model_name: |
| 763 | model_kind = 'vit_l' |
| 764 | else: |
| 765 | model_kind = 'vit_b' |
| 766 | |
| 767 | sam = sam_model_registry[model_kind](checkpoint=sam_modelname) |
| 768 | size = os.path.getsize(sam_modelname) |
| 769 | sam.safe_to = core.SafeToGPU(size) |
| 770 | |
| 771 | device = model_management.get_torch_device() |
| 772 | |
| 773 | sam.safe_to.to_device(sam, device) |
| 774 | |
| 775 | sam.is_auto_mode = self.device_mode == "AUTO" |
| 776 | |
| 777 | combined_mask, _ = core.make_sam_mask_segmented(sam, segs, images, self.detection_hint, sam_dilation, sam_threshold, bbox_expansion, mask_hint_threshold, mask_hint_use_negative) |
| 778 | |
| 779 | else: |
| 780 | combined_mask = mask_optional |
| 781 | |
| 782 | # *** MASK TO IMAGE ***: |
| 783 | |
| 784 | mask_image = combined_mask.reshape((-1, 1, combined_mask.shape[-2], combined_mask.shape[-1])).movedim(1, -1).expand(-1, -1, -1, 3) |
| 785 | |
| 786 | # *** MASK MORPH ***: |
| 787 | |
| 788 | mask_image = core.tensor2mask(mask_image) |
| 789 | |
| 790 | if morphology_operation == "dilate": |
| 791 | mask_image = self.dilate(mask_image, morphology_distance) |
| 792 | elif morphology_operation == "erode": |
nothing calls this directly
no test coverage detected