5 from torchvision import transforms 6 from torchvision.ops import masks_to_boxes 7 import torchvision.transforms.functional as TF 8 import torch.nn.functional as torchfn 9 import subprocess 10 import sys 11 12 DELIMITER = '|'
15 16 package_list = None 17 def update_package_list(): 18 import sys 19 import subprocess 20 21 global package_list 22 package_list = [r.decode().split('==')[0] for r in subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']).split()]
18 import sys 19 import subprocess 20 21 global package_list 22 package_list = [r.decode().split('==')[0] for r in subprocess.check_output([sys.executable, '-m', 'pip', 'freeze']).split()] 23 24 def ensure_package(package_name, import_path=None): 25 global package_list
29 update_package_list() 30 31 if package_name not in package_list: 32 print("(First Run) Installing missing package %s" % package_name) 33 subprocess.check_call([sys.executable, '-m', 'pip', '-q', 'install', import_path]) 34 update_package_list() 35 36 def tensor2mask(t: torch.Tensor) -> torch.Tensor:
205 if not os.path.exists(file_name): 206 print(f'Downloading and caching file: {cache_name}') 207 with open(file_name, 'wb') as file: 208 import requests 209 r = requests.get(url, stream=True) 210 r.raise_for_status() 211 for block in r.iter_content(4096): 212 file.write(block)
723 mask = torch.nn.functional.interpolate(mask.unsqueeze(1), size=(H, W), mode='nearest')[:,0,:,:] 724 MB, _, _ = mask.shape 725 726 if MB < B: 727 assert(B % MB == 0) 728 mask = mask.repeat(B // MB, 1, 1) 729 730 # masks_to_boxes errors if the tensor is all zeros, so we'll add a single pixel and zero it out at the end
864 MB = mask.shape[0] 865 PB = image_to_paste.shape[0] 866 if mask_mapping_optional is None: 867 if B < PB: 868 assert(PB % B == 0) 869 image_base = image_base.repeat(PB // B, 1, 1, 1) 870 B, H, W, C = image_base.shape 871 if MB < B:
868 assert(PB % B == 0) 869 image_base = image_base.repeat(PB // B, 1, 1, 1) 870 B, H, W, C = image_base.shape 871 if MB < B: 872 assert(B % MB == 0) 873 mask = mask.repeat(B // MB, 1, 1) 874 elif B < MB: 875 assert(MB % B == 0)
871 if MB < B: 872 assert(B % MB == 0) 873 mask = mask.repeat(B // MB, 1, 1) 874 elif B < MB: 875 assert(MB % B == 0) 876 image_base = image_base.repeat(MB // B, 1, 1, 1) 877 if PB < B: 878 assert(B % PB == 0)
874 elif B < MB: 875 assert(MB % B == 0) 876 image_base = image_base.repeat(MB // B, 1, 1, 1) 877 if PB < B: 878 assert(B % PB == 0) 879 image_to_paste = image_to_paste.repeat(B // PB, 1, 1, 1) 880 mask = torch.nn.functional.interpolate(mask.unsqueeze(1), size=(H, W), mode='nearest')[:,0,:,:] 881 MB, MH, MW = mask.shape
1294 return (hsv,) 1295 elif out_space == "RGB": 1296 return (hsv2rgb(hsv),) 1297 else: 1298 assert out_space == "HSL" 1299 return (hsv2hsl(hsv),) 1300 1301 class MaqueradeIncrementerNode: