-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b6915f
commit cd3b55e
Showing
6 changed files
with
49 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from glob import glob | ||
import os | ||
from PIL import Image | ||
from torchvision import transforms | ||
from torchvision.datasets import CelebA | ||
import torch | ||
from torch.utils.data import Dataset, DataLoader | ||
|
||
|
||
class celebA(Dataset): | ||
def __init__(self, data_path, img_ext, crop_size, img_size): | ||
self.celebs = glob(data_path + '/*' + img_ext) | ||
Range = transforms.Lambda(lambda X: 2 * X - 1.) | ||
self.transforms = transforms.Compose([ | ||
transforms.CenterCrop(crop_size), | ||
transforms.Resize(img_size), | ||
transforms.RandomHorizontalFlip(), | ||
transforms.ToTensor(), | ||
Range | ||
]) | ||
|
||
def __len__(self): | ||
return len(self.celebs) | ||
|
||
def __getitem__(self, index): | ||
img = Image.open(self.celebs[index]).convert('RGB') | ||
return self.transforms(img) | ||
|
||
|
||
def get_celeba_loaders(data_path, img_ext, crop_size, img_size, batch_size, download): | ||
dataset = celebA(data_path, img_ext, crop_size, img_size) | ||
if download: | ||
dataset = CelebA('celebA', transform=dataset.transforms, download=True) | ||
return DataLoader(dataset, batch_size=batch_size, shuffle=True, num_workers=28) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters