def inference(net, img_path='', output_path='./', output_name='f', use_gpu=True):
    '\n\n    :param net:\n    :param img_path:\n    :param output_path:\n    :return:\n    '
    adj2_ = torch.from_numpy(graph.cihp2pascal_nlp_adj).float()
    adj2_test = adj2_.unsqueeze(0).unsqueeze(0).expand(1, 1, 7, 20).cuda().transpose(2, 3)
    adj1_ = Variable(torch.from_numpy(graph.preprocess_adj(graph.pascal_graph)).float())
    adj3_test = adj1_.unsqueeze(0).unsqueeze(0).expand(1, 1, 7, 7).cuda()
    cihp_adj = graph.preprocess_adj(graph.cihp_graph)
    adj3_ = Variable(torch.from_numpy(cihp_adj).float())
    adj1_test = adj3_.unsqueeze(0).unsqueeze(0).expand(1, 1, 20, 20).cuda()
    scale_list = [1, 0.5, 0.75, 1.25, 1.5, 1.75]
    img = read_img(img_path)
    testloader_list = []
    testloader_flip_list = []
    for pv in scale_list:
        composed_transforms_ts = transforms.Compose([tr.Scale_only_img(pv), tr.Normalize_xception_tf_only_img(), tr.ToTensor_only_img()])
        composed_transforms_ts_flip = transforms.Compose([tr.Scale_only_img(pv), tr.HorizontalFlip_only_img(), tr.Normalize_xception_tf_only_img(), tr.ToTensor_only_img()])
        testloader_list.append(img_transform(img, composed_transforms_ts))
        testloader_flip_list.append(img_transform(img, composed_transforms_ts_flip))
    start_time = timeit.default_timer()
    net.eval()
    for (iii, sample_batched) in enumerate(zip(testloader_list, testloader_flip_list)):
        (inputs, labels) = (sample_batched[0]['image'], sample_batched[0]['label'])
        (inputs_f, _) = (sample_batched[1]['image'], sample_batched[1]['label'])
        inputs = inputs.unsqueeze(0)
        inputs_f = inputs_f.unsqueeze(0)
        inputs = torch.cat((inputs, inputs_f), dim=0)
        if (iii == 0):
            (_, _, h, w) = inputs.size()
        inputs = Variable(inputs, requires_grad=False)
        with torch.no_grad():
            if (use_gpu >= 0):
                inputs = inputs.cuda()
            outputs = net.forward(inputs, adj1_test.cuda(), adj3_test.cuda(), adj2_test.cuda())
            outputs = ((outputs[0] + flip(flip_cihp(outputs[1]), dim=(- 1))) / 2)
            outputs = outputs.unsqueeze(0)
            if (iii > 0):
                outputs = F.upsample(outputs, size=(h, w), mode='bilinear', align_corners=True)
                outputs_final = (outputs_final + outputs)
            else:
                outputs_final = outputs.clone()
    predictions = torch.max(outputs_final, 1)[1]
    results = predictions.cpu().numpy()
    vis_res = decode_labels(results)
    parsing_im = Image.fromarray(vis_res[0])
    parsing_im.save((output_path + '/{}.png'.format(output_name)))
    end_time = timeit.default_timer()
    print((('time used for the multi-scale image inference' + ' is :') + str((end_time - start_time))))
:param net:
:param img_path:
:param output_path:
:return:
def inference(net, img_path=, output_path='./', output_name='f', use_gpu=True):
    '\n\n    :param net:\n    :param img_path:\n    :param output_path:\n    :return:\n    '
    adj2_ = torch.from_numpy(graph.cihp2pascal_nlp_adj).float()
    adj2_test = adj2_.unsqueeze(0).unsqueeze(0).expand(1, 1, 7, 20).cuda().transpose(2, 3)
    adj1_ = Variable(torch.from_numpy(graph.preprocess_adj(graph.pascal_graph)).float())
    adj3_test = adj1_.unsqueeze(0).unsqueeze(0).expand(1, 1, 7, 7).cuda()
    cihp_adj = graph.preprocess_adj(graph.cihp_graph)
    adj3_ = Variable(torch.from_numpy(cihp_adj).float())
    adj1_test = adj3_.unsqueeze(0).unsqueeze(0).expand(1, 1, 20, 20).cuda()
    scale_list = [1, 0.5, 0.75, 1.25, 1.5, 1.75]
    img = read_img(img_path)
    testloader_list = []
    testloader_flip_list = []
    for pv in scale_list:
        composed_transforms_ts = transforms.Compose([tr.Scale_only_img(pv), tr.Normalize_xception_tf_only_img(), tr.ToTensor_only_img()])
        composed_transforms_ts_flip = transforms.Compose([tr.Scale_only_img(pv), tr.HorizontalFlip_only_img(), tr.Normalize_xception_tf_only_img(), tr.ToTensor_only_img()])
        testloader_list.append(img_transform(img, composed_transforms_ts))
        testloader_flip_list.append(img_transform(img, composed_transforms_ts_flip))
    start_time = timeit.default_timer()
    net.eval()
    for (iii, sample_batched) in enumerate(zip(testloader_list, testloader_flip_list)):
        (inputs, labels) = (sample_batched[0]['image'], sample_batched[0]['label'])
        (inputs_f, _) = (sample_batched[1]['image'], sample_batched[1]['label'])
        inputs = inputs.unsqueeze(0)
        inputs_f = inputs_f.unsqueeze(0)
        inputs = torch.cat((inputs, inputs_f), dim=0)
        if (iii == 0):
            (_, _, h, w) = inputs.size()
        inputs = Variable(inputs, requires_grad=False)
        with torch.no_grad():
            if (use_gpu >= 0):
                inputs = inputs.cuda()
            outputs = net.forward(inputs, adj1_test.cuda(), adj3_test.cuda(), adj2_test.cuda())
            outputs = ((outputs[0] + flip(flip_cihp(outputs[1]), dim=(- 1))) / 2)
            outputs = outputs.unsqueeze(0)
            if (iii > 0):
                outputs = F.upsample(outputs, size=(h, w), mode='bilinear', align_corners=True)
                outputs_final = (outputs_final + outputs)
            else:
                outputs_final = outputs.clone()
    predictions = torch.max(outputs_final, 1)[1]
    results = predictions.cpu().numpy()
    vis_res = decode_labels(results)
    parsing_im = Image.fromarray(vis_res[0])
    parsing_im.save((output_path + '/{}.png'.format(output_name)))
    end_time = timeit.default_timer()
    print((('time used for the multi-scale image inference' + ' is :') + str((end_time - start_time))))