2017-fall-DL-training-program / VAE-GAN-and-VAE-GAN

An assignment to learn how to implement three differnent kinds of generative models
2 stars 0 forks source link

Lab 3-2 . CeleA_dataset.py #16

Closed mtkmark closed 6 years ago

mtkmark commented 6 years ago

Hi .

For CelebA_dataset.py, is it download able ?

Thanks Mark

hui-po-wang commented 6 years ago

Hi @mtkmark,

IT has put datasets in the dataset directory, it should be the same one as we used before.

Thanks

conlinwang commented 6 years ago

There you go!

class CelebADataset(data.Dataset): def init(self, h5_path, transform=None): assert (os.path.isfile(h5_path)) self.h5_path = h5_path self.transform = transform

    #laoding the dataset into memory
    f = h5py.File(self.h5_path, "r")
    key = list(f.keys())
    print ("key list:", key)
    self.dataset = f[key[0]]
    print ("dataset loaded and its shape:", self.dataset.shape)

def __getitem__(self, index):
    img = self.dataset[index]
    img = np.transpose(img, (1,2,0))
    if self.transform is not None:
        img = self.transform(img)

    return img, 0

def __len__(self):
    return len(self.dataset)
kevingo commented 6 years ago

Re-format

class CelebADataset(data.Dataset):
    def init(self, h5_path, transform=None):
        assert (os.path.isfile(h5_path))
        self.h5_path = h5_path
        self.transform = transform

        #laoding the dataset into memory
        f = h5py.File(self.h5_path, "r")
        key = list(f.keys())
        print ("key list:", key)
        self.dataset = f[key[0]]
        print ("dataset loaded and its shape:", self.dataset.shape)

    def __getitem__(self, index):
        img = self.dataset[index]
        img = np.transpose(img, (1,2,0))
        if self.transform is not None:
            img = self.transform(img)

        return img, 0

    def __len__(self):
        return len(self.dataset)
mtkmark commented 6 years ago

Thanks