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.backbone == 'ResNet50': model = PCB(opt) elif opt.backbone == 'EfficientNet-B0': model = PCB_Effi(opt) if opt.LSTM: # model_name = 'PCB-128_dim_cls' # model = load_network(model, model_name) model = PCB_Effi_LSTM(model, opt) # 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) # model_name = 'LSTM'
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 = 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':
# gallery_path = image_datasets['gallery'].imgs # query_path = image_datasets['query'].imgs # 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)