commit all

This commit is contained in:
2023-01-25 12:25:59 +00:00
parent 1bf224841f
commit 7470ca9fb6
139 changed files with 82069 additions and 811 deletions
+26 -22
View File
@@ -26,7 +26,7 @@ def get_img_idxs():
img_idxs = dict()
img_coords = dict()
uv_masks = dict()
uv_mask = np.load('custom_utils/mask_256x512.npy')
uv_mask = np.load('custom_data/garment_uv_mask_full.npy')
coords = np.transpose(np.stack(np.nonzero((1 - uv_mask))), (1,0))
img_idx = np.transpose(np.stack(np.nonzero((uv_mask))), (1,0))
img_idxs[512] = img_idx
@@ -41,7 +41,17 @@ def get_img_idxs():
img_coords[res] = coords
uv_masks[res] = down.astype(np.int32)
return img_idxs, img_coords, uv_masks
uv_masks_body = dict()
uv_mask_body = np.load('custom_utils/mask_256x512.npy')
uv_mask_body = cv2.dilate(uv_mask_body.astype(np.float32), cv2.getStructuringElement(cv2.MORPH_RECT, (2 * 2 + 1, 2 * 2 + 1), (2, 2)), iterations=2)
uv_masks_body[512] = uv_mask_body
for res in [32, 64, 128, 256]:
down = tf.image.resize(uv_mask_body[:,:,tf.newaxis].astype(np.int32), size=(res, int(res/2)), method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
down = np.squeeze(down.numpy().astype(bool))
uv_masks_body[res] = down
return img_idxs, img_coords, uv_masks, uv_masks_body
def fill(img, mask):
@@ -96,12 +106,10 @@ def downscale_uv_maps_posed_body(folder, type, sizes):
frames = os.listdir(os.path.join(folder, type))[int(args.start):int(args.end)]
for frame in tqdm.tqdm(frames):
id, _ = frame.split('_')
img = np.load(os.path.join(folder, type, frame)); img = img['uv_posed_body_no_orient']
mask_full = uv_mask_store[512][id]
img = fill(img, mask_full)
img = fill(img, uv_masks_body[512])
for size in sizes:
mask = uv_mask_store[size][id]
mask = uv_masks_body[size]
down = tf.image.resize(img, size=(size, int(size/2)), method=tf.image.ResizeMethod.LANCZOS5)
down = down * mask[:,:,np.newaxis]
np.savez_compressed(os.path.join(folder, type + '_' + str(size), frame), uv_posed_body_no_orient = down)
@@ -114,12 +122,11 @@ def downscale_uv_maps_curv(folder, type, sizes):
frames = os.listdir(os.path.join(folder, type))[int(args.start):int(args.end)]
for frame in tqdm.tqdm(frames):
id, _ = frame.split('_')
img = np.load(os.path.join(folder, type, frame)); img = img['curvature_uv']
mask_full = uv_mask_store[512][id]
mask_full = uv_mask_store[512][None]
img = fill_label(img, mask_full)
for size in sizes:
mask = uv_mask_store[size][id]
mask = uv_mask_store[size][None]
down = tf.image.resize(img[:,:,tf.newaxis], size=(size, int(size/2)), method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
down = np.squeeze(down) * mask[:,:]
np.savez_compressed(os.path.join(folder, type + '_' + str(size), frame), uv_curvature = down)
@@ -133,12 +140,11 @@ def downscale_uv_maps_unposed(folder, type, sizes):
frames = os.listdir(os.path.join(folder, type))[int(args.start):int(args.end)]
for frame in tqdm.tqdm(frames):
id, _ = frame.split('_')
img = np.load(os.path.join(folder, type, frame)); img = img['uv_unposed_no_shape']
mask_full = uv_mask_store[512][id]
mask_full = uv_mask_store[512][None]
img = fill(img, mask_full)
for size in sizes:
mask = uv_mask_store[size][id]
mask = uv_mask_store[size][None]
down = tf.image.resize(img, size=(size, int(size/2)), method=tf.image.ResizeMethod.LANCZOS5)
down = down * mask[:,:,np.newaxis]
np.savez_compressed(os.path.join(folder, type + '_' + str(size), frame), uv_unposed_no_shape = down)
@@ -151,14 +157,13 @@ def downscale_uv_maps_static(folder, type, sizes):
frames = os.listdir(os.path.join(folder, type))[int(args.start):int(args.end)]
for frame in tqdm.tqdm(frames):
id, _ = frame.split('.')
img = np.load(os.path.join(folder, type, frame)); img = img['uv_static']
mask_full = uv_mask_store[512][id]
mask_full = uv_mask_store[512][None]
img = fill(img, mask_full)
for size in sizes:
down = tf.image.resize(img, size=(size, int(size/2)), method=tf.image.ResizeMethod.LANCZOS5)
mask = uv_mask_store[size][id]
mask = uv_mask_store[size][None]
down = down * mask[:,:,np.newaxis]
np.savez_compressed(os.path.join(folder, type + '_' + str(size), frame), uv_static = down)
@@ -169,7 +174,6 @@ def downscale_uv_maps_mask(folder, type, size):
frames = os.listdir(os.path.join(folder, type))[int(args.start):int(args.end)]
for frame in tqdm.tqdm(frames):
id, _ = frame.split('.')
img = np.load(os.path.join(folder, type, frame)); img = img['uv_mask'].astype(np.float32)
down = tf.image.resize(img[:,:,tf.newaxis], size=(size, int(size/2)), method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
down = np.squeeze(down.numpy().astype(bool))
@@ -179,9 +183,9 @@ def downscale_uv_maps_mask(folder, type, size):
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--folder", help = "end of range", default='/home/workspace/local-data/cape_processed/test/male')
parser.add_argument("-f", "--folder", help = "end of range", default='/home/workspace/local-data/cape_processed/train/male')
parser.add_argument("-s", "--start", help = "start of range", default=0)
parser.add_argument("-e", "--end", help = "end of range", default=10000)
parser.add_argument("-e", "--end", help = "end of range", default=100000)
parser.add_argument("-n", "--name", help = "end of range", default='lhunor')
args = parser.parse_args()
@@ -189,7 +193,7 @@ if __name__ == '__main__':
sizes = [32, 64, 128, 256]
folder = args.folder
img_idxs, img_coords, uv_masks = get_img_idxs()
img_idxs, img_coords, uv_masks, uv_masks_body = get_img_idxs()
uv_mask_store = { size: UVMaskStore(folder, size=size) for size in sizes }
uv_mask_store[512] = UVMaskStore(folder, size=512)
@@ -200,9 +204,9 @@ if __name__ == '__main__':
# downscale_uv_maps_mask(folder=folder, type='uv_mask', size=256)
downscale_uv_maps_static(folder=folder, type='uv_static', sizes=sizes)
# downscale_uv_maps_unposed(folder=folder, type='uv_unposed_no_shape', sizes=sizes)
# downscale_uv_maps_curv(folder=folder, type='uv_curvature', sizes=sizes)
# downscale_uv_maps_posed_body(folder=folder, type='uv_posed_body_no_orient', sizes=sizes)
downscale_uv_maps_unposed(folder=folder, type='uv_unposed_no_shape', sizes=sizes)
downscale_uv_maps_curv(folder=folder, type='uv_curvature', sizes=sizes)
downscale_uv_maps_posed_body(folder=folder, type='uv_posed_body_no_orient', sizes=sizes)
print()