示例#1
0
data_transforms = {
    'test': transforms.Compose([
        transforms.ToPILImage(),
        transforms.Resize((224, 224)),
        transforms.ToTensor(),
        transforms.Normalize(mean=[0.485, 0.456, 0.406],
                             std=[0.229, 0.224, 0.225])
    ]),
}

# Image and label directories
labels_dir = './ClothingAttributeDataset/labels/'
images_dir = './ClothingAttributeDataset/images/'

# Load the data
image_datasets = {x: ClothingAttributeDataset(labels_dir, images_dir, x, data_transforms[x]) for x in ['test']}
dataloaders = {x: DataLoader(image_datasets[x], batch_size=TEST_BATCH_SIZE, shuffle=True) for x in ['test']}
dataset_sizes = {x: len(image_datasets[x]) for x in ['test']}

main_task = 5  # gender
class_names = ['Male', 'Female']

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")


def imshow(inp, title=None):
    """Imshow for Tensor."""
    inp = inp.numpy().transpose((1, 2, 0))
    mean = np.array([0.485, 0.456, 0.406])
    std = np.array([0.229, 0.224, 0.225])
    inp = std * inp + mean
示例#2
0
    transforms.Compose([
        transforms.ToPILImage(),
        transforms.Resize((224, 224)),
        transforms.ToTensor(),
        transforms.Normalize(mean=[0.485, 0.456, 0.406],
                             std=[0.229, 0.224, 0.225])
    ]),
}

# Image and label directories
labels_dir = './ClothingAttributeDataset/labels/'
images_dir = './ClothingAttributeDataset/images/'

# Load the data
image_datasets = {
    x: ClothingAttributeDataset(labels_dir, images_dir, x, data_transforms[x])
    for x in ['test']
}
dataloaders = {
    x: DataLoader(image_datasets[x], batch_size=TEST_BATCH_SIZE)
    for x in ['test']
}
dataset_sizes = {x: len(image_datasets[x]) for x in ['test']}

main_task = 5  # gender
auxiliary_task = 20  # skin exposure
class_names = ['Male', 'Female']

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")