create downscaled version of preprocessed inputs
This commit is contained in:
+100
@@ -0,0 +1,100 @@
|
||||
import os
|
||||
import tqdm
|
||||
import cv2
|
||||
import tensorflow as tf
|
||||
import scipy.interpolate as spi
|
||||
import numpy as np
|
||||
import plotly.graph_objects as go
|
||||
import plotly.express as ex
|
||||
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
||||
|
||||
|
||||
def fill(img, mask):
|
||||
coords = np.transpose(np.stack(np.nonzero((1 - mask))), (1,0))
|
||||
img_idx = np.transpose(np.stack(np.nonzero((mask))), (1,0))
|
||||
img_data = img[img_idx[:,0], img_idx[:,1], :]
|
||||
|
||||
interpolator = spi.NearestNDInterpolator(x=img_idx, y=img_data)
|
||||
img_2 = interpolator(coords)
|
||||
res = np.zeros((512,256,3), dtype=np.float32)
|
||||
res[coords[:,0], coords[:,1], :] = img_2
|
||||
res[img_idx[:,0], img_idx[:,1], :] = img_data
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def fill_label(img, mask):
|
||||
coords = np.transpose(np.stack(np.nonzero((1 - mask))), (1,0))
|
||||
img_idx = np.transpose(np.stack(np.nonzero((mask))), (1,0))
|
||||
img_data = img[img_idx[:,0], img_idx[:,1]]
|
||||
|
||||
interpolator = spi.NearestNDInterpolator(x=img_idx, y=img_data)
|
||||
img_2 = interpolator(coords)
|
||||
res = np.zeros((512,256), dtype=np.float32)
|
||||
res[coords[:,0], coords[:,1]] = img_2
|
||||
res[img_idx[:,0], img_idx[:,1]] = img_data
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def downscale_uv_maps_posed_body(folder, type, size: int):
|
||||
os.makedirs(os.path.join(folder, type + '_' + str(size)), exist_ok=True)
|
||||
|
||||
frames = os.listdir(os.path.join(folder, type))
|
||||
|
||||
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_filled']
|
||||
down = tf.image.resize(img, size=(size, int(size/2)), method=tf.image.ResizeMethod.LANCZOS5)
|
||||
np.savez_compressed(os.path.join(folder, type + '_' + str(size), frame), uv_posed_body_no_orient_filled = down)
|
||||
|
||||
|
||||
def downscale_uv_maps_curv(folder, type, size):
|
||||
os.makedirs(os.path.join(folder, type + '_' + str(size)), exist_ok=True)
|
||||
|
||||
frames = os.listdir(os.path.join(folder, type))
|
||||
|
||||
for frame in tqdm.tqdm(frames):
|
||||
id, _ = frame.split('_')
|
||||
img = np.load(os.path.join(folder, type, frame)); img = img['uv_curvature_filled']
|
||||
down = cv2.resize(img, (int(size/2), size), interpolation=cv2.INTER_NEAREST)
|
||||
np.savez_compressed(os.path.join(folder, type + '_' + str(size), frame), uv_curvature_filled = down)
|
||||
|
||||
|
||||
|
||||
def downscale_uv_maps_unposed(folder, type, size):
|
||||
os.makedirs(os.path.join(folder, type + '_' + str(size)), exist_ok=True)
|
||||
|
||||
frames = os.listdir(os.path.join(folder, type))
|
||||
|
||||
for frame in tqdm.tqdm(frames):
|
||||
id, _ = frame.split('_')
|
||||
img = np.load(os.path.join(folder, type, frame)); img = img['uv_unposed_no_shape_filled']
|
||||
down = tf.image.resize(img, size=(size, int(size/2)), method=tf.image.ResizeMethod.LANCZOS5)
|
||||
np.savez_compressed(os.path.join(folder, type + '_' + str(size), frame), uv_unposed_no_shape_filled = down)
|
||||
|
||||
|
||||
|
||||
def downscale_uv_maps_static(folder, type, size):
|
||||
os.makedirs(os.path.join(folder, type + '_' + str(size)), exist_ok=True)
|
||||
|
||||
frames = os.listdir(os.path.join(folder, type))
|
||||
|
||||
for frame in tqdm.tqdm(frames):
|
||||
id, _ = frame.split('.')
|
||||
img = np.load(os.path.join(folder, type, frame)); img = img['uv_static_filled']
|
||||
down = tf.image.resize(img, size=(size, int(size/2)), method=tf.image.ResizeMethod.LANCZOS5)
|
||||
np.savez_compressed(os.path.join(folder, type + '_' + str(size), frame), uv_static_filled = down)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
size = 128
|
||||
downscale_uv_maps_static(folder='/home/workspace/local-data/train_100', type='uv_static_filled', size=size)
|
||||
downscale_uv_maps_unposed(folder='/home/workspace/local-data/train_100', type='uv_unposed_no_shape_filled', size=size)
|
||||
downscale_uv_maps_curv(folder='/home/workspace/local-data/train_100', type='uv_curvature_filled', size=size)
|
||||
downscale_uv_maps_posed_body(folder='/home/workspace/local-data/train_100', type='uv_posed_body_no_orient_filled', size=size)
|
||||
|
||||
|
||||
print()
|
||||
Reference in New Issue
Block a user