Script updates
This commit is contained in:
parent
b84469e922
commit
9dc3c8f0ff
|
@ -19,9 +19,9 @@ def main():
|
||||||
# compression time. If read raw images during training, use 0 for faster IO speed.
|
# compression time. If read raw images during training, use 0 for faster IO speed.
|
||||||
|
|
||||||
opt['dest'] = 'file'
|
opt['dest'] = 'file'
|
||||||
opt['input_folder'] = ['F:\\4k6k\\datasets\\images\\youtube\\images']
|
opt['input_folder'] = ['F:\\4k6k\\datasets\\ns_images\\imagesets\\imgset4']
|
||||||
opt['save_folder'] = 'F:\\4k6k\\datasets\\images\\ge_full_1024'
|
opt['save_folder'] = 'F:\\4k6k\\datasets\\ns_images\\256_unsupervised_new'
|
||||||
opt['imgsize'] = 1024
|
opt['imgsize'] = 256
|
||||||
#opt['bottom_crop'] = 120
|
#opt['bottom_crop'] = 120
|
||||||
|
|
||||||
save_folder = opt['save_folder']
|
save_folder = opt['save_folder']
|
||||||
|
@ -52,6 +52,7 @@ class TiledDataset(data.Dataset):
|
||||||
print("Error with ", path)
|
print("Error with ", path)
|
||||||
return None
|
return None
|
||||||
if len(img.shape) == 2:
|
if len(img.shape) == 2:
|
||||||
|
print("Skipping due to greyscale")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Perform explicit crops first. These are generally used to get rid of watermarks so we dont even want to
|
# Perform explicit crops first. These are generally used to get rid of watermarks so we dont even want to
|
||||||
|
@ -61,7 +62,8 @@ class TiledDataset(data.Dataset):
|
||||||
|
|
||||||
h, w, c = img.shape
|
h, w, c = img.shape
|
||||||
# Uncomment to filter any image that doesnt meet a threshold size.
|
# Uncomment to filter any image that doesnt meet a threshold size.
|
||||||
if min(h,w) < 1024:
|
if min(h,w) < 256:
|
||||||
|
print("Skipping due to threshold")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# We must convert the image into a square.
|
# We must convert the image into a square.
|
||||||
|
@ -70,13 +72,7 @@ class TiledDataset(data.Dataset):
|
||||||
img = img[(h - dim) // 2:dim + (h - dim) // 2, (w - dim) // 2:dim + (w - dim) // 2, :]
|
img = img[(h - dim) // 2:dim + (h - dim) // 2, (w - dim) // 2:dim + (w - dim) // 2, :]
|
||||||
img = cv2.resize(img, (self.opt['imgsize'], self.opt['imgsize']), interpolation=cv2.INTER_AREA)
|
img = cv2.resize(img, (self.opt['imgsize'], self.opt['imgsize']), interpolation=cv2.INTER_AREA)
|
||||||
|
|
||||||
# I was having some issues with unicode filenames with cv2. Hence using PIL.
|
cv2.imwrite(osp.join(self.opt['save_folder'], basename + ".jpg"), img, [cv2.IMWRITE_JPEG_QUALITY, self.opt['compression_level']])
|
||||||
# cv2.imwrite(osp.join(self.opt['save_folder'], basename + ".jpg"), img, [cv2.IMWRITE_JPEG_QUALITY, self.opt['compression_level']])
|
|
||||||
|
|
||||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
|
||||||
img = (img * 255).astype(np.uint8)
|
|
||||||
img = Image.fromarray(img)
|
|
||||||
img.save(osp.join(self.opt['save_folder'], basename + ".jpg"), "JPEG", quality=self.opt['compression_level'], optimize=True)
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
|
|
|
@ -13,19 +13,19 @@ import torch
|
||||||
def main():
|
def main():
|
||||||
split_img = False
|
split_img = False
|
||||||
opt = {}
|
opt = {}
|
||||||
opt['n_thread'] = 7
|
opt['n_thread'] = 4
|
||||||
opt['compression_level'] = 90 # JPEG compression quality rating.
|
opt['compression_level'] = 90 # JPEG compression quality rating.
|
||||||
# CV_IMWRITE_PNG_COMPRESSION from 0 to 9. A higher value means a smaller size and longer
|
# CV_IMWRITE_PNG_COMPRESSION from 0 to 9. A higher value means a smaller size and longer
|
||||||
# compression time. If read raw images during training, use 0 for faster IO speed.
|
# compression time. If read raw images during training, use 0 for faster IO speed.
|
||||||
|
|
||||||
opt['dest'] = 'file'
|
opt['dest'] = 'file'
|
||||||
opt['input_folder'] = 'F:\\4k6k\\datasets\\images\youtube\\images_cook'
|
opt['input_folder'] = 'F:\\4k6k\\datasets\\ns_images\\imagesets\\images'
|
||||||
opt['save_folder'] = 'F:\\4k6k\\datasets\\images\\youtube_massive_cook'
|
opt['save_folder'] = 'F:\\4k6k\\datasets\\ns_images\\imagesets\\512_with_ref_new'
|
||||||
opt['crop_sz'] = [512, 1024, 2048] # the size of each sub-image
|
opt['crop_sz'] = [1024, 2048] # the size of each sub-image
|
||||||
opt['step'] = [256, 512, 1024] # step of the sliding crop window
|
opt['step'] = [700, 1200] # step of the sliding crop window
|
||||||
opt['exclusions'] = [[],[],[]] # image names matching these terms wont be included in the processing.
|
opt['exclusions'] = [[],[],[]] # image names matching these terms wont be included in the processing.
|
||||||
opt['thres_sz'] = 128 # size threshold
|
opt['thres_sz'] = 256 # size threshold
|
||||||
opt['resize_final_img'] = [.5, .25, .125]
|
opt['resize_final_img'] = [.5, .25]
|
||||||
opt['only_resize'] = False
|
opt['only_resize'] = False
|
||||||
opt['vertical_split'] = False
|
opt['vertical_split'] = False
|
||||||
opt['input_image_max_size_before_being_halved'] = 5500 # As described, images larger than this dimensional size will be halved before anything else is done.
|
opt['input_image_max_size_before_being_halved'] = 5500 # As described, images larger than this dimensional size will be halved before anything else is done.
|
||||||
|
@ -245,7 +245,7 @@ class TiledDataset(data.Dataset):
|
||||||
for exc in exclusions:
|
for exc in exclusions:
|
||||||
if exc in path:
|
if exc in path:
|
||||||
excluded = True
|
excluded = True
|
||||||
break;
|
break
|
||||||
if excluded:
|
if excluded:
|
||||||
continue
|
continue
|
||||||
results.extend(self.get_for_scale(img, crop_sz, step, resize_factor, ref_resize_factor))
|
results.extend(self.get_for_scale(img, crop_sz, step, resize_factor, ref_resize_factor))
|
||||||
|
@ -262,6 +262,7 @@ def extract_single(opt, writer):
|
||||||
dataset = TiledDataset(opt)
|
dataset = TiledDataset(opt)
|
||||||
dataloader = data.DataLoader(dataset, num_workers=opt['n_thread'], collate_fn=identity)
|
dataloader = data.DataLoader(dataset, num_workers=opt['n_thread'], collate_fn=identity)
|
||||||
tq = tqdm(dataloader)
|
tq = tqdm(dataloader)
|
||||||
|
i = 0
|
||||||
for spl_imgs in tq:
|
for spl_imgs in tq:
|
||||||
if spl_imgs is None:
|
if spl_imgs is None:
|
||||||
continue
|
continue
|
||||||
|
@ -272,7 +273,8 @@ def extract_single(opt, writer):
|
||||||
imgs, path = imgs
|
imgs, path = imgs
|
||||||
if imgs is None or len(imgs) <= 1:
|
if imgs is None or len(imgs) <= 1:
|
||||||
continue
|
continue
|
||||||
path = path + "_" + lbl
|
path = f'{path}_{lbl}_{i}'
|
||||||
|
i += 1
|
||||||
ref_id = writer.write_reference_image(imgs[0], path)
|
ref_id = writer.write_reference_image(imgs[0], path)
|
||||||
for tile in imgs[1:]:
|
for tile in imgs[1:]:
|
||||||
writer.write_tile_image(ref_id, tile)
|
writer.write_tile_image(ref_id, tile)
|
||||||
|
|
|
@ -162,7 +162,8 @@ if __name__ == "__main__":
|
||||||
torch.backends.cudnn.benchmark = True
|
torch.backends.cudnn.benchmark = True
|
||||||
srg_analyze = False
|
srg_analyze = False
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-opt', type=str, help='Path to options YAML file.', default='../../options/train_exd_imgsetext_srflow_bigboi_frompsnr.yml')
|
parser.add_argument('-opt', type=str, help='Path to options YAML file.', default='../options/train_exd_imgsetext_srflow_bigboi_ganbase.yml')
|
||||||
|
#parser.add_argument('-opt', type=str, help='Path to options YAML file.', default='../../options/train_exd_imgsetext_srflow_bigboi_frompsnr.yml')
|
||||||
opt = option.parse(parser.parse_args().opt, is_train=False)
|
opt = option.parse(parser.parse_args().opt, is_train=False)
|
||||||
opt = option.dict_to_nonedict(opt)
|
opt = option.dict_to_nonedict(opt)
|
||||||
utils.util.loaded_options = opt
|
utils.util.loaded_options = opt
|
||||||
|
@ -180,8 +181,8 @@ if __name__ == "__main__":
|
||||||
gen.eval()
|
gen.eval()
|
||||||
|
|
||||||
mode = "feed_through" # temperature | restore | latent_transfer | feed_through
|
mode = "feed_through" # temperature | restore | latent_transfer | feed_through
|
||||||
imgs_to_resample_pattern = "F:\\4k6k\\datasets\\ns_images\\adrianna\\val2\\lr\\*"
|
#imgs_to_resample_pattern = "F:\\4k6k\\datasets\\ns_images\\adrianna\\val2\\lr\\*"
|
||||||
#imgs_to_resample_pattern = "F:\\4k6k\\datasets\\ns_images\\adrianna\\analyze\\analyze_xx\\*"
|
imgs_to_resample_pattern = "F:\\4k6k\\datasets\\ns_images\\adrianna\\analyze\\analyze_xx\\*"
|
||||||
#imgs_to_resample_pattern = "F:\\4k6k\\datasets\\ns_images\\imagesets\\images-half\\*lanette*"
|
#imgs_to_resample_pattern = "F:\\4k6k\\datasets\\ns_images\\imagesets\\images-half\\*lanette*"
|
||||||
scale = 2
|
scale = 2
|
||||||
resample_factor = 2 # When != 1, the HR image is upsampled by this factor using a bicubic to get the local latents. E.g. set this to '2' to get 2x upsampling.
|
resample_factor = 2 # When != 1, the HR image is upsampled by this factor using a bicubic to get the local latents. E.g. set this to '2' to get 2x upsampling.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user