Created
March 12, 2020 19:46
-
-
Save miracleyoo/5a873839fbb809cd87db7601b314de8c to your computer and use it in GitHub Desktop.
[Generate the images pack tensor with the same random transform pattern] #python #pytorch
This file contains hidden or 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
import numpy as np | |
import torch | |
def generate_images_pack_matrix(in_root, train=False): | |
# make a seed with numpy generator | |
seed = np.random.randint(2147483647) | |
in_root = Path(in_root) | |
img_paths = [i for i in list(in_root.iterdir()) if i.is_file() and not i.name.startswith(".")] | |
img_paths.sort(key=lambda x:int(x.stem)) | |
res=[] | |
for img_path in img_paths: | |
# apply this seed to img tranfsorms | |
random.seed(seed) | |
img = Image.open(str(img_path)) | |
if train: | |
img = eye_train_transforms(img) | |
else: | |
img = eye_val_transforms(img) | |
res.append(img) | |
return torch.stack(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment