diff --git a/prompter/config/lucchi.py b/prompter/config/lucchi.py new file mode 100644 index 0000000..08a4071 --- /dev/null +++ b/prompter/config/lucchi.py @@ -0,0 +1,66 @@ +prompter = dict( + backbone=dict( + model_name='convnext_small', + pretrained=True, + num_classes=0, + global_pool='' + ), + neck=dict( + in_channels=[96, 192, 384, 768], + out_channels=256, + num_outs=4, + add_extra_convs='on_input', + ), + dropout=0.1, + space=16, + hidden_dim=256 +) + +data = dict( + name='lucchi', + num_classes=1, + batch_size_per_gpu=8, + num_workers=8, + train=dict(transform=[ + dict(type='RandomCrop', height=768, width=1024, p=1), + dict(type='RandomGridShuffle', grid=(4, 4), p=0.5), + dict(type='ColorJitter', brightness=0.25, contrast=0.25, saturation=0.1, hue=0.05, p=0.2), + #dict(type='RandomRotate90', p=0.5), + dict(type='Downscale', scale_max=0.5, scale_min=0.5, p=0.15), + dict(type='Blur', blur_limit=10, p=0.2), + dict(type='GaussNoise', var_limit=50, p=0.25), + dict(type='ZoomBlur', p=0.1, max_factor=1.05), + dict(type='HorizontalFlip', p=0.5), + dict(type='VerticalFlip', p=0.5), + dict(type='ShiftScaleRotate', shift_limit=0.3, scale_limit=0.1, rotate_limit=0, border_mode=0, value=0, p=0.5), + dict(type='PadIfNeeded', min_height=None, min_width=None, pad_height_divisor=prompter["space"], + pad_width_divisor=prompter["space"], position="top_left", p=1), + dict(type='Normalize'), + ]), + val=dict(transform=[ + dict(type='PadIfNeeded', min_height=None, min_width=None, pad_height_divisor=prompter["space"], + pad_width_divisor=prompter["space"], position="top_left", p=1), + dict(type='Normalize'), + ]), + test=dict(transform=[ + dict(type='PadIfNeeded', min_height=None, min_width=None, pad_height_divisor=prompter["space"], + pad_width_divisor=prompter["space"], position="top_left", p=1), + dict(type='Normalize'), + ]), +) + +optimizer = dict( + type='Adam', + lr=1e-4, + weight_decay=1e-4 +) + +criterion = dict( + matcher=dict(type='HungarianMatcher', dis_type='l2', set_cost_point=0.1, set_cost_class=1), + eos_coef=0.25, + reg_loss_coef=5e-3, + cls_loss_coef=1.0, + mask_loss_coef=1.0 +) + +test = dict(nms_thr=12, match_dis=12, filtering=True) diff --git a/prompter/dataset.py b/prompter/dataset.py index bf2d6c8..bbfb6ce 100644 --- a/prompter/dataset.py +++ b/prompter/dataset.py @@ -10,7 +10,9 @@ from albumentations.pytorch import ToTensorV2 from torch.utils.data import Dataset, DataLoader from torch.utils.data.distributed import DistributedSampler - +from PIL import Image +import re +import cv2 as cv def read_from_json(json_path): with open(json_path, 'r', encoding='utf-8') as f: @@ -29,7 +31,6 @@ def __init__( self.data = anno_json self.img_paths = list(anno_json.keys()) self.keys = ['image', 'keypoints'] + [f'keypoints{i}' for i in range(1, cfg.data.num_classes)] + ['mask'] - self.phase = mode self.dataset = cfg.data.name @@ -53,7 +54,23 @@ def __getitem__(self, index: int): img_path = self.img_paths[index] - values = ([io.imread(f'../segmentor/{img_path}')[..., :3]] + + # Define the regex pattern to match the 'mask' part + pattern = re.compile(r'(/mask/)') + # Replace 'mask' with 'raw' in the path + raw_path = re.sub(pattern, r'/raw/', img_path) + + if raw_path[-3:] == 'mat': + raw_path = raw_path[:-3] + 'png' + + np_img = [] + if self.dataset == 'lucchi' or self.dataset == 'Lucchipp': + np_img = io.imread(f'../segmentor/{raw_path}') + np_img = [cv.merge((np_img, np_img, np_img))] + else: + np_img = [io.imread(f'../segmentor/{raw_path}')[..., :3]] + + + values = (np_img + [np.array(point).reshape(-1, 2) for point in self.data[img_path]]) if self.dataset == 'kumar': @@ -64,6 +81,8 @@ def __getitem__(self, index: int): mask = np.load(f'../segmentor/{mask_path}') elif self.dataset == 'cpm17': mask = scipy.io.loadmat(f'../segmentor/{img_path[:-4].replace("Images", "Labels")}.mat')['inst_map'] + elif self.dataset == 'lucchi' or self.dataset == 'Lucchipp': + mask = np.asarray(Image.open(f'../segmentor/{img_path}')) else: mask = np.load(f'../segmentor/{img_path.replace("Images", "Masks")[:-4]}.npy', allow_pickle=True)[()][ 'inst_map'] @@ -73,6 +92,8 @@ def __getitem__(self, index: int): ori_shape = values[0].shape[:2] sample = dict(zip(self.keys, values)) + sample['keypoints'] = [tuple(k) for k in sample['keypoints']] + res = self.transform(**sample) res = list(res.values()) diff --git a/prompter/main.py b/prompter/main.py index ac9ba07..53b3c19 100644 --- a/prompter/main.py +++ b/prompter/main.py @@ -9,8 +9,10 @@ from engine import train_one_epoch, evaluate from torch.utils.data import DataLoader from torch.utils.data.distributed import DistributedSampler +import os +os.environ["WANDB__SERVICE_WAIT"] = "300" def parse_args(): parser = argparse.ArgumentParser('Cell prompter') parser.add_argument('--config', default='pannuke123.py', type=str) @@ -235,7 +237,7 @@ def main(): checkpoint, f"checkpoint/{args.output_dir}/best.pth", ) - except NameError: + except AttributeError: pass if is_main_process() and args.use_wandb: diff --git a/prompter/predict_prompts.py b/prompter/predict_prompts.py index 823d6b8..97563f5 100644 --- a/prompter/predict_prompts.py +++ b/prompter/predict_prompts.py @@ -9,6 +9,8 @@ from main import parse_args from mmengine.config import Config +import re +import cv2 as cv args = parse_args() cfg = Config.fromfile(f'config/{args.config}') @@ -38,7 +40,17 @@ def process_files(files): for file in tqdm(files): - img = io.imread(f'../segmentor/{file}')[..., :3] + pattern = re.compile(r'(/mask/)') + raw_path = re.sub(pattern, r'/raw/', file) + + if raw_path[-3:] == 'mat': + raw_path = raw_path[:-3] + 'png' + + if dataset == 'lucchi' or dataset == 'Lucchipp': + img = io.imread(f'../segmentor/{raw_path}') + img = cv.merge((img, img, img)) + else: + img = io.imread(f'../segmentor/{raw_path}')[..., :3] image = transform(image=img)['image'].unsqueeze(0).to(device) diff --git a/prompter/timm/__pycache__/__init__.cpython-37.pyc b/prompter/timm/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index a5149ad..0000000 Binary files a/prompter/timm/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/__pycache__/__init__.cpython-39.pyc b/prompter/timm/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index ed8c911..0000000 Binary files a/prompter/timm/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/__pycache__/version.cpython-37.pyc b/prompter/timm/__pycache__/version.cpython-37.pyc deleted file mode 100644 index fa86d3e..0000000 Binary files a/prompter/timm/__pycache__/version.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/__pycache__/version.cpython-39.pyc b/prompter/timm/__pycache__/version.cpython-39.pyc deleted file mode 100644 index d1347f2..0000000 Binary files a/prompter/timm/__pycache__/version.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/__init__.cpython-37.pyc b/prompter/timm/data/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index bbc7b93..0000000 Binary files a/prompter/timm/data/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/__init__.cpython-39.pyc b/prompter/timm/data/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index b469270..0000000 Binary files a/prompter/timm/data/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/auto_augment.cpython-37.pyc b/prompter/timm/data/__pycache__/auto_augment.cpython-37.pyc deleted file mode 100644 index f9e9698..0000000 Binary files a/prompter/timm/data/__pycache__/auto_augment.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/auto_augment.cpython-39.pyc b/prompter/timm/data/__pycache__/auto_augment.cpython-39.pyc deleted file mode 100644 index fe9ceeb..0000000 Binary files a/prompter/timm/data/__pycache__/auto_augment.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/config.cpython-37.pyc b/prompter/timm/data/__pycache__/config.cpython-37.pyc deleted file mode 100644 index 701e2bb..0000000 Binary files a/prompter/timm/data/__pycache__/config.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/config.cpython-39.pyc b/prompter/timm/data/__pycache__/config.cpython-39.pyc deleted file mode 100644 index 058bc60..0000000 Binary files a/prompter/timm/data/__pycache__/config.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/constants.cpython-37.pyc b/prompter/timm/data/__pycache__/constants.cpython-37.pyc deleted file mode 100644 index 4fcb5af..0000000 Binary files a/prompter/timm/data/__pycache__/constants.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/constants.cpython-39.pyc b/prompter/timm/data/__pycache__/constants.cpython-39.pyc deleted file mode 100644 index e085e32..0000000 Binary files a/prompter/timm/data/__pycache__/constants.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/dataset.cpython-37.pyc b/prompter/timm/data/__pycache__/dataset.cpython-37.pyc deleted file mode 100644 index ff9510f..0000000 Binary files a/prompter/timm/data/__pycache__/dataset.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/dataset.cpython-39.pyc b/prompter/timm/data/__pycache__/dataset.cpython-39.pyc deleted file mode 100644 index f7c28ee..0000000 Binary files a/prompter/timm/data/__pycache__/dataset.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/dataset_factory.cpython-37.pyc b/prompter/timm/data/__pycache__/dataset_factory.cpython-37.pyc deleted file mode 100644 index aa1f1b0..0000000 Binary files a/prompter/timm/data/__pycache__/dataset_factory.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/distributed_sampler.cpython-37.pyc b/prompter/timm/data/__pycache__/distributed_sampler.cpython-37.pyc deleted file mode 100644 index fc32b0c..0000000 Binary files a/prompter/timm/data/__pycache__/distributed_sampler.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/loader.cpython-37.pyc b/prompter/timm/data/__pycache__/loader.cpython-37.pyc deleted file mode 100644 index 5d4d49d..0000000 Binary files a/prompter/timm/data/__pycache__/loader.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/mixup.cpython-37.pyc b/prompter/timm/data/__pycache__/mixup.cpython-37.pyc deleted file mode 100644 index 58e753b..0000000 Binary files a/prompter/timm/data/__pycache__/mixup.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/random_erasing.cpython-37.pyc b/prompter/timm/data/__pycache__/random_erasing.cpython-37.pyc deleted file mode 100644 index c75f6de..0000000 Binary files a/prompter/timm/data/__pycache__/random_erasing.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/real_labels.cpython-37.pyc b/prompter/timm/data/__pycache__/real_labels.cpython-37.pyc deleted file mode 100644 index 7f737fd..0000000 Binary files a/prompter/timm/data/__pycache__/real_labels.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/transforms.cpython-37.pyc b/prompter/timm/data/__pycache__/transforms.cpython-37.pyc deleted file mode 100644 index 8f39411..0000000 Binary files a/prompter/timm/data/__pycache__/transforms.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/__pycache__/transforms_factory.cpython-37.pyc b/prompter/timm/data/__pycache__/transforms_factory.cpython-37.pyc deleted file mode 100644 index 22f4b48..0000000 Binary files a/prompter/timm/data/__pycache__/transforms_factory.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/parsers/__pycache__/__init__.cpython-37.pyc b/prompter/timm/data/parsers/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 61e1909..0000000 Binary files a/prompter/timm/data/parsers/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/parsers/__pycache__/__init__.cpython-39.pyc b/prompter/timm/data/parsers/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 1458df1..0000000 Binary files a/prompter/timm/data/parsers/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/data/parsers/__pycache__/class_map.cpython-37.pyc b/prompter/timm/data/parsers/__pycache__/class_map.cpython-37.pyc deleted file mode 100644 index 206b4e0..0000000 Binary files a/prompter/timm/data/parsers/__pycache__/class_map.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/parsers/__pycache__/img_extensions.cpython-37.pyc b/prompter/timm/data/parsers/__pycache__/img_extensions.cpython-37.pyc deleted file mode 100644 index f0ae6bf..0000000 Binary files a/prompter/timm/data/parsers/__pycache__/img_extensions.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/parsers/__pycache__/parser.cpython-37.pyc b/prompter/timm/data/parsers/__pycache__/parser.cpython-37.pyc deleted file mode 100644 index b97dcc2..0000000 Binary files a/prompter/timm/data/parsers/__pycache__/parser.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/parsers/__pycache__/parser_factory.cpython-37.pyc b/prompter/timm/data/parsers/__pycache__/parser_factory.cpython-37.pyc deleted file mode 100644 index 8482a99..0000000 Binary files a/prompter/timm/data/parsers/__pycache__/parser_factory.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/parsers/__pycache__/parser_factory.cpython-39.pyc b/prompter/timm/data/parsers/__pycache__/parser_factory.cpython-39.pyc deleted file mode 100644 index ef3d115..0000000 Binary files a/prompter/timm/data/parsers/__pycache__/parser_factory.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/data/parsers/__pycache__/parser_image_folder.cpython-37.pyc b/prompter/timm/data/parsers/__pycache__/parser_image_folder.cpython-37.pyc deleted file mode 100644 index 2ee67e1..0000000 Binary files a/prompter/timm/data/parsers/__pycache__/parser_image_folder.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/data/parsers/__pycache__/parser_image_folder.cpython-39.pyc b/prompter/timm/data/parsers/__pycache__/parser_image_folder.cpython-39.pyc deleted file mode 100644 index f66205d..0000000 Binary files a/prompter/timm/data/parsers/__pycache__/parser_image_folder.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/data/parsers/__pycache__/parser_image_in_tar.cpython-37.pyc b/prompter/timm/data/parsers/__pycache__/parser_image_in_tar.cpython-37.pyc deleted file mode 100644 index 820f206..0000000 Binary files a/prompter/timm/data/parsers/__pycache__/parser_image_in_tar.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/__init__.cpython-37.pyc b/prompter/timm/models/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 3d56823..0000000 Binary files a/prompter/timm/models/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/__init__.cpython-39.pyc b/prompter/timm/models/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 0ee5296..0000000 Binary files a/prompter/timm/models/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/beit.cpython-37.pyc b/prompter/timm/models/__pycache__/beit.cpython-37.pyc deleted file mode 100644 index bc919f6..0000000 Binary files a/prompter/timm/models/__pycache__/beit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/beit.cpython-39.pyc b/prompter/timm/models/__pycache__/beit.cpython-39.pyc deleted file mode 100644 index 39c96a7..0000000 Binary files a/prompter/timm/models/__pycache__/beit.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/byoanet.cpython-37.pyc b/prompter/timm/models/__pycache__/byoanet.cpython-37.pyc deleted file mode 100644 index f9c6cb6..0000000 Binary files a/prompter/timm/models/__pycache__/byoanet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/byobnet.cpython-37.pyc b/prompter/timm/models/__pycache__/byobnet.cpython-37.pyc deleted file mode 100644 index 5423fcd..0000000 Binary files a/prompter/timm/models/__pycache__/byobnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/cait.cpython-37.pyc b/prompter/timm/models/__pycache__/cait.cpython-37.pyc deleted file mode 100644 index 0969f83..0000000 Binary files a/prompter/timm/models/__pycache__/cait.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/coat.cpython-37.pyc b/prompter/timm/models/__pycache__/coat.cpython-37.pyc deleted file mode 100644 index 815b940..0000000 Binary files a/prompter/timm/models/__pycache__/coat.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/convit.cpython-37.pyc b/prompter/timm/models/__pycache__/convit.cpython-37.pyc deleted file mode 100644 index 8931d80..0000000 Binary files a/prompter/timm/models/__pycache__/convit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/convmixer.cpython-37.pyc b/prompter/timm/models/__pycache__/convmixer.cpython-37.pyc deleted file mode 100644 index 0a21bab..0000000 Binary files a/prompter/timm/models/__pycache__/convmixer.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/convnext.cpython-37.pyc b/prompter/timm/models/__pycache__/convnext.cpython-37.pyc deleted file mode 100644 index 47f8218..0000000 Binary files a/prompter/timm/models/__pycache__/convnext.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/crossvit.cpython-37.pyc b/prompter/timm/models/__pycache__/crossvit.cpython-37.pyc deleted file mode 100644 index 4713c83..0000000 Binary files a/prompter/timm/models/__pycache__/crossvit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/cspnet.cpython-37.pyc b/prompter/timm/models/__pycache__/cspnet.cpython-37.pyc deleted file mode 100644 index e748e8e..0000000 Binary files a/prompter/timm/models/__pycache__/cspnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/deit.cpython-37.pyc b/prompter/timm/models/__pycache__/deit.cpython-37.pyc deleted file mode 100644 index be1d53f..0000000 Binary files a/prompter/timm/models/__pycache__/deit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/densenet.cpython-37.pyc b/prompter/timm/models/__pycache__/densenet.cpython-37.pyc deleted file mode 100644 index a208480..0000000 Binary files a/prompter/timm/models/__pycache__/densenet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/dla.cpython-37.pyc b/prompter/timm/models/__pycache__/dla.cpython-37.pyc deleted file mode 100644 index 0d74965..0000000 Binary files a/prompter/timm/models/__pycache__/dla.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/dpn.cpython-37.pyc b/prompter/timm/models/__pycache__/dpn.cpython-37.pyc deleted file mode 100644 index ffb4f76..0000000 Binary files a/prompter/timm/models/__pycache__/dpn.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/edgenext.cpython-37.pyc b/prompter/timm/models/__pycache__/edgenext.cpython-37.pyc deleted file mode 100644 index e05db64..0000000 Binary files a/prompter/timm/models/__pycache__/edgenext.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/efficientformer.cpython-37.pyc b/prompter/timm/models/__pycache__/efficientformer.cpython-37.pyc deleted file mode 100644 index 5f112b3..0000000 Binary files a/prompter/timm/models/__pycache__/efficientformer.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/efficientnet.cpython-37.pyc b/prompter/timm/models/__pycache__/efficientnet.cpython-37.pyc deleted file mode 100644 index b2f2781..0000000 Binary files a/prompter/timm/models/__pycache__/efficientnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/efficientnet_blocks.cpython-37.pyc b/prompter/timm/models/__pycache__/efficientnet_blocks.cpython-37.pyc deleted file mode 100644 index bd24a14..0000000 Binary files a/prompter/timm/models/__pycache__/efficientnet_blocks.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/efficientnet_builder.cpython-37.pyc b/prompter/timm/models/__pycache__/efficientnet_builder.cpython-37.pyc deleted file mode 100644 index 4b99713..0000000 Binary files a/prompter/timm/models/__pycache__/efficientnet_builder.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/factory.cpython-37.pyc b/prompter/timm/models/__pycache__/factory.cpython-37.pyc deleted file mode 100644 index f859661..0000000 Binary files a/prompter/timm/models/__pycache__/factory.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/features.cpython-37.pyc b/prompter/timm/models/__pycache__/features.cpython-37.pyc deleted file mode 100644 index ede1b05..0000000 Binary files a/prompter/timm/models/__pycache__/features.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/fx_features.cpython-37.pyc b/prompter/timm/models/__pycache__/fx_features.cpython-37.pyc deleted file mode 100644 index 555fe90..0000000 Binary files a/prompter/timm/models/__pycache__/fx_features.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/gcvit.cpython-37.pyc b/prompter/timm/models/__pycache__/gcvit.cpython-37.pyc deleted file mode 100644 index 707bc11..0000000 Binary files a/prompter/timm/models/__pycache__/gcvit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/ghostnet.cpython-37.pyc b/prompter/timm/models/__pycache__/ghostnet.cpython-37.pyc deleted file mode 100644 index d5b1743..0000000 Binary files a/prompter/timm/models/__pycache__/ghostnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/gluon_resnet.cpython-37.pyc b/prompter/timm/models/__pycache__/gluon_resnet.cpython-37.pyc deleted file mode 100644 index ad3e525..0000000 Binary files a/prompter/timm/models/__pycache__/gluon_resnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/gluon_xception.cpython-37.pyc b/prompter/timm/models/__pycache__/gluon_xception.cpython-37.pyc deleted file mode 100644 index 60f07e9..0000000 Binary files a/prompter/timm/models/__pycache__/gluon_xception.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/hardcorenas.cpython-37.pyc b/prompter/timm/models/__pycache__/hardcorenas.cpython-37.pyc deleted file mode 100644 index ffe5a0d..0000000 Binary files a/prompter/timm/models/__pycache__/hardcorenas.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/helpers.cpython-37.pyc b/prompter/timm/models/__pycache__/helpers.cpython-37.pyc deleted file mode 100644 index 38cab14..0000000 Binary files a/prompter/timm/models/__pycache__/helpers.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/hrnet.cpython-37.pyc b/prompter/timm/models/__pycache__/hrnet.cpython-37.pyc deleted file mode 100644 index 0a2d0c2..0000000 Binary files a/prompter/timm/models/__pycache__/hrnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/hub.cpython-37.pyc b/prompter/timm/models/__pycache__/hub.cpython-37.pyc deleted file mode 100644 index 3a23d34..0000000 Binary files a/prompter/timm/models/__pycache__/hub.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/inception_resnet_v2.cpython-37.pyc b/prompter/timm/models/__pycache__/inception_resnet_v2.cpython-37.pyc deleted file mode 100644 index 41db45a..0000000 Binary files a/prompter/timm/models/__pycache__/inception_resnet_v2.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/inception_v3.cpython-37.pyc b/prompter/timm/models/__pycache__/inception_v3.cpython-37.pyc deleted file mode 100644 index 9df5079..0000000 Binary files a/prompter/timm/models/__pycache__/inception_v3.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/inception_v4.cpython-37.pyc b/prompter/timm/models/__pycache__/inception_v4.cpython-37.pyc deleted file mode 100644 index 229eec2..0000000 Binary files a/prompter/timm/models/__pycache__/inception_v4.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/levit.cpython-37.pyc b/prompter/timm/models/__pycache__/levit.cpython-37.pyc deleted file mode 100644 index 5f429ee..0000000 Binary files a/prompter/timm/models/__pycache__/levit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/maxxvit.cpython-37.pyc b/prompter/timm/models/__pycache__/maxxvit.cpython-37.pyc deleted file mode 100644 index 8282943..0000000 Binary files a/prompter/timm/models/__pycache__/maxxvit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/mlp_mixer.cpython-37.pyc b/prompter/timm/models/__pycache__/mlp_mixer.cpython-37.pyc deleted file mode 100644 index 5507be2..0000000 Binary files a/prompter/timm/models/__pycache__/mlp_mixer.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/mobilenetv3.cpython-37.pyc b/prompter/timm/models/__pycache__/mobilenetv3.cpython-37.pyc deleted file mode 100644 index 456e95f..0000000 Binary files a/prompter/timm/models/__pycache__/mobilenetv3.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/mobilevit.cpython-37.pyc b/prompter/timm/models/__pycache__/mobilevit.cpython-37.pyc deleted file mode 100644 index 873d8ec..0000000 Binary files a/prompter/timm/models/__pycache__/mobilevit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/mvitv2.cpython-37.pyc b/prompter/timm/models/__pycache__/mvitv2.cpython-37.pyc deleted file mode 100644 index 3cc18af..0000000 Binary files a/prompter/timm/models/__pycache__/mvitv2.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/nasnet.cpython-37.pyc b/prompter/timm/models/__pycache__/nasnet.cpython-37.pyc deleted file mode 100644 index 7842d92..0000000 Binary files a/prompter/timm/models/__pycache__/nasnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/nest.cpython-37.pyc b/prompter/timm/models/__pycache__/nest.cpython-37.pyc deleted file mode 100644 index 85bfd14..0000000 Binary files a/prompter/timm/models/__pycache__/nest.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/nfnet.cpython-37.pyc b/prompter/timm/models/__pycache__/nfnet.cpython-37.pyc deleted file mode 100644 index 464ac10..0000000 Binary files a/prompter/timm/models/__pycache__/nfnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/pit.cpython-37.pyc b/prompter/timm/models/__pycache__/pit.cpython-37.pyc deleted file mode 100644 index b820173..0000000 Binary files a/prompter/timm/models/__pycache__/pit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/pnasnet.cpython-37.pyc b/prompter/timm/models/__pycache__/pnasnet.cpython-37.pyc deleted file mode 100644 index bcdaba1..0000000 Binary files a/prompter/timm/models/__pycache__/pnasnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/poolformer.cpython-37.pyc b/prompter/timm/models/__pycache__/poolformer.cpython-37.pyc deleted file mode 100644 index e0ecc9b..0000000 Binary files a/prompter/timm/models/__pycache__/poolformer.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/pvt_v2.cpython-37.pyc b/prompter/timm/models/__pycache__/pvt_v2.cpython-37.pyc deleted file mode 100644 index 768f2a2..0000000 Binary files a/prompter/timm/models/__pycache__/pvt_v2.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/registry.cpython-37.pyc b/prompter/timm/models/__pycache__/registry.cpython-37.pyc deleted file mode 100644 index 709a0b8..0000000 Binary files a/prompter/timm/models/__pycache__/registry.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/regnet.cpython-37.pyc b/prompter/timm/models/__pycache__/regnet.cpython-37.pyc deleted file mode 100644 index df14e5f..0000000 Binary files a/prompter/timm/models/__pycache__/regnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/res2net.cpython-37.pyc b/prompter/timm/models/__pycache__/res2net.cpython-37.pyc deleted file mode 100644 index 7cb0165..0000000 Binary files a/prompter/timm/models/__pycache__/res2net.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/resnest.cpython-37.pyc b/prompter/timm/models/__pycache__/resnest.cpython-37.pyc deleted file mode 100644 index 6717ca2..0000000 Binary files a/prompter/timm/models/__pycache__/resnest.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/resnet.cpython-37.pyc b/prompter/timm/models/__pycache__/resnet.cpython-37.pyc deleted file mode 100644 index b4ebaaf..0000000 Binary files a/prompter/timm/models/__pycache__/resnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/resnetv2.cpython-37.pyc b/prompter/timm/models/__pycache__/resnetv2.cpython-37.pyc deleted file mode 100644 index 37ddbbb..0000000 Binary files a/prompter/timm/models/__pycache__/resnetv2.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/rexnet.cpython-37.pyc b/prompter/timm/models/__pycache__/rexnet.cpython-37.pyc deleted file mode 100644 index a899f61..0000000 Binary files a/prompter/timm/models/__pycache__/rexnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/selecsls.cpython-37.pyc b/prompter/timm/models/__pycache__/selecsls.cpython-37.pyc deleted file mode 100644 index 1f37f22..0000000 Binary files a/prompter/timm/models/__pycache__/selecsls.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/senet.cpython-37.pyc b/prompter/timm/models/__pycache__/senet.cpython-37.pyc deleted file mode 100644 index b08e298..0000000 Binary files a/prompter/timm/models/__pycache__/senet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/sequencer.cpython-37.pyc b/prompter/timm/models/__pycache__/sequencer.cpython-37.pyc deleted file mode 100644 index 59ed5d3..0000000 Binary files a/prompter/timm/models/__pycache__/sequencer.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/sknet.cpython-37.pyc b/prompter/timm/models/__pycache__/sknet.cpython-37.pyc deleted file mode 100644 index 793277e..0000000 Binary files a/prompter/timm/models/__pycache__/sknet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/swin_transformer.cpython-37.pyc b/prompter/timm/models/__pycache__/swin_transformer.cpython-37.pyc deleted file mode 100644 index 5d7ec22..0000000 Binary files a/prompter/timm/models/__pycache__/swin_transformer.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/swin_transformer_v2.cpython-37.pyc b/prompter/timm/models/__pycache__/swin_transformer_v2.cpython-37.pyc deleted file mode 100644 index e154b66..0000000 Binary files a/prompter/timm/models/__pycache__/swin_transformer_v2.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/swin_transformer_v2_cr.cpython-37.pyc b/prompter/timm/models/__pycache__/swin_transformer_v2_cr.cpython-37.pyc deleted file mode 100644 index 437a36c..0000000 Binary files a/prompter/timm/models/__pycache__/swin_transformer_v2_cr.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/tnt.cpython-37.pyc b/prompter/timm/models/__pycache__/tnt.cpython-37.pyc deleted file mode 100644 index babfb1d..0000000 Binary files a/prompter/timm/models/__pycache__/tnt.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/tresnet.cpython-37.pyc b/prompter/timm/models/__pycache__/tresnet.cpython-37.pyc deleted file mode 100644 index 01029c7..0000000 Binary files a/prompter/timm/models/__pycache__/tresnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/twins.cpython-37.pyc b/prompter/timm/models/__pycache__/twins.cpython-37.pyc deleted file mode 100644 index 6df35c2..0000000 Binary files a/prompter/timm/models/__pycache__/twins.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/vgg.cpython-37.pyc b/prompter/timm/models/__pycache__/vgg.cpython-37.pyc deleted file mode 100644 index fc0f9aa..0000000 Binary files a/prompter/timm/models/__pycache__/vgg.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/visformer.cpython-37.pyc b/prompter/timm/models/__pycache__/visformer.cpython-37.pyc deleted file mode 100644 index 22eae11..0000000 Binary files a/prompter/timm/models/__pycache__/visformer.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/vision_transformer.cpython-37.pyc b/prompter/timm/models/__pycache__/vision_transformer.cpython-37.pyc deleted file mode 100644 index 1935a28..0000000 Binary files a/prompter/timm/models/__pycache__/vision_transformer.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/vision_transformer_hybrid.cpython-37.pyc b/prompter/timm/models/__pycache__/vision_transformer_hybrid.cpython-37.pyc deleted file mode 100644 index 3b97c08..0000000 Binary files a/prompter/timm/models/__pycache__/vision_transformer_hybrid.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/vision_transformer_relpos.cpython-37.pyc b/prompter/timm/models/__pycache__/vision_transformer_relpos.cpython-37.pyc deleted file mode 100644 index f778602..0000000 Binary files a/prompter/timm/models/__pycache__/vision_transformer_relpos.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/volo.cpython-37.pyc b/prompter/timm/models/__pycache__/volo.cpython-37.pyc deleted file mode 100644 index 7c94f35..0000000 Binary files a/prompter/timm/models/__pycache__/volo.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/vovnet.cpython-37.pyc b/prompter/timm/models/__pycache__/vovnet.cpython-37.pyc deleted file mode 100644 index 8a659ae..0000000 Binary files a/prompter/timm/models/__pycache__/vovnet.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/xception.cpython-37.pyc b/prompter/timm/models/__pycache__/xception.cpython-37.pyc deleted file mode 100644 index c0a71c8..0000000 Binary files a/prompter/timm/models/__pycache__/xception.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/xception_aligned.cpython-37.pyc b/prompter/timm/models/__pycache__/xception_aligned.cpython-37.pyc deleted file mode 100644 index 2224631..0000000 Binary files a/prompter/timm/models/__pycache__/xception_aligned.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/__pycache__/xcit.cpython-37.pyc b/prompter/timm/models/__pycache__/xcit.cpython-37.pyc deleted file mode 100644 index 9cf6ad0..0000000 Binary files a/prompter/timm/models/__pycache__/xcit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/__init__.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index cbf2728..0000000 Binary files a/prompter/timm/models/layers/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/activations.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/activations.cpython-37.pyc deleted file mode 100644 index a79ca35..0000000 Binary files a/prompter/timm/models/layers/__pycache__/activations.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/activations_jit.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/activations_jit.cpython-37.pyc deleted file mode 100644 index d6eafb8..0000000 Binary files a/prompter/timm/models/layers/__pycache__/activations_jit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/activations_me.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/activations_me.cpython-37.pyc deleted file mode 100644 index 7a194c2..0000000 Binary files a/prompter/timm/models/layers/__pycache__/activations_me.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/adaptive_avgmax_pool.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/adaptive_avgmax_pool.cpython-37.pyc deleted file mode 100644 index f5eab43..0000000 Binary files a/prompter/timm/models/layers/__pycache__/adaptive_avgmax_pool.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/blur_pool.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/blur_pool.cpython-37.pyc deleted file mode 100644 index 8b6d970..0000000 Binary files a/prompter/timm/models/layers/__pycache__/blur_pool.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/bottleneck_attn.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/bottleneck_attn.cpython-37.pyc deleted file mode 100644 index e04bce8..0000000 Binary files a/prompter/timm/models/layers/__pycache__/bottleneck_attn.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/cbam.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/cbam.cpython-37.pyc deleted file mode 100644 index d7b8e15..0000000 Binary files a/prompter/timm/models/layers/__pycache__/cbam.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/classifier.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/classifier.cpython-37.pyc deleted file mode 100644 index 747a4e5..0000000 Binary files a/prompter/timm/models/layers/__pycache__/classifier.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/cond_conv2d.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/cond_conv2d.cpython-37.pyc deleted file mode 100644 index 9ab53a2..0000000 Binary files a/prompter/timm/models/layers/__pycache__/cond_conv2d.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/config.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/config.cpython-37.pyc deleted file mode 100644 index 66394f6..0000000 Binary files a/prompter/timm/models/layers/__pycache__/config.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/conv2d_same.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/conv2d_same.cpython-37.pyc deleted file mode 100644 index a35723a..0000000 Binary files a/prompter/timm/models/layers/__pycache__/conv2d_same.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/conv_bn_act.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/conv_bn_act.cpython-37.pyc deleted file mode 100644 index 402c19b..0000000 Binary files a/prompter/timm/models/layers/__pycache__/conv_bn_act.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/create_act.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/create_act.cpython-37.pyc deleted file mode 100644 index 22a8dc1..0000000 Binary files a/prompter/timm/models/layers/__pycache__/create_act.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/create_attn.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/create_attn.cpython-37.pyc deleted file mode 100644 index e7264b4..0000000 Binary files a/prompter/timm/models/layers/__pycache__/create_attn.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/create_conv2d.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/create_conv2d.cpython-37.pyc deleted file mode 100644 index 588a802..0000000 Binary files a/prompter/timm/models/layers/__pycache__/create_conv2d.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/create_norm.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/create_norm.cpython-37.pyc deleted file mode 100644 index 3c2a457..0000000 Binary files a/prompter/timm/models/layers/__pycache__/create_norm.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/create_norm_act.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/create_norm_act.cpython-37.pyc deleted file mode 100644 index 2380446..0000000 Binary files a/prompter/timm/models/layers/__pycache__/create_norm_act.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/drop.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/drop.cpython-37.pyc deleted file mode 100644 index ea11014..0000000 Binary files a/prompter/timm/models/layers/__pycache__/drop.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/eca.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/eca.cpython-37.pyc deleted file mode 100644 index 8145223..0000000 Binary files a/prompter/timm/models/layers/__pycache__/eca.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/evo_norm.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/evo_norm.cpython-37.pyc deleted file mode 100644 index 8705c21..0000000 Binary files a/prompter/timm/models/layers/__pycache__/evo_norm.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/fast_norm.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/fast_norm.cpython-37.pyc deleted file mode 100644 index f0eae98..0000000 Binary files a/prompter/timm/models/layers/__pycache__/fast_norm.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/filter_response_norm.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/filter_response_norm.cpython-37.pyc deleted file mode 100644 index 9e13dfe..0000000 Binary files a/prompter/timm/models/layers/__pycache__/filter_response_norm.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/gather_excite.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/gather_excite.cpython-37.pyc deleted file mode 100644 index 3a57e46..0000000 Binary files a/prompter/timm/models/layers/__pycache__/gather_excite.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/global_context.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/global_context.cpython-37.pyc deleted file mode 100644 index 7631c1c..0000000 Binary files a/prompter/timm/models/layers/__pycache__/global_context.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/halo_attn.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/halo_attn.cpython-37.pyc deleted file mode 100644 index 51842e2..0000000 Binary files a/prompter/timm/models/layers/__pycache__/halo_attn.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/helpers.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/helpers.cpython-37.pyc deleted file mode 100644 index 0500268..0000000 Binary files a/prompter/timm/models/layers/__pycache__/helpers.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/inplace_abn.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/inplace_abn.cpython-37.pyc deleted file mode 100644 index 06e042c..0000000 Binary files a/prompter/timm/models/layers/__pycache__/inplace_abn.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/lambda_layer.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/lambda_layer.cpython-37.pyc deleted file mode 100644 index fa11553..0000000 Binary files a/prompter/timm/models/layers/__pycache__/lambda_layer.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/linear.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/linear.cpython-37.pyc deleted file mode 100644 index a998a49..0000000 Binary files a/prompter/timm/models/layers/__pycache__/linear.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/mixed_conv2d.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/mixed_conv2d.cpython-37.pyc deleted file mode 100644 index da3d723..0000000 Binary files a/prompter/timm/models/layers/__pycache__/mixed_conv2d.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/mlp.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/mlp.cpython-37.pyc deleted file mode 100644 index 286e113..0000000 Binary files a/prompter/timm/models/layers/__pycache__/mlp.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/non_local_attn.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/non_local_attn.cpython-37.pyc deleted file mode 100644 index c6c52aa..0000000 Binary files a/prompter/timm/models/layers/__pycache__/non_local_attn.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/norm.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/norm.cpython-37.pyc deleted file mode 100644 index 9b49cff..0000000 Binary files a/prompter/timm/models/layers/__pycache__/norm.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/norm_act.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/norm_act.cpython-37.pyc deleted file mode 100644 index d77330b..0000000 Binary files a/prompter/timm/models/layers/__pycache__/norm_act.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/padding.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/padding.cpython-37.pyc deleted file mode 100644 index 4400764..0000000 Binary files a/prompter/timm/models/layers/__pycache__/padding.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/patch_embed.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/patch_embed.cpython-37.pyc deleted file mode 100644 index c89ee47..0000000 Binary files a/prompter/timm/models/layers/__pycache__/patch_embed.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/pool2d_same.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/pool2d_same.cpython-37.pyc deleted file mode 100644 index e3b3fbb..0000000 Binary files a/prompter/timm/models/layers/__pycache__/pool2d_same.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/selective_kernel.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/selective_kernel.cpython-37.pyc deleted file mode 100644 index 46d7fd2..0000000 Binary files a/prompter/timm/models/layers/__pycache__/selective_kernel.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/separable_conv.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/separable_conv.cpython-37.pyc deleted file mode 100644 index eba02eb..0000000 Binary files a/prompter/timm/models/layers/__pycache__/separable_conv.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/space_to_depth.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/space_to_depth.cpython-37.pyc deleted file mode 100644 index a434b66..0000000 Binary files a/prompter/timm/models/layers/__pycache__/space_to_depth.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/split_attn.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/split_attn.cpython-37.pyc deleted file mode 100644 index 277f22b..0000000 Binary files a/prompter/timm/models/layers/__pycache__/split_attn.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/split_batchnorm.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/split_batchnorm.cpython-37.pyc deleted file mode 100644 index 08517f8..0000000 Binary files a/prompter/timm/models/layers/__pycache__/split_batchnorm.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/squeeze_excite.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/squeeze_excite.cpython-37.pyc deleted file mode 100644 index 70d3185..0000000 Binary files a/prompter/timm/models/layers/__pycache__/squeeze_excite.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/std_conv.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/std_conv.cpython-37.pyc deleted file mode 100644 index 301dfe4..0000000 Binary files a/prompter/timm/models/layers/__pycache__/std_conv.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/test_time_pool.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/test_time_pool.cpython-37.pyc deleted file mode 100644 index 9d1e8ae..0000000 Binary files a/prompter/timm/models/layers/__pycache__/test_time_pool.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/trace_utils.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/trace_utils.cpython-37.pyc deleted file mode 100644 index 5b34d66..0000000 Binary files a/prompter/timm/models/layers/__pycache__/trace_utils.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/models/layers/__pycache__/weight_init.cpython-37.pyc b/prompter/timm/models/layers/__pycache__/weight_init.cpython-37.pyc deleted file mode 100644 index 56f7f4e..0000000 Binary files a/prompter/timm/models/layers/__pycache__/weight_init.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/__init__.cpython-37.pyc b/prompter/timm/utils/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 35eca4b..0000000 Binary files a/prompter/timm/utils/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/__init__.cpython-39.pyc b/prompter/timm/utils/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 0593d13..0000000 Binary files a/prompter/timm/utils/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/agc.cpython-37.pyc b/prompter/timm/utils/__pycache__/agc.cpython-37.pyc deleted file mode 100644 index a858d76..0000000 Binary files a/prompter/timm/utils/__pycache__/agc.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/agc.cpython-39.pyc b/prompter/timm/utils/__pycache__/agc.cpython-39.pyc deleted file mode 100644 index 0534191..0000000 Binary files a/prompter/timm/utils/__pycache__/agc.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/checkpoint_saver.cpython-37.pyc b/prompter/timm/utils/__pycache__/checkpoint_saver.cpython-37.pyc deleted file mode 100644 index 26a4603..0000000 Binary files a/prompter/timm/utils/__pycache__/checkpoint_saver.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/checkpoint_saver.cpython-39.pyc b/prompter/timm/utils/__pycache__/checkpoint_saver.cpython-39.pyc deleted file mode 100644 index 69aa523..0000000 Binary files a/prompter/timm/utils/__pycache__/checkpoint_saver.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/clip_grad.cpython-37.pyc b/prompter/timm/utils/__pycache__/clip_grad.cpython-37.pyc deleted file mode 100644 index 041c9f5..0000000 Binary files a/prompter/timm/utils/__pycache__/clip_grad.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/cuda.cpython-37.pyc b/prompter/timm/utils/__pycache__/cuda.cpython-37.pyc deleted file mode 100644 index 5373014..0000000 Binary files a/prompter/timm/utils/__pycache__/cuda.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/decay_batch.cpython-37.pyc b/prompter/timm/utils/__pycache__/decay_batch.cpython-37.pyc deleted file mode 100644 index 2d0c8b9..0000000 Binary files a/prompter/timm/utils/__pycache__/decay_batch.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/distributed.cpython-37.pyc b/prompter/timm/utils/__pycache__/distributed.cpython-37.pyc deleted file mode 100644 index df0124c..0000000 Binary files a/prompter/timm/utils/__pycache__/distributed.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/jit.cpython-37.pyc b/prompter/timm/utils/__pycache__/jit.cpython-37.pyc deleted file mode 100644 index 3b0d449..0000000 Binary files a/prompter/timm/utils/__pycache__/jit.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/log.cpython-37.pyc b/prompter/timm/utils/__pycache__/log.cpython-37.pyc deleted file mode 100644 index af9a6d8..0000000 Binary files a/prompter/timm/utils/__pycache__/log.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/metrics.cpython-37.pyc b/prompter/timm/utils/__pycache__/metrics.cpython-37.pyc deleted file mode 100644 index a0d5c6e..0000000 Binary files a/prompter/timm/utils/__pycache__/metrics.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/misc.cpython-37.pyc b/prompter/timm/utils/__pycache__/misc.cpython-37.pyc deleted file mode 100644 index ca16c56..0000000 Binary files a/prompter/timm/utils/__pycache__/misc.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/model.cpython-37.pyc b/prompter/timm/utils/__pycache__/model.cpython-37.pyc deleted file mode 100644 index 5b6eccb..0000000 Binary files a/prompter/timm/utils/__pycache__/model.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/model.cpython-39.pyc b/prompter/timm/utils/__pycache__/model.cpython-39.pyc deleted file mode 100644 index 5a42420..0000000 Binary files a/prompter/timm/utils/__pycache__/model.cpython-39.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/model_ema.cpython-37.pyc b/prompter/timm/utils/__pycache__/model_ema.cpython-37.pyc deleted file mode 100644 index c4ef589..0000000 Binary files a/prompter/timm/utils/__pycache__/model_ema.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/random.cpython-37.pyc b/prompter/timm/utils/__pycache__/random.cpython-37.pyc deleted file mode 100644 index 0d78613..0000000 Binary files a/prompter/timm/utils/__pycache__/random.cpython-37.pyc and /dev/null differ diff --git a/prompter/timm/utils/__pycache__/summary.cpython-37.pyc b/prompter/timm/utils/__pycache__/summary.cpython-37.pyc deleted file mode 100644 index 1377337..0000000 Binary files a/prompter/timm/utils/__pycache__/summary.cpython-37.pyc and /dev/null differ diff --git a/segmentor/config/lucchi_b.py b/segmentor/config/lucchi_b.py new file mode 100644 index 0000000..a1b38fd --- /dev/null +++ b/segmentor/config/lucchi_b.py @@ -0,0 +1,59 @@ +segmentor = dict( + type='PromptNucSeg-B', + img_size=512, + patch_size=16, + multimask=False +) + +input_shape = segmentor['img_size'] +data = dict( + name='lucchi', + num_classes=1, + num_mask_per_img=25, + batch_size_per_gpu=8, + num_workers=8, + num_neg_prompt=0, + train=dict(transform=[ + dict(type='RandomCrop', height=512, width=512, p=1), + dict(type='RandomRotate90', p=0.5), + dict(type='HorizontalFlip', p=0.5), + dict(type='VerticalFlip', p=0.5), + dict(type='Downscale', scale_max=0.5, scale_min=0.5, p=0.15), + dict(type='Blur', blur_limit=10, p=0.2), + dict(type='GaussNoise', var_limit=50, p=0.25), + dict(type='ColorJitter', brightness=0.25, contrast=0.25, saturation=0.1, hue=0.05, p=0.2), + dict(type='Superpixels', p=0.1, p_replace=0.1, n_segments=200, max_size=int(input_shape / 2)), + dict(type='ZoomBlur', p=0.1, max_factor=1.05), + dict(type='RandomSizedCrop', min_max_height=(int(input_shape / 2), input_shape), + height=input_shape, + width=input_shape, + p=0.1), + dict(type='ElasticTransform', p=0.2, sigma=25, alpha=0.5, alpha_affine=15), + dict(type='Normalize') + ]), + val=dict(transform=[ + dict(type='Normalize'), + ]), + test=dict(transform=[ + dict(type='Normalize'), + ]), + post=dict(iou_threshold=0.5) +) + +optimizer = dict( + type='Adam', + lr=1e-4, + weight_decay=1e-4 +) + +scheduler = dict( + type='MultiStepLR', + milestones=[300], + gamma=0.1 +) + +criterion = dict( + loss_focal=20, + loss_dice=1, + loss_iou=1 +) diff --git a/segmentor/config/lucchi_l.py b/segmentor/config/lucchi_l.py new file mode 100644 index 0000000..f185d22 --- /dev/null +++ b/segmentor/config/lucchi_l.py @@ -0,0 +1,59 @@ +segmentor = dict( + type='PromptNucSeg-L', + img_size=256, + patch_size=16, + multimask=False +) + +input_shape = segmentor['img_size'] +data = dict( + name='lucchi', + num_classes=1, + num_mask_per_img=25, + batch_size_per_gpu=8, + num_workers=8, + num_neg_prompt=0, + train=dict(transform=[ + dict(type='RandomCrop', height=256, width=256, p=1), + dict(type='RandomRotate90', p=0.5), + dict(type='HorizontalFlip', p=0.5), + dict(type='VerticalFlip', p=0.5), + dict(type='Downscale', scale_max=0.5, scale_min=0.5, p=0.15), + dict(type='Blur', blur_limit=10, p=0.2), + dict(type='GaussNoise', var_limit=50, p=0.25), + dict(type='ColorJitter', brightness=0.25, contrast=0.25, saturation=0.1, hue=0.05, p=0.2), + dict(type='Superpixels', p=0.1, p_replace=0.1, n_segments=200, max_size=int(input_shape / 2)), + dict(type='ZoomBlur', p=0.1, max_factor=1.05), + dict(type='RandomSizedCrop', min_max_height=(int(input_shape / 2), input_shape), + height=input_shape, + width=input_shape, + p=0.1), + dict(type='ElasticTransform', p=0.2, sigma=25, alpha=0.5, alpha_affine=15), + dict(type='Normalize') + ]), + val=dict(transform=[ + dict(type='Normalize'), + ]), + test=dict(transform=[ + dict(type='Normalize'), + ]), + post=dict(iou_threshold=0.5) +) + +optimizer = dict( + type='Adam', + lr=1e-4, + weight_decay=1e-4 +) + +scheduler = dict( + type='MultiStepLR', + milestones=[300], + gamma=0.1 +) + +criterion = dict( + loss_focal=20, + loss_dice=1, + loss_iou=1 +) diff --git a/segmentor/dataset.py b/segmentor/dataset.py index 7573a17..a8dc306 100644 --- a/segmentor/dataset.py +++ b/segmentor/dataset.py @@ -9,6 +9,9 @@ from skimage import io from torch.utils.data import Dataset from albumentations.pytorch import ToTensorV2 +import re +import cv2 as cv +from PIL import Image class DataFolder(Dataset): @@ -56,10 +59,19 @@ def __getitem__(self, idx): mask_path = '/'.join(sub_paths) elif self.dataset == 'cpm17': mask_path = f'{img_path[:-4].replace("Images", "Labels")}.mat' + elif self.dataset == 'lucchi' or self.dataset == 'Lucchipp': + mask_path = img_path else: mask_path = f'{img_path[:-4].replace("Images", "Masks")}.npy' - img, mask = io.imread(img_path)[..., :3], load_maskfile(mask_path) + if self.dataset == 'lucchi' or self.dataset == 'Lucchipp': + pattern = re.compile(r'(/mask/)') + raw_path = re.sub(pattern, r'/raw/', img_path) + img = io.imread(raw_path) + img = cv.merge((img, img, img)) + mask = load_maskfile(mask_path) + else: + img, mask = io.imread(img_path)[..., :3], load_maskfile(mask_path) if self.mode != 'train': res = self.transform(image=img) @@ -141,7 +153,7 @@ def __getitem__(self, idx): prompt_points = torch.empty(0, (self.num_neg_prompt + 1), 2) prompt_labels = torch.empty(0, (self.num_neg_prompt + 1)) all_points = torch.empty(0, 2) - inst_map = torch.empty(0, 256, 256) + inst_map = torch.empty(0, 512, 512) cell_types = torch.empty(0) return img, inst_map.long(), prompt_points, prompt_labels, cell_types, all_points @@ -157,6 +169,9 @@ def load_maskfile(mask_path: str): inst_map = scipy.io.loadmat(mask_path)['inst_map'] type_map = (inst_map.copy() > 0).astype(float) + elif 'lucchi' or 'Lucchipp' in mask_path: + inst_map = np.asarray(Image.open(mask_path)) + type_map = (inst_map.copy() > 0).astype(float) else: inst_map = np.load(mask_path) type_map = (inst_map.copy() > 0).astype(float) diff --git a/segmentor/datasets/lucchi/extract_data.py b/segmentor/datasets/lucchi/extract_data.py new file mode 100644 index 0000000..da3f032 --- /dev/null +++ b/segmentor/datasets/lucchi/extract_data.py @@ -0,0 +1,61 @@ +import json +import os +import numpy as np +import cv2 as cv +from PIL import Image +import re + +def mkdir(path): + try: + os.makedirs(path) + except OSError as e: + return + +def sort_key(path): + match = re.search(r'\d+', path) + return int(match.group()) if match else 0 + +train_anno = {'classes': ['mito']} +test_anno = {'classes': ['mito']} + +num_classes = 1 + +for root, _, files in os.walk('.'): + + for file in files: + if root[-4:] == 'mask': + file_path = root + '/' + file + inst_map = np.asarray(Image.open(file_path), dtype=np.uint8) + inst_map = cv.connectedComponents(inst_map)[1] + + points = [[] for _ in range(num_classes)] + print(file) + for pid in np.unique(inst_map)[1:]: + src = ((inst_map == pid) * 255).astype(np.uint8) + + contours = cv.findContours(src, cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE)[0] + for c in contours: + print(c.shape) + cnt = max(contours, key=cv.contourArea) + + M = cv.moments(cnt) + if M['m00']: + cx = int(M['m10'] / M['m00']) + cy = int(M['m01'] / M['m00']) + else: + dist = cv.distanceTransform(src, cv.DIST_L1, 3) + cx, cy = np.argwhere(dist == dist.max())[0, [1, 0]].tolist() + + points[0].append([cx, cy]) + + if 'train' in root: + train_anno[f'datasets/lucchi/train/mask/{file}'] = points + else: + test_anno[f'datasets/lucchi/test/mask/{file}'] = points + +np.save('../lucchi_train_files.npy', sorted(list(train_anno.keys())[1:], key=sort_key)) +np.save('../lucchi_test_files.npy', sorted(list(test_anno.keys())[1:], key=sort_key)) + +mkdir('../../../prompter/datasets/lucchi') +json.dump(train_anno, open('../../../prompter/datasets/lucchi/train.json', 'w')) +json.dump(test_anno, open('../../../prompter/datasets/lucchi/test.json', 'w')) diff --git a/segmentor/main.py b/segmentor/main.py index 87ecde7..906f6e4 100644 --- a/segmentor/main.py +++ b/segmentor/main.py @@ -18,9 +18,10 @@ get_fast_pq, get_fast_aji ) - +import os import argparse +os.environ["WANDB__SERVICE_WAIT"] = "300" def parse_args(): parser = argparse.ArgumentParser('Cell segmentor') @@ -28,12 +29,12 @@ def parse_args(): parser.add_argument('--config', default='pannuke123.py', help='config file') parser.add_argument('--resume', default='', type=str, help='resume from checkpoint') parser.add_argument("--eval", action='store_true', help='only evaluate') - parser.add_argument("--overlap", default=64, type=int, help="overlapping pixels") + parser.add_argument("--overlap", default=320, type=int, help="overlapping pixels") parser.add_argument("--start-epoch", default=0, type=int, metavar="N", help="start epoch") parser.add_argument('--epochs', default=200, type=int) parser.add_argument("--print-freq", default=10, type=int, help="print frequency") - parser.add_argument("--start-eval", default=60, type=int) + parser.add_argument("--start-eval", default=2000, type=int) parser.add_argument('--output_dir', default='', type=str) parser.add_argument('--seed', default=42, type=int) @@ -61,7 +62,6 @@ def main(): init_distributed_mode(args) set_seed(args) - print(args) cfg = Config.fromfile(f'config/{args.config}') if args.output_dir: @@ -153,7 +153,7 @@ def main(): if args.use_wandb and is_main_process(): wandb.init( - project="Segmentor", + project="Segmentor 512 B", name=args.run_name, group=args.group_name, config=vars(args) @@ -256,9 +256,15 @@ def train_on_epoch( images = images.to(device) true_masks = true_masks.to(device) + prompt_points = prompt_points.reshape(1, prompt_points.shape[0], 2) + prompt_labels = prompt_labels.reshape(1, prompt_labels.shape[0]) + prompt_points = prompt_points.to(device) prompt_labels = prompt_labels.to(device) + + + #print(f'{prompt_points=}') cell_nums = cell_nums.to(device) outputs = model( @@ -490,6 +496,7 @@ def evaluate( inds = torch.arange(len(prompt_points)) + #print(f"{len(crop_boxes)=}") for idx, crop_box in enumerate(crop_boxes): x1, y1, x2, y2 = crop_box @@ -528,6 +535,7 @@ def evaluate( masks = inference( model, images[..., y1:y2, x1:x2], + inst_maps[..., y1:y2, x1:x2], crop_box, ori_sizes[0], sub_prompt_points, @@ -549,6 +557,8 @@ def evaluate( all_inds.append(mask_data['inds']) + + model_time = time.time() - model_time metric_logger.update(model_time=model_time) @@ -559,28 +569,32 @@ def evaluate( unique_inds, counts = np.unique(all_inds, return_counts=True) # first-aspect NMS - keep_prior = np.ones(len(all_inds), dtype=bool) - for i in np.where(counts > 1)[0]: - inds = np.where(all_inds == unique_inds[i])[0] - inds = np.delete(inds, np.argmax(all_scores[inds])) - keep_prior[inds] = False - keep_prior = torch.from_numpy(keep_prior) + # keep_prior = np.ones(len(all_inds), dtype=bool) + # for i in np.where(counts > 1)[0]: + # inds = np.where(all_inds == unique_inds[i])[0] + # inds = np.delete(inds, np.argmax(all_scores[inds])) + # keep_prior[inds] = False + # keep_prior = torch.from_numpy(keep_prior) - all_boxes = all_boxes[keep_prior] - all_scores = all_scores[keep_prior] - all_masks = [all_masks[ind] for ind in np.where(keep_prior)[0]] + # all_boxes = all_boxes[keep_prior] + # all_scores = all_scores[keep_prior] + # all_masks = [all_masks[ind] for ind in np.where(keep_prior)[0]] # second-aspect NMS - keep_by_nms = batched_nms( - all_boxes.float(), - all_scores, - torch.zeros_like(all_boxes[:, 0]), # apply cross categories - iou_threshold=iou_threshold - ).numpy() - order = keep_by_nms[::-1] + # keep_by_nms = batched_nms( + # all_boxes.float(), + # all_scores, + # torch.zeros(all_boxes.shape[0]), # apply cross categories + # iou_threshold=iou_threshold + # ).numpy() + # order = keep_by_nms[::-1] b_inst_map = np.zeros_like(inst_maps[0], dtype=int) - for iid, ind in enumerate(order): - b_inst_map[all_masks[ind]] = iid + 1 + for mask in all_masks: + #TODO better way to merge mask, for now union + b_inst_map += mask + # for iid, ind in enumerate(order): + # b_inst_map[all_masks[ind]] = iid + 1 + if len(np.unique(inst_maps[0])) == 1: bpq_tmp = np.nan @@ -589,7 +603,9 @@ def evaluate( else: [bdq_tmp, bsq_tmp, bpq_tmp], _ = get_fast_pq( remap_label(inst_maps[0]), - remap_label(b_inst_map) + remap_label(b_inst_map), + i=data_iter_step, + args=args ) aji_score = get_fast_aji( diff --git a/segmentor/prompts_on_img.py b/segmentor/prompts_on_img.py new file mode 100644 index 0000000..1e2722f --- /dev/null +++ b/segmentor/prompts_on_img.py @@ -0,0 +1,26 @@ +import numpy as np +import matplotlib.pyplot as plt +import os + +test_path_raw = 'datasets/lucchi/test/raw/' +prompt_path = 'prompts/lucchi/' +to_save = 'prompts/visual/lucchi/' +os.makedirs(to_save, exist_ok=True) + +for file in os.listdir(test_path_raw): + print(test_path_raw + file) + if file[-3:] != 'png': + continue + + im = plt.imread(test_path_raw + file) + implot = plt.imshow(im, cmap='gray') + + a = np.load(prompt_path + file[:-4] + '.npy') + + categories = a[:, 2] + colormap = np.array(['red', 'blue', 'green', 'brown']) + + plt.scatter(a[:, 0], a[:, 1], s=50, c=colormap[categories.astype(int)]) + plt.savefig(to_save + file) + plt.clf() + diff --git a/segmentor/stats_utils.py b/segmentor/stats_utils.py index f140fb7..055ab08 100644 --- a/segmentor/stats_utils.py +++ b/segmentor/stats_utils.py @@ -18,7 +18,7 @@ def get_fast_aji(true, pred): """ true = np.copy(true) # ? do we need this - pred = np.copy(pred) + pred = np.copy(pred > 0) true_id_list = list(np.unique(true)) pred_id_list = list(np.unique(pred)) @@ -173,9 +173,39 @@ def get_fast_aji_plus(true, pred): aji_score = overall_inter / overall_union return aji_score +from PIL import Image +def save_two_masks(gt_mask, pred_mask, in_pq_path, prompt_path, save_mask_path): + #TODO use args to generate raw masks + + + img = Image.fromarray((pred_mask * 255).astype(np.uint8), mode='L') + img.save(save_mask_path) + + prompts = np.load(prompt_path) + categories = prompts[:, 2] + colormap = np.array(['blue', 'green', 'brown']) + + fig, axes = plt.subplots(1, 2, figsize=(10, 5)) + # Plot the first mask + axes[0].imshow(gt_mask, cmap='gray') + axes[0].set_title('Mask GT') + axes[0].scatter(prompts[:, 0], prompts[:, 1], s=30, c=colormap[categories.astype(int)]) + + #print(np.unique(pred_mask)) + cp = pred_mask + + # Plot the second mask + axes[1].imshow(cp, cmap='gray') + axes[1].set_title('Mask Pred') + + # Adjust layout to prevent overlap + plt.tight_layout() + + # Save the figure + plt.savefig(in_pq_path) ##### -def get_fast_pq(true, pred, match_iou=0.5): +def get_fast_pq(true, pred, match_iou=0.5, i=999, args=None): """`match_iou` is the IoU threshold level to determine the pairing between GT instances `p` and prediction instances `g`. `p` and `g` is a pair if IoU > `match_iou`. However, pair of `p` and `g` must be unique @@ -200,6 +230,10 @@ def get_fast_pq(true, pred, match_iou=0.5): """ assert match_iou >= 0.0, "Cant' be negative" + pred = pred > 0 + save_two_masks(true, pred, f'results/in_pq/{i}.png', f'prompts/Lucchipp/{i}.npy', + f'results/masks/{i}.png') + true = np.copy(true) pred = np.copy(pred) true_id_list = list(np.unique(true)) diff --git a/segmentor/utils.py b/segmentor/utils.py index 0abb787..85319de 100644 --- a/segmentor/utils.py +++ b/segmentor/utils.py @@ -15,6 +15,10 @@ from torchvision.transforms.functional import hflip, vflip from scipy.spatial.distance import directed_hausdorff as hausdorff +import albumentations as A +IMG_SAVE = 0 +WHOLE = 0 +MAX_IMG = 50 def train_collate_fn(batch): images, masks, prompt_points, prompt_labels, all_points, all_points_types, cell_nums = [[] for _ in range(7)] @@ -465,7 +469,7 @@ def start_points( ): points = [0] counter = 1 - stride = 256 - overlap + stride = split_size - overlap while True: pt = stride * counter if pt + split_size >= size: @@ -508,12 +512,75 @@ def start_points( from torchvision.ops.boxes import batched_nms import torch.nn as nn +from PIL import Image +import matplotlib.pyplot as plt +def save_two_masks(gt_mask, pred_mask, path): + gt_mask = np.array(gt_mask[0]) + pred_mask = np.array(pred_mask) + + fig, axes = plt.subplots(1, 2, figsize=(10, 5)) + + # Plot the first mask + axes[0].imshow(gt_mask, cmap='gray') + axes[0].set_title('Mask GT') + + # Plot the second mask + axes[1].imshow(pred_mask, cmap='gray') + axes[1].set_title('Mask Pred') + + # Adjust layout to prevent overlap + plt.tight_layout() + + # Save the figure + plt.savefig(path) + + +def save_result_as_image(input_image, segmentation_result, output_path): + # Convert PyTorch tensor to numpy array + input_image_np = np.array(input_image.squeeze(0).permute(1, 2, 0).cpu()) + # print(input_image_np.shape) + # print(input_image_np) + # TODO + inverse_transform = A.Compose([ A.Normalize(mean = [ 0., 0., 0. ], + std = [ 1/0.229, 1/0.224, 1/0.225 ]), + A.Normalize(mean = [ -0.485, -0.456, -0.406 ], + std = [ 1., 1., 1. ]), + ]) + # Apply the inverse transformation + original_image = inverse_transform(image=input_image_np)['image'] + + + # Ensure values are within the valid range (0 to 1 for normalized images) + #original_image = np.clip(original_image, 0, 1) + + input_image_np = original_image + #print(input_image_np) + + segmentation_result_np = np.array(segmentation_result.cpu()) + + # Convert segmentation result to a binary mask for visualization + segmentation_mask = (segmentation_result_np > 0).astype(np.uint8) * 122 + + im = Image.fromarray(segmentation_mask) + #im.save(output_path) + + + # Create an RGBA image with the input image and segmentation mask + merged_image = Image.new("RGB", input_image_np.shape[:2][::-1], (255, 255, 255, 0)) + input_image_rgba = Image.fromarray((input_image_np * 255).astype(np.uint8)) + segmentation_mask_rgba = Image.fromarray(segmentation_mask, "L") + merged_image.paste(input_image_rgba, (0, 0, input_image_rgba.width, input_image_rgba.height)) + merged_image.paste(segmentation_mask_rgba, (0, 0, segmentation_mask_rgba.width, segmentation_mask_rgba.height), segmentation_mask_rgba) + + # Save the merged image as PNG + merged_image.save(output_path, format="PNG") @torch.inference_mode() def inference( model: nn.Module, image: torch.Tensor, + inst_map: torch.Tensor, crop_box: np.ndarray, ori_size: tuple, prompt_points: torch.Tensor, @@ -529,12 +596,21 @@ def inference( inds=None, tta=False ): + global IMG_SAVE, MAX_IMG, WHOLE orig_h, orig_w = ori_size # Generate masks for this crop in batches mask_data = MaskData() for (points, labels, cell_types, sub_inds) in batch_iterator(points_per_batch, prompt_points, prompt_labels, prompt_cell_types, inds): + points = points.reshape(1, points.shape[0], 2) + labels = labels.reshape(1, labels.shape[0]) + + # print((f'{image.shape=}')) + # print(f'{points.shape=}') + # print(f'{labels.shape=}') + # print(f'{torch.as_tensor([len(points)]).to(points.device)=}') + outputs = model( image, points, @@ -542,6 +618,8 @@ def inference( torch.as_tensor([len(points)]).to(points.device), ) + # print(f'{outputs["pred_masks"].shape=}') + if tta: # used in FullNet and CDNet points1 = points.clone() @@ -688,6 +766,8 @@ def inference( masks = outputs["pred_masks"] iou_preds = outputs["pred_ious"] + #masks = masks[:1,:,:] + # Serialize predictions and store in MaskData batch_data = MaskData( masks=masks, @@ -703,6 +783,7 @@ def inference( keep_mask = batch_data["iou_preds"] > pred_iou_thresh batch_data.filter(keep_mask) + # Calculate stability score batch_data["stability_score"] = calculate_stability_score( batch_data["masks"], mask_threshold, stability_score_offset @@ -715,11 +796,22 @@ def inference( batch_data["masks"] = batch_data["masks"] > mask_threshold batch_data["boxes"] = batched_mask_to_box(batch_data["masks"]) + # if IMG_SAVE < MAX_IMG: + # # pass + # save_two_masks(inst_map, batch_data["masks"][0], f'results/masks/{IMG_SAVE}.png') + # save_result_as_image(image, outputs["pred_masks"][0], + # f'results/merged/{IMG_SAVE}.png') + # IMG_SAVE = IMG_SAVE + 1 + + #print(f'{keep_mask=}') + # Filter boxes that touch crop boundaries keep_mask = ~is_box_near_crop_edge(batch_data["boxes"], crop_box, [0, 0, orig_w, orig_h], atol=7) # print(keep_mask.shape, batch_data["masks"].shape, batch_data["boxes"].shape) - if not torch.all(keep_mask): - batch_data.filter(keep_mask) + # if not torch.all(keep_mask): + # batch_data.filter(keep_mask) + + #print(f'{keep_mask=}') # Compress to RLE batch_data["masks"] = uncrop_masks(batch_data["masks"], crop_box, orig_h, orig_w) @@ -754,6 +846,12 @@ def inference( mask_data["segmentations"] = [rle_to_mask(rle) for rle in mask_data["rles"]] + for sgm in mask_data["segmentations"]: + if WHOLE < MAX_IMG: + pass + #save_two_masks(inst_map, sgm, f'results/whole/{WHOLE}.png') + WHOLE += 1 + # Write mask records curr_anns = [] for idx in range(len(mask_data["segmentations"])):