def cal_acc(loader, netF, netB, netC):
    k = 0
    start_test = True
    with torch.no_grad():
        iter_test = iter(loader)
        for i in range(len(loader)):
            data = iter_test.next()
            input_images = []
            inputs = data[0]
            inputs_clone = inputs.clone()
            for j in range(inputs_clone.size(0)):
                x = transforms.Normalize(((- 1),), (2,))(inputs_clone[j])
                input_images.append(transforms.ToPILImage()(x))
            labels = data[1]
            outputs = netC(netB(netF(inputs)))
            (_, predict) = torch.max(outputs.float().cpu(), 1)
            for j in range(inputs.size(0)):
                folder = (args.output_dir + '/inspect/label-{}'.format(labels[j]))
                if (not osp.exists(folder)):
                    os.makedirs(folder)
                subfolder = (folder + '/pred-{}'.format(predict[j]))
                if (not osp.exists(subfolder)):
                    os.makedirs(subfolder)
                input_images[j].save((subfolder + '/{}.jpg'.format(k)))
                k += 1
            if start_test:
                all_output = outputs.float().cpu()
                all_label = labels.float()
                start_test = False
            else:
                all_output = torch.cat((all_output, outputs.float().cpu()), 0)
                all_label = torch.cat((all_label, labels.float()), 0)
    (_, predict) = torch.max(all_output, 1)
    accuracy = (torch.sum((torch.squeeze(predict).float() == all_label)).item() / float(all_label.size()[0]))
    mean_ent = torch.mean(loss.Entropy(nn.Softmax(dim=1)(all_output))).cpu().data.item()
    return ((accuracy * 100), mean_ent)
def cal_acc(loader, netF, netB, netC):
    k = 0
    start_test = True
    with torch.no_grad():
        iter_test = iter(loader)
        for i in range(len(loader)):
            data = iter_test.next()
            input_images = []
            inputs = data[0]
            inputs_clone = inputs.clone()
            for j in range(inputs_clone.size(0)):
                x = transforms.Normalize(((- 1),), (2,))(inputs_clone[j])
                input_images.append(transforms.ToPILImage()(x))
            labels = data[1]
            outputs = netC(netB(netF(inputs)))
            (_, predict) = torch.max(outputs.float().cpu(), 1)
            for j in range(inputs.size(0)):
                folder = (args.output_dir + '/inspect/label-{}'.format(labels[j]))
                if (not osp.exists(folder)):
                    os.makedirs(folder)
                subfolder = (folder + '/pred-{}'.format(predict[j]))
                if (not osp.exists(subfolder)):
                    os.makedirs(subfolder)
                input_images[j].save((subfolder + '/{}.jpg'.format(k)))
                k += 1
            if start_test:
                all_output = outputs.float().cpu()
                all_label = labels.float()
                start_test = False
            else:
                all_output = torch.cat((all_output, outputs.float().cpu()), 0)
                all_label = torch.cat((all_label, labels.float()), 0)
    (_, predict) = torch.max(all_output, 1)
    accuracy = (torch.sum((torch.squeeze(predict).float() == all_label)).item() / float(all_label.size()[0]))
    mean_ent = torch.mean(loss.Entropy(nn.Softmax(dim=1)(all_output))).cpu().data.item()
    return ((accuracy * 100), mean_ent)