23 from torchvision.ops import masks_to_boxes 24 import torchvision.transforms.functional as TF 25 import torch.nn.functional as F 26 from PIL import Image, ImageFilter, ImageOps 27 import subprocess 28 import math 29 30 # Check for CUDA availability
628 629 MB, _, _ = mask.shape 630 631 if MB < B: 632 assert(B % MB == 0) 633 mask = mask.repeat(B // MB, 1, 1) 634 635 # Masks to boxes
780 MB = mask.shape[0] 781 PB = image_to_paste.shape[0] 782 if mask_mapping_optional is None: 783 if B < PB: 784 assert(PB % B == 0) 785 image_base = image_base.repeat(PB // B, 1, 1, 1) 786 B, H, W, C = image_base.shape 787 if MB < B:
784 assert(PB % B == 0) 785 image_base = image_base.repeat(PB // B, 1, 1, 1) 786 B, H, W, C = image_base.shape 787 if MB < B: 788 assert(B % MB == 0) 789 mask = mask.repeat(B // MB, 1, 1) 790 elif B < MB: 791 assert(MB % B == 0)
787 if MB < B: 788 assert(B % MB == 0) 789 mask = mask.repeat(B // MB, 1, 1) 790 elif B < MB: 791 assert(MB % B == 0) 792 image_base = image_base.repeat(MB // B, 1, 1, 1) 793 if PB < B: 794 assert(B % PB == 0)
790 elif B < MB: 791 assert(MB % B == 0) 792 image_base = image_base.repeat(MB // B, 1, 1, 1) 793 if PB < B: 794 assert(B % PB == 0) 795 image_to_paste = image_to_paste.repeat(B // PB, 1, 1, 1) 796 mask = F.interpolate(mask.unsqueeze(1), size=(H, W), mode='nearest')[:,0,:,:] 797 MB, MH, MW = mask.shape
928 929 # Freeze PIP modules 930 def packages(versions=False): 931 import sys 932 import subprocess 933 return [( r.decode().split('==')[0] if not versions else r.decode() ) for r in subprocess.check_output([sys.executable, '-s', '-m', 'pip', 'freeze']).split()] 934 935 # PIL to Mask
929 # Freeze PIP modules 930 def packages(versions=False): 931 import sys 932 import subprocess 933 return [( r.decode().split('==')[0] if not versions else r.decode() ) for r in subprocess.check_output([sys.executable, '-s', '-m', 'pip', 'freeze']).split()] 934 935 # PIL to Mask 936 def pil2mask(image):
945 946 # scipy handling 947 if 'scipy' not in packages(): 948 cstr("Installing `scipy` ...").msg.print() 949 subprocess.check_call([sys.executable, '-s', '-m', 'pip', 'install', 'scipy']) 950 try: 951 import scipy 952 except ImportError as e: