Ejemplo n.º 1
0
if opt.PCB and (opt.LSTM or opt.GGNN):
    model_name = 'PCB-128_dim_cls'
    model = load_network(model, model_name)
    model = PCB_Effi_LSTM(model) if opt.LSTM else PCB_Effi_GGNN(model)
    # model_name = 'LSTM' or 'GGNN'
    # model = load_network(model, model_name)

print(model)

if not opt.multi_loss:
    ignored_params = list(map(id, model.model._fc.parameters()))
    ignored_params += (list(map(id, model.classifier.parameters())) +
                       list(map(id, model.model.parameters())))
    base_params = filter(lambda p: id(p) not in ignored_params,
                         model.parameters())
    optimizer_ft = optim.SGD([{
        'params': base_params,
        'lr': 0.1 * opt.lr
    }, {
        'params': model.classifier.parameters(),
        'lr': opt.lr
    }],
                             weight_decay=5e-4,
                             momentum=0.9,
                             nesterov=True)
else:
    ignored_params = list(map(id, model.model._fc.parameters()))

    ignored_params += (
        list(map(id, model.classifierA0.parameters())) +
Ejemplo n.º 2
0
if opt.GGNN:
    model_name = 'PCB-128_dim_cls'
    model = load_network(model, model_name)
    model = PCB_Effi_GGNN(model, opt.train_backbone)
    # model_name = 'LSTM'
    # model = load_network(model, model_name)

print(model)

if not opt.multi_loss:
    ignored_params = list(map(id, model.model._fc.parameters()))
    ignored_params += (list(map(id, model.classifier.parameters())))
    if not opt.train_backbone:
        ignored_params += (list(map(id, model.model.parameters())))
    base_params = filter(
        lambda p: id(p) not in ignored_params, model.parameters()
    )
    optimizer = optim.SGD(
        [{'params': base_params, 'lr': 0.1*opt.lr},
         {'params': model.classifier.parameters(), 'lr': opt.lr}],
        weight_decay=5e-4, momentum=0.9, nesterov=True)
else:
    ignored_params = list(map(id, model.model._fc.parameters()))
    ignored_params += (
        list(map(id, model.classifierA0.parameters()))
        + list(map(id, model.classifierA1.parameters()))
        + list(map(id, model.classifierA2.parameters()))
        + list(map(id, model.classifierA3.parameters()))

        +list(map(id, model.classifierB0.parameters() ))
        +list(map(id, model.classifierB1.parameters() ))