From d99d0c29a906f10d663b844d1e4398cfc91e860e Mon Sep 17 00:00:00 2001 From: pnorridge <37704783+pnorridge@users.noreply.github.com> Date: Wed, 26 Jan 2022 17:47:59 +0000 Subject: [PATCH 1/3] Update train_classification.py Loading pre-trained weights did not overwrite the existing weight set. --- train_classification.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train_classification.py b/train_classification.py index a41f0a8..b014258 100644 --- a/train_classification.py +++ b/train_classification.py @@ -44,7 +44,7 @@ def main(args): print_info_message('Loading pretrained basenet model weights') model_dict = model.state_dict() - overlap_dict = {k: v for k, v in model_dict.items() if k in pretrained_dict} + overlap_dict = {k: v for k, v in pretrained_dict if k in model_dict.items()} total_size_overlap = 0 for k, v in enumerate(overlap_dict): From 9c2613c00dda5859edda49954814eecf86392158 Mon Sep 17 00:00:00 2001 From: pnorridge <37704783+pnorridge@users.noreply.github.com> Date: Sat, 29 Jan 2022 14:58:00 +0000 Subject: [PATCH 2/3] Fix for different input channel count Updated to ensure that different numbers of input channels can be handled without error. (Shortcut connection configuration assumed this was always equal to config_inp_reinf.) --- model/classification/espnetv2.py | 8 ++++---- nn_layers/eesp.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/model/classification/espnetv2.py b/model/classification/espnetv2.py index 41b51c9..af76135 100644 --- a/model/classification/espnetv2.py +++ b/model/classification/espnetv2.py @@ -57,19 +57,19 @@ def __init__(self, args): self.level1 = CBR(channels_in, out_channel_map[0], 3, 2) # 112 L1 - self.level2_0 = DownSampler(out_channel_map[0], out_channel_map[1], k=K[0], r_lim=recept_limit[0], reinf=self.input_reinforcement) # out = 56 + self.level2_0 = DownSampler(out_channel_map[0], out_channel_map[1], input2_nin=channels_in, k=K[0], r_lim=recept_limit[0], reinf=self.input_reinforcement) # out = 56 - self.level3_0 = DownSampler(out_channel_map[1], out_channel_map[2], k=K[1], r_lim=recept_limit[1], reinf=self.input_reinforcement) # out = 28 + self.level3_0 = DownSampler(out_channel_map[1], out_channel_map[2], input2_nin=channels_in, k=K[1], r_lim=recept_limit[1], reinf=self.input_reinforcement) # out = 28 self.level3 = nn.ModuleList() for i in range(reps_at_each_level[1]): self.level3.append(EESP(out_channel_map[2], out_channel_map[2], stride=1, k=K[2], r_lim=recept_limit[2])) - self.level4_0 = DownSampler(out_channel_map[2], out_channel_map[3], k=K[2], r_lim=recept_limit[2], reinf=self.input_reinforcement) #out = 14 + self.level4_0 = DownSampler(out_channel_map[2], out_channel_map[3], input2_nin=channels_in, k=K[2], r_lim=recept_limit[2], reinf=self.input_reinforcement) #out = 14 self.level4 = nn.ModuleList() for i in range(reps_at_each_level[2]): self.level4.append(EESP(out_channel_map[3], out_channel_map[3], stride=1, k=K[3], r_lim=recept_limit[3])) - self.level5_0 = DownSampler(out_channel_map[3], out_channel_map[4], k=K[3], r_lim=recept_limit[3]) #7 + self.level5_0 = DownSampler(out_channel_map[3], out_channel_map[4], input2_nin=channels_in, k=K[3], r_lim=recept_limit[3]) #7 self.level5 = nn.ModuleList() for i in range(reps_at_each_level[3]): self.level5.append(EESP(out_channel_map[4], out_channel_map[4], stride=1, k=K[4], r_lim=recept_limit[4])) diff --git a/nn_layers/eesp.py b/nn_layers/eesp.py index 064b5f9..8c268dd 100644 --- a/nn_layers/eesp.py +++ b/nn_layers/eesp.py @@ -101,7 +101,7 @@ class DownSampler(nn.Module): the final output. ''' - def __init__(self, nin, nout, k=4, r_lim=9, reinf=True): + def __init__(self, nin, nout, input2_nin=config_inp_reinf, k=4, r_lim=9, reinf=True): ''' :param nin: number of input channels :param nout: number of output channels @@ -115,7 +115,7 @@ def __init__(self, nin, nout, k=4, r_lim=9, reinf=True): self.avg = nn.AvgPool2d(kernel_size=3, padding=1, stride=2) if reinf: self.inp_reinf = nn.Sequential( - CBR(config_inp_reinf, config_inp_reinf, 3, 1), + CBR(input2_nin, config_inp_reinf, 3, 1), CB(config_inp_reinf, nout, 1, 1) ) self.act = nn.PReLU(nout) From 4e400d9483d4d0420da291c66946df7b233e7471 Mon Sep 17 00:00:00 2001 From: pnorridge <37704783+pnorridge@users.noreply.github.com> Date: Sat, 29 Jan 2022 16:03:16 +0000 Subject: [PATCH 3/3] Revert "Fix for different input channel count" This reverts commit 9c2613c00dda5859edda49954814eecf86392158. --- model/classification/espnetv2.py | 8 ++++---- nn_layers/eesp.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/model/classification/espnetv2.py b/model/classification/espnetv2.py index af76135..41b51c9 100644 --- a/model/classification/espnetv2.py +++ b/model/classification/espnetv2.py @@ -57,19 +57,19 @@ def __init__(self, args): self.level1 = CBR(channels_in, out_channel_map[0], 3, 2) # 112 L1 - self.level2_0 = DownSampler(out_channel_map[0], out_channel_map[1], input2_nin=channels_in, k=K[0], r_lim=recept_limit[0], reinf=self.input_reinforcement) # out = 56 + self.level2_0 = DownSampler(out_channel_map[0], out_channel_map[1], k=K[0], r_lim=recept_limit[0], reinf=self.input_reinforcement) # out = 56 - self.level3_0 = DownSampler(out_channel_map[1], out_channel_map[2], input2_nin=channels_in, k=K[1], r_lim=recept_limit[1], reinf=self.input_reinforcement) # out = 28 + self.level3_0 = DownSampler(out_channel_map[1], out_channel_map[2], k=K[1], r_lim=recept_limit[1], reinf=self.input_reinforcement) # out = 28 self.level3 = nn.ModuleList() for i in range(reps_at_each_level[1]): self.level3.append(EESP(out_channel_map[2], out_channel_map[2], stride=1, k=K[2], r_lim=recept_limit[2])) - self.level4_0 = DownSampler(out_channel_map[2], out_channel_map[3], input2_nin=channels_in, k=K[2], r_lim=recept_limit[2], reinf=self.input_reinforcement) #out = 14 + self.level4_0 = DownSampler(out_channel_map[2], out_channel_map[3], k=K[2], r_lim=recept_limit[2], reinf=self.input_reinforcement) #out = 14 self.level4 = nn.ModuleList() for i in range(reps_at_each_level[2]): self.level4.append(EESP(out_channel_map[3], out_channel_map[3], stride=1, k=K[3], r_lim=recept_limit[3])) - self.level5_0 = DownSampler(out_channel_map[3], out_channel_map[4], input2_nin=channels_in, k=K[3], r_lim=recept_limit[3]) #7 + self.level5_0 = DownSampler(out_channel_map[3], out_channel_map[4], k=K[3], r_lim=recept_limit[3]) #7 self.level5 = nn.ModuleList() for i in range(reps_at_each_level[3]): self.level5.append(EESP(out_channel_map[4], out_channel_map[4], stride=1, k=K[4], r_lim=recept_limit[4])) diff --git a/nn_layers/eesp.py b/nn_layers/eesp.py index 8c268dd..064b5f9 100644 --- a/nn_layers/eesp.py +++ b/nn_layers/eesp.py @@ -101,7 +101,7 @@ class DownSampler(nn.Module): the final output. ''' - def __init__(self, nin, nout, input2_nin=config_inp_reinf, k=4, r_lim=9, reinf=True): + def __init__(self, nin, nout, k=4, r_lim=9, reinf=True): ''' :param nin: number of input channels :param nout: number of output channels @@ -115,7 +115,7 @@ def __init__(self, nin, nout, input2_nin=config_inp_reinf, k=4, r_lim=9, reinf=T self.avg = nn.AvgPool2d(kernel_size=3, padding=1, stride=2) if reinf: self.inp_reinf = nn.Sequential( - CBR(input2_nin, config_inp_reinf, 3, 1), + CBR(config_inp_reinf, config_inp_reinf, 3, 1), CB(config_inp_reinf, nout, 1, 1) ) self.act = nn.PReLU(nout)