Skip to content

Commit

Permalink
some debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
NoamRosenberg committed Aug 14, 2019
1 parent f03f7ea commit 2317ff4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
26 changes: 13 additions & 13 deletions new_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ def __init__(self, network_arch, cell_arch, num_classes, num_layers, criterion =
nn.ReLU ()
)
#C_prev_prev = 64
initial_fm = C_initial / self._block_multiplier
initial_fm = int(C_initial / self._block_multiplier)
filter_param_dict = {0: 1, 1: 2, 2: 4, 3: 8}
for i in range (self._num_layers) :
if i==0:
level_option = torch.sum(self.network_arch[0], dim=1)
level = torch.argmax(level_option).item()

three_branch_options = torch.sum(network_arch[i], dim=0)
three_branch_options = torch.sum(self.network_arch[i], dim=0)
downup_sample = torch.argmax(three_branch_options).item() - 1

_cell = cell (self._step, self._block_multiplier, -1,
Expand All @@ -125,14 +125,14 @@ def __init__(self, network_arch, cell_arch, num_classes, num_layers, criterion =


elif i==1:
level_option = torch.sum(network_arch[i], dim=1)
prev_level_option = torch.sum(network_arch[i-1], dim=1)
level_option = torch.sum(self.network_arch[i], dim=1)
prev_level_option = torch.sum(self.network_arch[i-1], dim=1)
level = torch.argmax(level_option).item()
prev_level = torch.argmax(prev_level_option).item()

three_branch_options = torch.sum(network_arch[i], dim=0)
three_branch_options = torch.sum(self.network_arch[i], dim=0)
downup_sample = torch.argmax(three_branch_options).item() - 1
prev_three_branch_options = torch.sum(network_arch[i-1], dim=0)
prev_three_branch_options = torch.sum(self.network_arch[i-1], dim=0)
prev_downup_sample = torch.argmax(prev_three_branch_options).item() - 1
total_downup = prev_downup_sample + downup_sample

Expand All @@ -144,16 +144,16 @@ def __init__(self, network_arch, cell_arch, num_classes, num_layers, criterion =


else:
level_option = torch.sum(network_arch[i], dim=1)
prev_level_option = torch.sum(network_arch[i-1], dim=1)
prev_prev_level_option = torch.sum(network_arch[i-2], dim=1)
level_option = torch.sum(self.network_arch[i], dim=1)
prev_level_option = torch.sum(self.network_arch[i-1], dim=1)
prev_prev_level_option = torch.sum(self.network_arch[i-2], dim=1)
level = torch.argmax(level_option).item()
prev_level = torch.argmax(prev_level_option).item()
prev_prev_level = torch.argmax(prev_prev_level_option).item()

three_branch_options = torch.sum(network_arch[i], dim=0)
three_branch_options = torch.sum(self.network_arch[i], dim=0)
downup_sample = torch.argmax(three_branch_options).item() - 1
prev_three_branch_options = torch.sum(network_arch[i-1], dim=0)
prev_three_branch_options = torch.sum(self.network_arch[i-1], dim=0)
prev_downup_sample = torch.argmax(prev_three_branch_options).item() - 1
total_downup = prev_downup_sample + downup_sample

Expand All @@ -165,7 +165,7 @@ def __init__(self, network_arch, cell_arch, num_classes, num_layers, criterion =

self.cells += [_cell]

last_level_option = torch.sum(network_arch[-1], dim=1)
last_level_option = torch.sum(self.network_arch[-1], dim=1)
last_level = torch.argmax(last_level_option).item()
aspp_num_input_channels = self._block_multiplier * self._filter_multiplier * filter_param_dict[last_level]
atrous_rate = 96 / (filter_param_dict[last_level] * 4)
Expand All @@ -178,7 +178,7 @@ def forward(self, x):
x = self.stem2 (x)
two_last_inputs = (None, x)
for i in range(self._num_layers):
two_last_inputs = self.cells[i](two_last_inputs[0], self.two_last_inputs[1])
two_last_inputs = self.cells[i](two_last_inputs[0], two_last_inputs[1])

last_input = two_last_inputs[-1]
aspp_result = self.aspp(last_input)
Expand Down
19 changes: 11 additions & 8 deletions train_new_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ def __init__(self, args):
# sync_bn=args.sync_bn,
# freeze_bn=args.freeze_bn)
# TODO: look into these

train_params = [{'params': model.get_1x_lr_params(), 'lr': args.lr},
{'params': model.get_10x_lr_params(), 'lr': args.lr * 10}]

# TODO: ALSO look into different param groups as done int deeplab below
# train_params = [{'params': model.get_1x_lr_params(), 'lr': args.lr},
# {'params': model.get_10x_lr_params(), 'lr': args.lr * 10}]
#
train_params = [{'params': model.parameters(), 'lr': args.lr}]
# Define Optimizer
optimizer = torch.optim.SGD(train_params, momentum=args.momentum,
weight_decay=args.weight_decay, nesterov=args.nesterov)
Expand All @@ -71,7 +72,7 @@ def __init__(self, args):
self.evaluator = Evaluator(self.nclass)
# Define lr scheduler
self.scheduler = LR_Scheduler(args.lr_scheduler, args.lr,
args.epochs, len(self.train_loader))
args.epochs, len(self.train_loader)) #TODO: use min_lr ?

# TODO: Figure out if len(self.train_loader) should be devided by two ? in other module as well
# Using cuda
Expand Down Expand Up @@ -214,10 +215,10 @@ def main():
help='whether to use SBD dataset (default: True)')
parser.add_argument('--workers', type=int, default=4,
metavar='N', help='dataloader threads')
parser.add_argument('--base-size', type=int, default=513,
help='base image size')
parser.add_argument('--crop-size', type=int, default=513,
parser.add_argument('--crop_size', type=int, default=320,
help='crop image size')
parser.add_argument('--resize', type=int, default=512,
help='resize image size')
parser.add_argument('--sync-bn', type=bool, default=None,
help='whether to use sync bn (default: auto)')
parser.add_argument('--freeze-bn', type=bool, default=False,
Expand Down Expand Up @@ -276,6 +277,8 @@ def main():
parser.add_argument('--filter_multiplier', type=int, default=20)
parser.add_argument('--autodeeplab', type=str, default='train',
choices=['search', 'train'])
parser.add_argument('--load-parallel', type=int, default=0)
parser.add_argument('--min_lr', type=float, default=0.001) #TODO: CHECK THAT THEY EVEN DO THIS FOR THE MODEL IN THE PAPER

args = parser.parse_args()
args.cuda = not args.no_cuda and torch.cuda.is_available()
Expand Down
5 changes: 3 additions & 2 deletions utils/lr_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def __call__(self, optimizer, i, epoch, best_pred):
else:
raise NotImplemented
# warm up lr schedule
if lr < self.min_lr:
lr = self.min_lr
if self.min_lr is not None:
if lr < self.min_lr:
lr = self.min_lr
if self.warmup_iters > 0 and T < self.warmup_iters:
lr = lr * 1.0 * T / self.warmup_iters
if epoch > self.epoch:
Expand Down
2 changes: 1 addition & 1 deletion utils/saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def save_experiment_config(self):
p['lr_scheduler'] = self.args.lr_scheduler
p['loss_type'] = self.args.loss_type
p['epoch'] = self.args.epochs
p['base_size'] = self.args.base_size
p['resize'] = self.args.resize
p['crop_size'] = self.args.crop_size

for key, val in p.items():
Expand Down

0 comments on commit 2317ff4

Please sign in to comment.