Coverage for src/deepdraw/configs/models/m2unet.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-11-30 15:00 +0100

1# SPDX-FileCopyrightText: Copyright © 2023 Idiap Research Institute <contact@idiap.ch> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4 

5"""MobileNetV2 U-Net model for image segmentation. 

6 

7The MobileNetV2 architecture is based on an inverted residual structure where 

8the input and output of the residual block are thin bottleneck layers opposite 

9to traditional residual models which use expanded representations in the input 

10an MobileNetV2 uses lightweight depthwise convolutions to filter features in 

11the intermediate expansion layer. This model implements a MobileNetV2 U-Net 

12model, henceforth named M2U-Net, combining the strenghts of U-Net for medical 

13segmentation applications and the speed of MobileNetV2 networks. 

14 

15References: [SANDLER-2018]_, [RONNEBERGER-2015]_ 

16""" 

17 

18from torch.optim.lr_scheduler import MultiStepLR 

19 

20from deepdraw.engine.adabound import AdaBound 

21from deepdraw.models.losses import SoftJaccardBCELogitsLoss 

22from deepdraw.models.m2unet import m2unet 

23 

24# config 

25lr = 0.001 

26betas = (0.9, 0.999) 

27eps = 1e-08 

28weight_decay = 0 

29final_lr = 0.1 

30gamma = 1e-3 

31eps = 1e-8 

32amsbound = False 

33 

34scheduler_milestones = [900] 

35scheduler_gamma = 0.1 

36 

37model = m2unet() 

38 

39# optimizer 

40optimizer = AdaBound( 

41 model.parameters(), 

42 lr=lr, 

43 betas=betas, 

44 final_lr=final_lr, 

45 gamma=gamma, 

46 eps=eps, 

47 weight_decay=weight_decay, 

48 amsbound=amsbound, 

49) 

50 

51# criterion 

52criterion = SoftJaccardBCELogitsLoss(alpha=0.7) 

53 

54# scheduler 

55scheduler = MultiStepLR( 

56 optimizer, milestones=scheduler_milestones, gamma=scheduler_gamma 

57)