From 9902face76d7099d64d61f90433842dce1f87d0b Mon Sep 17 00:00:00 2001 From: MarkoHaralovic <104767429+MarkoHaralovic@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:40:18 +0200 Subject: [PATCH] Added dockerfile, registered smaller ConvNeXt-V2 models, added default HP values for the smaller, newly registerd models. --- .dockerignore | 8 +++++ Dockerfile | 12 +++++++ downstream_imagenet/arg.py | 5 +++ .../models/convnext_official.py | 36 +++++++++++++++++++ pretrain/models/convnext.py | 21 +++++++++-- pretrain/requirements.txt | 1 + 6 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6e969d2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +*.swp +**/__pycache__/** +.idea/* +ckpt/ +*.pth +*.log +*.txt +.dockerignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f929e6f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM pytorch/pytorch:1.10.0-cuda11.3-cudnn8-devel + +WORKDIR / + +RUN pip install timm==0.5.4 + +COPY /pretrain/requirements.txt / +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["bash"] diff --git a/downstream_imagenet/arg.py b/downstream_imagenet/arg.py index a7435bf..956b63a 100644 --- a/downstream_imagenet/arg.py +++ b/downstream_imagenet/arg.py @@ -12,6 +12,11 @@ HP_DEFAULT_NAMES = ['bs', 'ep', 'wp_ep', 'opt', 'base_lr', 'lr_scale', 'wd', 'mixup', 'rep_aug', 'drop_path', 'ema'] HP_DEFAULT_VALUES = { + 'convnext_atto': (1024, 400, 20, 'adam', 0.0002, 0.7, 0.01, 0.8, 3, 0.3, 0.9999), + 'convnext_femto': (1024, 400, 20, 'adam', 0.0002, 0.7, 0.01, 0.8, 3, 0.3, 0.9999), + 'convnext_pico': (512, 400, 20, 'adam', 0.0002, 0.7, 0.01, 0.8, 3, 0.3, 0.9999), + 'convnext_nano': (512, 400, 20, 'adam', 0.0002, 0.7, 0.01, 0.8, 3, 0.3, 0.9999), + 'convnext_tiny': (256, 400, 20, 'adam', 0.0002, 0.7, 0.01, 0.8, 3, 0.3, 0.9999), 'convnext_small': (4096, 400, 20, 'adam', 0.0002, 0.7, 0.01, 0.8, 3, 0.3, 0.9999), 'convnext_base': (4096, 400, 20, 'adam', 0.0001, 0.7, 0.01, 0.8, 3, 0.4, 0.9999), 'convnext_large': (4096, 200, 10, 'adam', 0.0001, 0.7, 0.02, 0.8, 3, 0.5, 0.9999), diff --git a/downstream_imagenet/models/convnext_official.py b/downstream_imagenet/models/convnext_official.py index 2f47c48..f5f6034 100644 --- a/downstream_imagenet/models/convnext_official.py +++ b/downstream_imagenet/models/convnext_official.py @@ -154,6 +154,42 @@ def forward(self, x): "convnext_xlarge_22k": "https://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_224.pth", } +@register_model +def convnext_atto(pretrained=False,in_22k=False, **kwargs): + model = ConvNeXt(depths=[2, 2, 6, 2], dims=[40, 80, 160, 320], **kwargs) + if pretrained: + url = model_urls['convnext_atto_22k'] if in_22k else model_urls['convnext_atto_1k'] + checkpoint = torch.hub.load_state_dict_from_url(url=url, map_location="cpu", check_hash=True) + model.load_state_dict(checkpoint["model"]) + return model + +@register_model +def convnext_femto(pretrained=False,in_22k=False, **kwargs): + model = ConvNeXt(depths=[2, 2, 6, 2], dims=[48, 96, 192, 384], **kwargs) + if pretrained: + url = model_urls['convnext_femto_22k'] if in_22k else model_urls['convnext_femto_1k'] + checkpoint = torch.hub.load_state_dict_from_url(url=url, map_location="cpu", check_hash=True) + model.load_state_dict(checkpoint["model"]) + return model + +@register_model +def convnext_pico(pretrained=False,in_22k=False, **kwargs): + model = ConvNeXt(depths=[2, 2, 6, 2], dims=[64, 128, 256, 512], **kwargs) + if pretrained: + url = model_urls['convnext_pico_22k'] if in_22k else model_urls['convnext_pico_1k'] + checkpoint = torch.hub.load_state_dict_from_url(url=url, map_location="cpu", check_hash=True) + model.load_state_dict(checkpoint["model"]) + return model + +@register_model +def convnext_nano(pretrained=False,in_22k=False, **kwargs): + model = ConvNeXt(depths=[2, 2, 8, 2], dims=[80, 160, 320, 640], **kwargs) + if pretrained: + url = model_urls['convnext_nano_22k'] if in_22k else model_urls['convnext_nano_1k'] + checkpoint = torch.hub.load_state_dict_from_url(url=url, map_location="cpu", check_hash=True) + model.load_state_dict(checkpoint["model"]) + return model + @register_model def convnext_tiny(pretrained=False,in_22k=False, **kwargs): model = ConvNeXt(depths=[3, 3, 9, 3], dims=[96, 192, 384, 768], **kwargs) diff --git a/pretrain/models/convnext.py b/pretrain/models/convnext.py index 6b0169e..acb2c74 100644 --- a/pretrain/models/convnext.py +++ b/pretrain/models/convnext.py @@ -99,12 +99,29 @@ def get_classifier(self): def extra_repr(self): return f'drop_path_rate={self.drop_path_rate}, layer_scale_init_value={self.layer_scale_init_value:g}' +@register_model +def convnext_atto(pretrained=False,in_22k=False, **kwargs): + model = ConvNeXt(depths=[2, 2, 6, 2], dims=[40, 80, 160, 320], **kwargs) + return model @register_model -def convnext_tiny(pretrained=False, in_22k=False, **kwargs): - model = ConvNeXt(depths=[3, 3, 9, 3], dims=[96, 192, 384, 768], **kwargs) +def convnext_femto(pretrained=False,in_22k=False, **kwargs): + model = ConvNeXt(depths=[2, 2, 6, 2], dims=[48, 96, 192, 384], **kwargs) return model +@register_model +def convnext_pico(pretrained=False,in_22k=False, **kwargs): + model = ConvNeXt(depths=[2, 2, 6, 2], dims=[64, 128, 256, 512], **kwargs) + +@register_model +def convnext_nano(pretrained=False,in_22k=False, **kwargs): + model = ConvNeXt(depths=[2, 2, 8, 2], dims=[80, 160, 320, 640], **kwargs) + return model + +@register_model +def convnext_tiny(pretrained=False,in_22k=False, **kwargs): + model = ConvNeXt(depths=[3, 3, 9, 3], dims=[96, 192, 384, 768], **kwargs) + return model @register_model def convnext_small(pretrained=False, in_22k=False, **kwargs): diff --git a/pretrain/requirements.txt b/pretrain/requirements.txt index 896e276..2ab13f8 100644 --- a/pretrain/requirements.txt +++ b/pretrain/requirements.txt @@ -4,3 +4,4 @@ Pillow typed-argument-parser timm==0.5.4 tensorboardx +tensorboard \ No newline at end of file