-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pnsuau
committed
Jul 18, 2023
1 parent
7819fdf
commit 6c92cab
Showing
13 changed files
with
1,982 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os.path | ||
from data.unaligned_labeled_mask_ref_dataset import UnalignedLabeledMaskRefDataset | ||
from data.online_creation import fill_mask_with_random, fill_mask_with_color | ||
from PIL import Image | ||
import numpy as np | ||
import torch | ||
import warnings | ||
|
||
|
||
class SelfSupervisedLabeledMaskRefDataset(UnalignedLabeledMaskRefDataset): | ||
""" | ||
This dataset class can create paired datasets with mask labels from only one domain. | ||
""" | ||
|
||
def __init__(self, opt, phase): | ||
"""Initialize this dataset class. | ||
Parameters: | ||
opt (Option class) -- stores all the experiment flags; needs to be a subclass of BaseOptions | ||
""" | ||
super().__init__(opt, phase) | ||
|
||
def get_img( | ||
self, | ||
A_img_path, | ||
A_label_mask_path, | ||
A_label_cls, | ||
B_img_path=None, | ||
B_label_mask_path=None, | ||
B_label_cls=None, | ||
index=None, | ||
): | ||
result = super().get_img( | ||
A_img_path, | ||
A_label_mask_path, | ||
A_label_cls, | ||
B_img_path, | ||
B_label_mask_path, | ||
B_label_cls, | ||
index, | ||
clamp_semantics=False, | ||
) | ||
|
||
try: | ||
|
||
if self.opt.data_online_creation_rand_mask_A: | ||
A_img = fill_mask_with_random(result["A"], result["A_label_mask"], -1) | ||
elif self.opt.data_online_creation_color_mask_A: | ||
A_img = fill_mask_with_color(result["A"], result["A_label_mask"], {}) | ||
else: | ||
raise Exception( | ||
"self supervised dataset: no self supervised method specified" | ||
) | ||
|
||
result.update( | ||
{ | ||
"A": A_img, | ||
"B": result["A"], | ||
"B_img_paths": result["A_img_paths"], | ||
"B_label_mask": result["A_label_mask"].clone(), | ||
} | ||
) | ||
except Exception as e: | ||
print(e, "self supervised data loading") | ||
return None | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
|
||
from torchvision.transforms.functional import resize | ||
from PIL import Image | ||
|
||
from data.base_dataset import get_transform_ref | ||
from data.unaligned_labeled_mask_dataset import UnalignedLabeledMaskDataset | ||
from data.image_folder import make_ref_path | ||
|
||
|
||
class UnalignedLabeledMaskRefDataset(UnalignedLabeledMaskDataset): | ||
def __init__(self, opt, phase): | ||
super().__init__(opt, phase) | ||
|
||
self.A_img_ref = make_ref_path(self.dir_A, "/conditions.txt") | ||
|
||
self.transform_ref = get_transform_ref(opt) | ||
|
||
def get_img( | ||
self, | ||
A_img_path, | ||
A_label_mask_path, | ||
A_label_cls, | ||
B_img_path=None, | ||
B_label_mask_path=None, | ||
B_label_cls=None, | ||
index=None, | ||
clamp_semantics=True, | ||
): | ||
|
||
result = super().get_img( | ||
A_img_path, | ||
A_label_mask_path, | ||
A_label_cls, | ||
B_img_path, | ||
B_label_mask_path, | ||
B_label_cls, | ||
index, | ||
clamp_semantics, | ||
) | ||
|
||
img_path = result["A_img_paths"] | ||
|
||
if self.opt.data_relative_paths: | ||
img_path = img_path.replace(self.root, "") | ||
|
||
ref_A_path = self.A_img_ref[img_path] | ||
|
||
if self.opt.data_relative_paths: | ||
ref_A_path = os.path.join(self.root, ref_A_path) | ||
|
||
try: | ||
ref_A = Image.open(ref_A_path).convert("RGB") | ||
|
||
except Exception as e: | ||
print( | ||
"failure with reading A domain image ref ", | ||
ref_A_path, | ||
) | ||
print(e) | ||
return None | ||
|
||
ref_A = self.transform_ref(ref_A) | ||
|
||
result.update({"ref_A": ref_A}) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.