Creates a new root for the dataset to be converted and placed into, then copies each image and mask into the given size and stores correctly.
(self)
| 151 | return len(self.sequences) |
| 152 | |
| 153 | def _convert_sequences(self): |
| 154 | # language=rst |
| 155 | """ |
| 156 | Creates a new root for the dataset to be converted and placed into, |
| 157 | then copies each image and mask into the given size and stores correctly. |
| 158 | """ |
| 159 | os.makedirs(os.path.join(self.converted_imagesets_path, f"{self.subset}.txt")) |
| 160 | os.makedirs(self.converted_img_path) |
| 161 | os.makedirs(self.converted_mask_path) |
| 162 | |
| 163 | shutil.copy( |
| 164 | os.path.join(self.imagesets_path, f"{self.subset}.txt"), |
| 165 | os.path.join(self.converted_imagesets_path, f"{self.subset}.txt"), |
| 166 | ) |
| 167 | |
| 168 | print("Converting sequences to size: {0}".format(self.size)) |
| 169 | for seq in tqdm(self.sequences_names): |
| 170 | os.makedirs(os.path.join(self.converted_img_path, seq)) |
| 171 | os.makedirs(os.path.join(self.converted_mask_path, seq)) |
| 172 | images = np.sort(glob(os.path.join(self.img_path, seq, "*.jpg"))).tolist() |
| 173 | if len(images) == 0 and not self.codalab: |
| 174 | raise FileNotFoundError(f"Images for sequence {seq} not found.") |
| 175 | for ind, img in enumerate(images): |
| 176 | im = Image.open(img) |
| 177 | im.thumbnail(self.size, Image.ANTIALIAS) |
| 178 | im.save( |
| 179 | os.path.join( |
| 180 | self.converted_img_path, seq, str(ind).zfill(5) + ".jpg" |
| 181 | ) |
| 182 | ) |
| 183 | masks = np.sort(glob(os.path.join(self.mask_path, seq, "*.png"))).tolist() |
| 184 | for ind, msk in enumerate(masks): |
| 185 | im = Image.open(msk) |
| 186 | im.thumbnail(self.size, Image.ANTIALIAS) |
| 187 | im.convert("RGB").save( |
| 188 | os.path.join( |
| 189 | self.converted_mask_path, seq, str(ind).zfill(5) + ".png" |
| 190 | ) |
| 191 | ) |
| 192 | |
| 193 | def _check_directories(self): |
| 194 | # language=rst |
no test coverage detected