Skip to content

Commit

Permalink
Defaults to weights=imagenet if possible (#19)
Browse files Browse the repository at this point in the history
* Nit

* Add pretrained weights

* Fix InceptionV3

* Fix `MobileNet100V3Large`

* Update version
  • Loading branch information
james77777778 authored Jan 20, 2024
1 parent 22136f9 commit b3b8219
Show file tree
Hide file tree
Showing 20 changed files with 483 additions and 136 deletions.
2 changes: 1 addition & 1 deletion kimm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from kimm import models # force to add models to the registry
from kimm.utils.model_registry import list_models

__version__ = "0.1.1"
__version__ = "0.1.2"
3 changes: 1 addition & 2 deletions kimm/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def set_properties(
# feature extractor
self._feature_extractor = kwargs.pop("feature_extractor", False)
self._feature_keys = kwargs.pop("feature_keys", None)
print("self._feature_keys", self._feature_keys)

def determine_input_tensor(
self,
Expand Down Expand Up @@ -208,4 +207,4 @@ def fix_config(self, config: typing.Dict):

@property
def default_origin(self):
return "https://github.com/james77777778/keras-aug/releases/download/v0.5.0"
return "https://github.com/james77777778/kimm/releases/download/0.1.0/"
15 changes: 12 additions & 3 deletions kimm/models/convmixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvMixer736D32",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convmixer736d32_convmixer_768_32.in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
32,
768,
Expand Down Expand Up @@ -188,11 +191,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvMixer1024D20",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convmixer1024d20_convmixer_1024_20_ks9_p14.in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
20,
1024,
Expand Down Expand Up @@ -230,11 +236,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvMixer1536D20",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convmixer1536d20_convmixer_1536_20.in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
20,
1536,
Expand Down
42 changes: 33 additions & 9 deletions kimm/models/convnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvNeXtAtto",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convnextatto_convnext_atto.d2_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
(2, 2, 6, 2),
(40, 80, 160, 320),
Expand Down Expand Up @@ -284,11 +287,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvNeXtFemto",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convnextfemto_convnext_femto.d1_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
(2, 2, 6, 2),
(48, 96, 192, 384),
Expand Down Expand Up @@ -321,11 +327,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvNeXtPico",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convnextpico_convnext_pico.d1_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
(2, 2, 6, 2),
(64, 128, 256, 512),
Expand Down Expand Up @@ -358,11 +367,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvNeXtNano",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convnextnano_convnext_nano.in12k_ft_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
(2, 2, 8, 2),
(80, 160, 320, 640),
Expand Down Expand Up @@ -395,11 +407,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvNeXtTiny",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convnexttiny_convnext_tiny.in12k_ft_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
(3, 3, 9, 3),
(96, 192, 384, 768),
Expand Down Expand Up @@ -432,11 +447,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvNeXtSmall",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convnextsmall_convnext_small.in12k_ft_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
(3, 3, 27, 3),
(96, 192, 384, 768),
Expand Down Expand Up @@ -469,11 +487,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvNeXtBase",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convnextbase_convnext_base.fb_in22k_ft_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
(3, 3, 27, 3),
(128, 256, 512, 1024),
Expand Down Expand Up @@ -506,11 +527,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None,
weights: typing.Optional[str] = "imagenet",
name: str = "ConvNeXtLarge",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "convnextlarge_convnext_large.fb_in22k_ft_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
(3, 3, 27, 3),
(192, 384, 768, 1536),
Expand Down Expand Up @@ -577,4 +601,4 @@ def __init__(
add_model_to_registry(ConvNeXtSmall, "imagenet")
add_model_to_registry(ConvNeXtBase, "imagenet")
add_model_to_registry(ConvNeXtLarge, "imagenet")
add_model_to_registry(ConvNeXtXLarge, "imagenet")
add_model_to_registry(ConvNeXtXLarge)
20 changes: 16 additions & 4 deletions kimm/models/densenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None, # TODO: imagenet
weights: typing.Optional[str] = "imagenet",
name: str = "DenseNet121",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "densenet121_densenet121.ra_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
32,
[6, 12, 24, 16],
Expand Down Expand Up @@ -205,11 +208,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None, # TODO: imagenet
weights: typing.Optional[str] = "imagenet",
name: str = "DenseNet161",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "densenet161_densenet161.tv_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
48,
[6, 12, 36, 24],
Expand Down Expand Up @@ -239,11 +245,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None, # TODO: imagenet
weights: typing.Optional[str] = "imagenet",
name: str = "DenseNet169",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "densenet169_densenet169.tv_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
32,
[6, 12, 32, 32],
Expand Down Expand Up @@ -273,11 +282,14 @@ def __init__(
dropout_rate: float = 0.0,
classes: int = 1000,
classifier_activation: str = "softmax",
weights: typing.Optional[str] = None, # TODO: imagenet
weights: typing.Optional[str] = "imagenet",
name: str = "DenseNet201",
**kwargs,
):
kwargs = self.fix_config(kwargs)
if weights == "imagenet":
file_name = "densenet201_densenet201.tv_in1k.keras"
kwargs["weights_url"] = f"{self.default_origin}/{file_name}"
super().__init__(
32,
[6, 12, 48, 32],
Expand Down
Loading

0 comments on commit b3b8219

Please sign in to comment.