MCPcopy Create free account
hub / github.com/adobe-research/custom-diffusion / __init__

Method __init__

src/finetune_data.py:116–172  ·  view source on GitHub ↗
(self,
                 datapath,
                 reg_datapath=None,
                 caption=None,
                 reg_caption=None,
                 size=512,
                 interpolation="bicubic",
                 flip_p=0.5,
                 aug=True,
                 style=False,
                 repeat=0.
                 )

Source from the content-addressed store, hash-verified

114
115class MaskBase(Dataset):
116 def __init__(self,
117 datapath,
118 reg_datapath=None,
119 caption=None,
120 reg_caption=None,
121 size=512,
122 interpolation="bicubic",
123 flip_p=0.5,
124 aug=True,
125 style=False,
126 repeat=0.
127 ):
128
129 self.aug = aug
130 self.repeat = repeat
131 self.style = style
132 self.templates_small = templates_small
133 if self.style:
134 self.templates_small = templates_small_style
135 if os.path.isdir(datapath):
136 self.image_paths1 = [os.path.join(datapath, file_path) for file_path in os.listdir(datapath) if isimage(file_path)]
137 else:
138 with open(datapath, "r") as f:
139 self.image_paths1 = f.read().splitlines()
140
141 self._length1 = len(self.image_paths1)
142
143 self.image_paths2 = []
144 self._length2 = 0
145 if reg_datapath is not None:
146 if os.path.isdir(reg_datapath):
147 self.image_paths2 = [os.path.join(reg_datapath, file_path) for file_path in os.listdir(reg_datapath) if isimage(file_path)]
148 else:
149 with open(reg_datapath, "r") as f:
150 self.image_paths2 = f.read().splitlines()
151 self._length2 = len(self.image_paths2)
152
153 self.labels = {
154 "relative_file_path1_": [x for x in self.image_paths1],
155 "relative_file_path2_": [x for x in self.image_paths2],
156 }
157
158 self.size = size
159 self.interpolation = {"linear": PIL.Image.LINEAR,
160 "bilinear": PIL.Image.BILINEAR,
161 "bicubic": PIL.Image.BICUBIC,
162 "lanczos": PIL.Image.LANCZOS,
163 }[interpolation]
164 self.flip = transforms.RandomHorizontalFlip(p=flip_p)
165 self.caption = caption
166
167 if os.path.exists(self.caption):
168 self.caption = [x.strip() for x in open(caption, 'r').readlines()]
169
170 self.reg_caption = reg_caption
171 if os.path.exists(self.reg_caption):
172 self.reg_caption = [x.strip() for x in open(reg_caption, 'r').readlines()]
173

Callers

nothing calls this directly

Calls 1

isimageFunction · 0.85

Tested by

no test coverage detected