Skip to content

Instantly share code, notes, and snippets.

@udithhaputhanthri
Last active May 30, 2020 03:59
Show Gist options
  • Save udithhaputhanthri/3bdd5e70ed6e42d7bd47ab2523442b20 to your computer and use it in GitHub Desktop.
Save udithhaputhanthri/3bdd5e70ed6e42d7bd47ab2523442b20 to your computer and use it in GitHub Desktop.
Image-to-Image Translation Using Conditional DCGANs
class get_dataset(torch.utils.data.Dataset):
def __init__(self,name='edges2shoes',type_='train',transform=None):
self.dir_=name+'/'+name+'/'+type_
self.img_list=sorted(os.listdir(self.dir_))
self.transform=transform
def __len__(self):
return len(self.img_list)
def __getitem__(self,idx):
both=plt.imread(self.dir_+'/'+self.img_list[idx]).astype('uint8')
x=both[:,:both.shape[1]//2,:]
y=both[:,both.shape[1]//2:,:]
x,y=self.transform(Image.fromarray(x)),self.transform(Image.fromarray(y))
return x,y
img_size=128
batch_size=32
my_transform=transforms.Compose([transforms.Resize((img_size,img_size)),transforms.ToTensor()])
dataset_edges2shoes=get_dataset(name='edges2shoes',type_='val',transform=my_transform)
dataloader=torch.utils.data.DataLoader(dataset_edges2shoes,batch_size=batch_size,shuffle=True,drop_last=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment