Пример #1
0
    # disp_interval = 5000
    # log_interval = 250
    pretrained_vgg16 = False
    fine_tune = False
    rand_seed = 64678
    if rand_seed is not None:
        np.random.seed(rand_seed)
        torch.manual_seed(rand_seed)
        torch.cuda.manual_seed(rand_seed)
    net = CrowdCounter()
    network.weights_normal_init(net, dev=0.01)
    if pretrained_vgg16:
        vgg16_model = models.vgg16(pretrained=True)
        # vgg16_model.cuda()
        net.DA_Net.copy_params_from_vgg16(vgg16_model)
    net.to(device)

    Loss_list = []
    for epoch in range(start_epoch, start_epoch + 2):
        train_loss = train_DA(epoch)
        Loss_list.append(train_loss)
        if epoch == 1:
            test_DA(epoch)

    # 记录train_loss
    train_loss_txt = open('train_loss.txt', 'w')
    for value in Loss_list:
        train_loss_txt.write(str(value))
        train_loss_txt.write('\n')
    train_loss_txt.close()
Пример #2
0
    f.write('MAE: %0.2f, MSE: %0.2f' % (mae,mse))
    f.close()


if __name__ == '__main__':

    torch.backends.cudnn.enabled = True
    torch.backends.cudnn.benchmark = False

    # data_path = './data/original/shanghaitech/part_B_final/test_data/images/'
    # gt_path = './data/original/shanghaitech/part_B_final/test_data/ground_truth_csv/'

    data_path = './data/original/shanghaitech/part_A_final/test_data/images/'
    gt_path = './data/original/shanghaitech/part_A_final/test_data/ground_truth_csv/'

    model_path = './Shanghai_A_Retrain_eps_1_5/saved_models//MCNN_Shanghai_A.h5'

    model = CrowdCounter()
    trained_model = os.path.join(model_path)
    network.load_net(trained_model, model)
    model.to(device)
    model.eval()

    data_loader = ImageDataLoader(data_path, gt_path, shuffle=False, gt_downsample=True, pre_load=True)

    eps_list = [0, 0.25, 0.5, 0.75, 1]

    print(model_path)

    epoch_robust_bound(data_loader, model, device, epsilon_try=0.25)