Skip to content

Commit

Permalink
[C] Update for timm registrys
Browse files Browse the repository at this point in the history
  • Loading branch information
kunkunlin1221 committed Dec 23, 2024
1 parent f3caa45 commit 7405a96
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
12 changes: 1 addition & 11 deletions chameleon/modules/backbones/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
from functools import partial

import timm

from ...registry import BACKBONES
from .gpunet import GPUNet

timm_models = timm.list_models()
for name in timm_models:
create_func = partial(timm.create_model, model_name=name)
BACKBONES.register_module(f'timm_{name}', module=create_func)

from .timm import *

__all__ = ['GPUNet']
15 changes: 15 additions & 0 deletions chameleon/modules/backbones/timm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import timm
import torch.nn as nn

from ...registry import BACKBONES


class Timm:
@staticmethod
def build_model(*args, **kwargs) -> nn.Module:
return timm.create_model(*args, **kwargs)


timm_models = timm.list_models()
for name in timm_models:
BACKBONES.register_module(f'timm_{name}', module=Timm.build_model)
1 change: 1 addition & 0 deletions tests/registry/test_root.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import torch
import torch.nn as nn
from torchmetrics.metric import Metric

from chameleon import ASPP, FPN, AdamW, AWingLoss, Conv2dBlock, GPUNet
Expand Down
3 changes: 2 additions & 1 deletion tests/tools/test_calflops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@


def test_calcualte_flops():
model = BACKBONES.build({'name': 'timm_resnet50'})
timm_create = BACKBONES.build({'name': 'timm_resnet50'})
model = timm_create(model_name='resnet50')
flops, macs, params = calculate_flops(model, (1, 3, 224, 224))
assert flops == '8.21 GFLOPS'
assert macs == '4.09 GMACs'
Expand Down

0 comments on commit 7405a96

Please sign in to comment.