Git Product home page Git Product logo

Comments (1)

tqch avatar tqch commented on August 16, 2024

Hi there. You can first download this repository and then add your custom dataset class to ddpm_torch/datasets.py. For example,

@register_dataset
class CustomDataset(tvds.VisionDataset):
    """
    My custom dataset
    """
    base_folder = "mydata"  # subdirectory under data root, e.g. ~/datasets
    resolution = (32, 32)  # re-scaled image resolution
    channels = 3  # RGB by default
    transform = transforms.Compose([
        transforms.Resize(32, 32),
        transforms.ToTensor(),
        transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
    ])   # your custom transformations
    all_size = 30000  # your dataset size

    def __init__(
            self,
            root,
            transform=None
    ):
        super().__init__(root, transform=transform)
        self.filename = sorted([
            fname
            for fname in os.listdir(os.path.join(root, self.base_folder))
            if fname.endswith((".png", ".jpg", ".jpeg", ".bmp"))
        ], key=lambda name: name.rsplit(".", maxsplit=1)[0])
        np.random.RandomState(1234).shuffle(self.filename)

    def __getitem__(self, index):
        im = PIL.Image.open(os.path.join(self.root, self.base_folder, self.filename[index]))

        if self.transform is not None:
            im = self.transform(im)

        return im

    def __len__(self):
        return len(self.filename)

from ddpm-torch.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.