Skip to content

Commit 519d358

Browse files
authored
timm upgrade 0.6.12 (qubvel-org#696)
* config: timm version bump 0.4.12 -> 0.6.12 * fix: timm based EfficientNetBaseEncoder after timm upgrade to 0.6.12 EfficientNet act1 layer in timm is merged with bn1 layer after ab49d275de8a9c344aea086fd86d04c4cabb6098 commit * fix: use "public" API for timm models availability check * fix: timm SkNetEncoder after timm upgrade to 0.6.12 `zero_init_last_bn` was renamed to `zero_init_last` in 372ad5fa0dbeb74dcec81db06e9ff69b3d5a2eb6 commit * fix: timm RegNet encoder after timm upgrade to 0.6.12 Instead of plain dict config RegNet uses RegNetCfg dataclass. Dataclasses module were added in Python 3.7, thats why min required Python version for package is also increased. * feat: bump Python version used in Github Actions to 3.7
1 parent fa3ac89 commit 519d358

File tree

9 files changed

+38
-37
lines changed

9 files changed

+38
-37
lines changed

.github/workflows/pypi.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Set up Python
1313
uses: actions/setup-python@v2
1414
with:
15-
python-version: '3.6'
15+
python-version: '3.7'
1616
- name: Install dependencies
1717
run: |
1818
python -m pip install --upgrade pip

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Set up Python ${{ matrix.python-version }}
1919
uses: actions/setup-python@v2
2020
with:
21-
python-version: 3.6
21+
python-version: 3.7
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.black]
22
line-length = 119
3-
target-version = ['py36', 'py37', 'py38']
3+
target-version = ['py37', 'py38']
44
include = '\.pyi?$'
55
exclude = '''
66
/(
@@ -16,4 +16,4 @@ exclude = '''
1616
| build
1717
| dist
1818
)/
19-
'''
19+
'''

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
torchvision>=0.5.0
22
pretrainedmodels==0.7.4
33
efficientnet-pytorch==0.7.1
4-
timm==0.4.12
4+
timm==0.6.12
55

66
tqdm
77
pillow

segmentation_models_pytorch/encoders/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ def get_preprocessing_params(encoder_name, pretrained="imagenet"):
9797

9898
if encoder_name.startswith("tu-"):
9999
encoder_name = encoder_name[3:]
100-
if encoder_name not in timm.models.registry._model_has_pretrained:
100+
if not timm.models.is_model_pretrained(encoder_name):
101101
raise ValueError(f"{encoder_name} does not have pretrained weights and preprocessing parameters")
102-
settings = timm.models.registry._model_default_cfgs[encoder_name]
102+
settings = timm.models.get_pretrained_cfg(encoder_name)
103103
else:
104104
all_settings = encoders[encoder_name]["pretrained_settings"]
105105
if pretrained not in all_settings.keys():

segmentation_models_pytorch/encoders/timm_efficientnet.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __init__(self, stage_idxs, out_channels, depth=5, **kwargs):
105105
def get_stages(self):
106106
return [
107107
nn.Identity(),
108-
nn.Sequential(self.conv_stem, self.bn1, self.act1),
108+
nn.Sequential(self.conv_stem, self.bn1),
109109
self.blocks[: self._stage_idxs[0]],
110110
self.blocks[self._stage_idxs[0] : self._stage_idxs[1]],
111111
self.blocks[self._stage_idxs[1] : self._stage_idxs[2]],

segmentation_models_pytorch/encoders/timm_regnet.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from ._base import EncoderMixin
2-
from timm.models.regnet import RegNet
2+
from timm.models.regnet import RegNet, RegNetCfg
33
import torch.nn as nn
44

55

66
class RegNetEncoder(RegNet, EncoderMixin):
77
def __init__(self, out_channels, depth=5, **kwargs):
8+
kwargs["cfg"] = RegNetCfg(**kwargs["cfg"])
89
super().__init__(**kwargs)
910
self._depth = depth
1011
self._out_channels = out_channels
@@ -141,95 +142,95 @@ def _mcfg(**kwargs):
141142
"pretrained_settings": pretrained_settings["timm-regnetx_002"],
142143
"params": {
143144
"out_channels": (3, 32, 24, 56, 152, 368),
144-
"cfg": _mcfg(w0=24, wa=36.44, wm=2.49, group_w=8, depth=13),
145+
"cfg": _mcfg(w0=24, wa=36.44, wm=2.49, group_size=8, depth=13),
145146
},
146147
},
147148
"timm-regnetx_004": {
148149
"encoder": RegNetEncoder,
149150
"pretrained_settings": pretrained_settings["timm-regnetx_004"],
150151
"params": {
151152
"out_channels": (3, 32, 32, 64, 160, 384),
152-
"cfg": _mcfg(w0=24, wa=24.48, wm=2.54, group_w=16, depth=22),
153+
"cfg": _mcfg(w0=24, wa=24.48, wm=2.54, group_size=16, depth=22),
153154
},
154155
},
155156
"timm-regnetx_006": {
156157
"encoder": RegNetEncoder,
157158
"pretrained_settings": pretrained_settings["timm-regnetx_006"],
158159
"params": {
159160
"out_channels": (3, 32, 48, 96, 240, 528),
160-
"cfg": _mcfg(w0=48, wa=36.97, wm=2.24, group_w=24, depth=16),
161+
"cfg": _mcfg(w0=48, wa=36.97, wm=2.24, group_size=24, depth=16),
161162
},
162163
},
163164
"timm-regnetx_008": {
164165
"encoder": RegNetEncoder,
165166
"pretrained_settings": pretrained_settings["timm-regnetx_008"],
166167
"params": {
167168
"out_channels": (3, 32, 64, 128, 288, 672),
168-
"cfg": _mcfg(w0=56, wa=35.73, wm=2.28, group_w=16, depth=16),
169+
"cfg": _mcfg(w0=56, wa=35.73, wm=2.28, group_size=16, depth=16),
169170
},
170171
},
171172
"timm-regnetx_016": {
172173
"encoder": RegNetEncoder,
173174
"pretrained_settings": pretrained_settings["timm-regnetx_016"],
174175
"params": {
175176
"out_channels": (3, 32, 72, 168, 408, 912),
176-
"cfg": _mcfg(w0=80, wa=34.01, wm=2.25, group_w=24, depth=18),
177+
"cfg": _mcfg(w0=80, wa=34.01, wm=2.25, group_size=24, depth=18),
177178
},
178179
},
179180
"timm-regnetx_032": {
180181
"encoder": RegNetEncoder,
181182
"pretrained_settings": pretrained_settings["timm-regnetx_032"],
182183
"params": {
183184
"out_channels": (3, 32, 96, 192, 432, 1008),
184-
"cfg": _mcfg(w0=88, wa=26.31, wm=2.25, group_w=48, depth=25),
185+
"cfg": _mcfg(w0=88, wa=26.31, wm=2.25, group_size=48, depth=25),
185186
},
186187
},
187188
"timm-regnetx_040": {
188189
"encoder": RegNetEncoder,
189190
"pretrained_settings": pretrained_settings["timm-regnetx_040"],
190191
"params": {
191192
"out_channels": (3, 32, 80, 240, 560, 1360),
192-
"cfg": _mcfg(w0=96, wa=38.65, wm=2.43, group_w=40, depth=23),
193+
"cfg": _mcfg(w0=96, wa=38.65, wm=2.43, group_size=40, depth=23),
193194
},
194195
},
195196
"timm-regnetx_064": {
196197
"encoder": RegNetEncoder,
197198
"pretrained_settings": pretrained_settings["timm-regnetx_064"],
198199
"params": {
199200
"out_channels": (3, 32, 168, 392, 784, 1624),
200-
"cfg": _mcfg(w0=184, wa=60.83, wm=2.07, group_w=56, depth=17),
201+
"cfg": _mcfg(w0=184, wa=60.83, wm=2.07, group_size=56, depth=17),
201202
},
202203
},
203204
"timm-regnetx_080": {
204205
"encoder": RegNetEncoder,
205206
"pretrained_settings": pretrained_settings["timm-regnetx_080"],
206207
"params": {
207208
"out_channels": (3, 32, 80, 240, 720, 1920),
208-
"cfg": _mcfg(w0=80, wa=49.56, wm=2.88, group_w=120, depth=23),
209+
"cfg": _mcfg(w0=80, wa=49.56, wm=2.88, group_size=120, depth=23),
209210
},
210211
},
211212
"timm-regnetx_120": {
212213
"encoder": RegNetEncoder,
213214
"pretrained_settings": pretrained_settings["timm-regnetx_120"],
214215
"params": {
215216
"out_channels": (3, 32, 224, 448, 896, 2240),
216-
"cfg": _mcfg(w0=168, wa=73.36, wm=2.37, group_w=112, depth=19),
217+
"cfg": _mcfg(w0=168, wa=73.36, wm=2.37, group_size=112, depth=19),
217218
},
218219
},
219220
"timm-regnetx_160": {
220221
"encoder": RegNetEncoder,
221222
"pretrained_settings": pretrained_settings["timm-regnetx_160"],
222223
"params": {
223224
"out_channels": (3, 32, 256, 512, 896, 2048),
224-
"cfg": _mcfg(w0=216, wa=55.59, wm=2.1, group_w=128, depth=22),
225+
"cfg": _mcfg(w0=216, wa=55.59, wm=2.1, group_size=128, depth=22),
225226
},
226227
},
227228
"timm-regnetx_320": {
228229
"encoder": RegNetEncoder,
229230
"pretrained_settings": pretrained_settings["timm-regnetx_320"],
230231
"params": {
231232
"out_channels": (3, 32, 336, 672, 1344, 2520),
232-
"cfg": _mcfg(w0=320, wa=69.86, wm=2.0, group_w=168, depth=23),
233+
"cfg": _mcfg(w0=320, wa=69.86, wm=2.0, group_size=168, depth=23),
233234
},
234235
},
235236
# regnety
@@ -238,95 +239,95 @@ def _mcfg(**kwargs):
238239
"pretrained_settings": pretrained_settings["timm-regnety_002"],
239240
"params": {
240241
"out_channels": (3, 32, 24, 56, 152, 368),
241-
"cfg": _mcfg(w0=24, wa=36.44, wm=2.49, group_w=8, depth=13, se_ratio=0.25),
242+
"cfg": _mcfg(w0=24, wa=36.44, wm=2.49, group_size=8, depth=13, se_ratio=0.25),
242243
},
243244
},
244245
"timm-regnety_004": {
245246
"encoder": RegNetEncoder,
246247
"pretrained_settings": pretrained_settings["timm-regnety_004"],
247248
"params": {
248249
"out_channels": (3, 32, 48, 104, 208, 440),
249-
"cfg": _mcfg(w0=48, wa=27.89, wm=2.09, group_w=8, depth=16, se_ratio=0.25),
250+
"cfg": _mcfg(w0=48, wa=27.89, wm=2.09, group_size=8, depth=16, se_ratio=0.25),
250251
},
251252
},
252253
"timm-regnety_006": {
253254
"encoder": RegNetEncoder,
254255
"pretrained_settings": pretrained_settings["timm-regnety_006"],
255256
"params": {
256257
"out_channels": (3, 32, 48, 112, 256, 608),
257-
"cfg": _mcfg(w0=48, wa=32.54, wm=2.32, group_w=16, depth=15, se_ratio=0.25),
258+
"cfg": _mcfg(w0=48, wa=32.54, wm=2.32, group_size=16, depth=15, se_ratio=0.25),
258259
},
259260
},
260261
"timm-regnety_008": {
261262
"encoder": RegNetEncoder,
262263
"pretrained_settings": pretrained_settings["timm-regnety_008"],
263264
"params": {
264265
"out_channels": (3, 32, 64, 128, 320, 768),
265-
"cfg": _mcfg(w0=56, wa=38.84, wm=2.4, group_w=16, depth=14, se_ratio=0.25),
266+
"cfg": _mcfg(w0=56, wa=38.84, wm=2.4, group_size=16, depth=14, se_ratio=0.25),
266267
},
267268
},
268269
"timm-regnety_016": {
269270
"encoder": RegNetEncoder,
270271
"pretrained_settings": pretrained_settings["timm-regnety_016"],
271272
"params": {
272273
"out_channels": (3, 32, 48, 120, 336, 888),
273-
"cfg": _mcfg(w0=48, wa=20.71, wm=2.65, group_w=24, depth=27, se_ratio=0.25),
274+
"cfg": _mcfg(w0=48, wa=20.71, wm=2.65, group_size=24, depth=27, se_ratio=0.25),
274275
},
275276
},
276277
"timm-regnety_032": {
277278
"encoder": RegNetEncoder,
278279
"pretrained_settings": pretrained_settings["timm-regnety_032"],
279280
"params": {
280281
"out_channels": (3, 32, 72, 216, 576, 1512),
281-
"cfg": _mcfg(w0=80, wa=42.63, wm=2.66, group_w=24, depth=21, se_ratio=0.25),
282+
"cfg": _mcfg(w0=80, wa=42.63, wm=2.66, group_size=24, depth=21, se_ratio=0.25),
282283
},
283284
},
284285
"timm-regnety_040": {
285286
"encoder": RegNetEncoder,
286287
"pretrained_settings": pretrained_settings["timm-regnety_040"],
287288
"params": {
288289
"out_channels": (3, 32, 128, 192, 512, 1088),
289-
"cfg": _mcfg(w0=96, wa=31.41, wm=2.24, group_w=64, depth=22, se_ratio=0.25),
290+
"cfg": _mcfg(w0=96, wa=31.41, wm=2.24, group_size=64, depth=22, se_ratio=0.25),
290291
},
291292
},
292293
"timm-regnety_064": {
293294
"encoder": RegNetEncoder,
294295
"pretrained_settings": pretrained_settings["timm-regnety_064"],
295296
"params": {
296297
"out_channels": (3, 32, 144, 288, 576, 1296),
297-
"cfg": _mcfg(w0=112, wa=33.22, wm=2.27, group_w=72, depth=25, se_ratio=0.25),
298+
"cfg": _mcfg(w0=112, wa=33.22, wm=2.27, group_size=72, depth=25, se_ratio=0.25),
298299
},
299300
},
300301
"timm-regnety_080": {
301302
"encoder": RegNetEncoder,
302303
"pretrained_settings": pretrained_settings["timm-regnety_080"],
303304
"params": {
304305
"out_channels": (3, 32, 168, 448, 896, 2016),
305-
"cfg": _mcfg(w0=192, wa=76.82, wm=2.19, group_w=56, depth=17, se_ratio=0.25),
306+
"cfg": _mcfg(w0=192, wa=76.82, wm=2.19, group_size=56, depth=17, se_ratio=0.25),
306307
},
307308
},
308309
"timm-regnety_120": {
309310
"encoder": RegNetEncoder,
310311
"pretrained_settings": pretrained_settings["timm-regnety_120"],
311312
"params": {
312313
"out_channels": (3, 32, 224, 448, 896, 2240),
313-
"cfg": _mcfg(w0=168, wa=73.36, wm=2.37, group_w=112, depth=19, se_ratio=0.25),
314+
"cfg": _mcfg(w0=168, wa=73.36, wm=2.37, group_size=112, depth=19, se_ratio=0.25),
314315
},
315316
},
316317
"timm-regnety_160": {
317318
"encoder": RegNetEncoder,
318319
"pretrained_settings": pretrained_settings["timm-regnety_160"],
319320
"params": {
320321
"out_channels": (3, 32, 224, 448, 1232, 3024),
321-
"cfg": _mcfg(w0=200, wa=106.23, wm=2.48, group_w=112, depth=18, se_ratio=0.25),
322+
"cfg": _mcfg(w0=200, wa=106.23, wm=2.48, group_size=112, depth=18, se_ratio=0.25),
322323
},
323324
},
324325
"timm-regnety_320": {
325326
"encoder": RegNetEncoder,
326327
"pretrained_settings": pretrained_settings["timm-regnety_320"],
327328
"params": {
328329
"out_channels": (3, 32, 232, 696, 1392, 3712),
329-
"cfg": _mcfg(w0=232, wa=115.89, wm=2.53, group_w=232, depth=20, se_ratio=0.25),
330+
"cfg": _mcfg(w0=232, wa=115.89, wm=2.53, group_size=232, depth=20, se_ratio=0.25),
330331
},
331332
},
332333
}

segmentation_models_pytorch/encoders/timm_sknet.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def load_state_dict(self, state_dict, **kwargs):
7373
"out_channels": (3, 64, 64, 128, 256, 512),
7474
"block": SelectiveKernelBasic,
7575
"layers": [2, 2, 2, 2],
76-
"zero_init_last_bn": False,
76+
"zero_init_last": False,
7777
"block_args": {"sk_kwargs": {"rd_ratio": 1 / 8, "split_input": True}},
7878
},
7979
},
@@ -84,7 +84,7 @@ def load_state_dict(self, state_dict, **kwargs):
8484
"out_channels": (3, 64, 64, 128, 256, 512),
8585
"block": SelectiveKernelBasic,
8686
"layers": [3, 4, 6, 3],
87-
"zero_init_last_bn": False,
87+
"zero_init_last": False,
8888
"block_args": {"sk_kwargs": {"rd_ratio": 1 / 8, "split_input": True}},
8989
},
9090
},
@@ -95,7 +95,7 @@ def load_state_dict(self, state_dict, **kwargs):
9595
"out_channels": (3, 64, 256, 512, 1024, 2048),
9696
"block": SelectiveKernelBottleneck,
9797
"layers": [3, 4, 6, 3],
98-
"zero_init_last_bn": False,
98+
"zero_init_last": False,
9999
"cardinality": 32,
100100
"base_width": 4,
101101
},

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
URL = "https://github.com/qubvel/segmentation_models.pytorch"
1818
1919
AUTHOR = "Pavel Iakubovskii"
20-
REQUIRES_PYTHON = ">=3.6.0"
20+
REQUIRES_PYTHON = ">=3.7.0"
2121
VERSION = None
2222

2323
# The rest you shouldn't have to touch too much :)

0 commit comments

Comments
 (0)