示例#1
0
    save_path = os.path.join('./logs', model_name, 'net_last.pth')
    network.load_state_dict(torch.load(save_path))
    return network


######################################################################
# Finetuning the convnet
# --------
#

opt.nclasses = dataset.num_train_pids

if opt.backbone == 'ResNet50':
    model = PCB(opt)
elif opt.backbone == 'EfficientNet-B0':
    model = PCB_Effi(opt)

# model_name = 'test-pcb-ac'
# model = load_network(model, model_name)
model = VRidGGNN(model)
# model_name = 'VRid'
# model = load_network(model, model_name)

print(model)

if opt.single_cls:
    if opt.backbone == 'ResNet50':
        ignored_params = list(map(id, model.model.fc.parameters()))
    elif opt.backbone == 'EfficientNet-B0':
        ignored_params = list(map(id, model.model._fc.parameters()))
    ignored_params += (list(map(id, model.classifier.parameters())))
示例#2
0
# gallery_cam, gallery_label = get_id(gallery_path)
# query_cam, query_label = get_id(query_path)


######################################################################
# Load Collected data Trained model
# --------
#

print('-------test-----------')

if opt.backbone == 'ResNet50':
    model_structure = PCB(opt)
elif opt.backbone == 'EfficientNet-B0':
    model_structure = PCB_Effi(opt)

model_structure = VRidGGNN(model_structure)
model = load_network(model_structure)
model = VRidGGNN_test(model)

# Change to test mode
model = model.eval()
if use_gpu:
    model = model.cuda()

# Extract feature
with torch.no_grad():
    gallery_feature = extract_feature(model, galleryloader)
    query_feature = extract_feature(model, queryloader)
示例#3
0
# ----------------------
#
# Load a pretrainied model and reset final fully connected layer.
#

opt.nclasses = len(class_names)

if opt.use_dense:
    model = ft_net_dense(opt.nclasses, opt.droprate)
elif opt.use_NAS:
    model = ft_net_NAS(opt.nclasses, opt.droprate)
else:
    model = ft_net(opt.nclasses, opt.droprate, opt.stride)

if opt.PCB:
    model = PCB_Effi(opt.nclasses)

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,
示例#4
0
def load_network(network, model_name):
    save_path = os.path.join('./logs', model_name, 'net_last.pth')
    network.load_state_dict(torch.load(save_path))
    return network


######################################################################
# Finetuning the convnet
# --------
#

opt.nclasses = len(class_names)

if opt.PCB:
    model = PCB_Effi(opt.nclasses)

if opt.LSTM:
    # model_name = 'PCB-128_dim_cls'
    # model = load_network(model, model_name)
    model = PCB_Effi_LSTM(model, opt.train_backbone)
    # model_name = 'LSTM'
    # model = load_network(model, model_name)

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)