save progress
This commit is contained in:
+60
-46
@@ -13,6 +13,7 @@ import numpy as np
|
||||
import scipy as sp
|
||||
import trimesh as tm
|
||||
import cmapy as cm
|
||||
import tables as tb
|
||||
import scipy.io as sio
|
||||
import scipy.interpolate as spi
|
||||
import matplotlib.pyplot as plt
|
||||
@@ -22,7 +23,8 @@ import plotly.express as ex
|
||||
import plotly.graph_objects as go
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
|
||||
from data.cloth3d_io import read_garment_mask, read_garment_template, read_posed_garment_frame, loadInfo, read_posed_body_frame, read_posed_body, read_posed_garment
|
||||
from data.cloth3d_io import read_garment_mask, read_garment_template, read_posed_garment_frame, loadInfo, read_posed_body_frame, read_posed_body, read_posed_garment, read_curvatures
|
||||
from data.utils import save_to_h5file
|
||||
|
||||
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = "6"
|
||||
@@ -119,6 +121,8 @@ def convert_to_uv_batch(res, m2uv, uv_map, verts, neighbours=15, mask=None, meth
|
||||
rbf_dest_current = np.nonzero(rbf_dest_current)
|
||||
rbf_dest_current = np.array(rbf_dest_current).T
|
||||
|
||||
out = []
|
||||
|
||||
for i in range(batch):
|
||||
print('processing frame: ' + str(i))
|
||||
|
||||
@@ -138,8 +142,10 @@ def convert_to_uv_batch(res, m2uv, uv_map, verts, neighbours=15, mask=None, meth
|
||||
|
||||
if garment_uv_mask is not None:
|
||||
result *= garment_uv_mask[:,:,np.newaxis]
|
||||
|
||||
np.savez_compressed(os.path.join(folder, 'uv_posed_no_orient', id + '_' + str(i) + '.npz'), uv_posed_no_orient=result)
|
||||
|
||||
out.append(result)
|
||||
|
||||
return out
|
||||
|
||||
|
||||
def convert_to_uv_batch_label(res, m2uv, uv_map, values, neighbours=15, mask=None, method='rbf', garment_uv_mask=None, garment_uv_mask_border=None):
|
||||
@@ -323,25 +329,16 @@ def get_shapedirs():
|
||||
shapedirs.append(male['shapedirs'][to_keep, :])
|
||||
return shapedirs
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-f", "--folder", help = "end of range", default='/home/workspace/data/dataset/test_skirt_ready_2')
|
||||
parser.add_argument("-x", "--extras", help = "end of range", default='/home/workspace/data/dataset/test_skirt_ready_2_extras')
|
||||
parser.add_argument("-f", "--folder", help = "end of range", default='/home/workspace/data/dataset/cloth3d/train')
|
||||
parser.add_argument("-s", "--start", help = "start of range", default=0)
|
||||
parser.add_argument("-e", "--end", help = "end of range", default=30000)
|
||||
parser.add_argument("-e", "--end", help = "end of range", default=1000)
|
||||
parser.add_argument("-n", "--name", help = "end of range", default='lhunor')
|
||||
parser.add_argument("-sk", "--skirt", help = "end of range", default=1)
|
||||
parser.add_argument("-sk", "--skirt", help = "end of range", default=0)
|
||||
args = parser.parse_args()
|
||||
|
||||
# smpl = SMPL('FeatureLines/superSMPL')
|
||||
|
||||
folder = args.folder
|
||||
extras_folder = args.extras
|
||||
|
||||
os.makedirs(extras_folder, exist_ok=True)
|
||||
|
||||
print("skirt" if args.skirt == 1 else "not skirt")
|
||||
|
||||
F = np.load("custom_utils/smpl_faces" + ("_skirt" if args.skirt == 1 else "") + ".npy")
|
||||
uv_map = np.load('custom_utils/stretched_uv_map_' + ("skirt" if args.skirt == 1 else "3") + '.npy')
|
||||
m2uv = np.load('custom_utils/m2uv' + ("_skirt" if args.skirt == 1 else "") + '.npy', allow_pickle=True).item()
|
||||
@@ -369,49 +366,64 @@ if __name__ == '__main__':
|
||||
rbf_dest[uv_map_discreet_unique[:, 0], uv_map_discreet_unique[:, 1]] = 0
|
||||
rbf_dest[np.invert(uv_mask[:,:,0])] = 0
|
||||
|
||||
is_skirt = True if args.skirt == 1 else False
|
||||
skirt_modifier = '_skirt' if is_skirt else ''
|
||||
|
||||
#########################################################################################
|
||||
|
||||
use_no_orient = False
|
||||
no_shape = False
|
||||
is_skirt = True if args.skirt == 1 else False
|
||||
folder = args.folder
|
||||
neighbourhood = 25
|
||||
frames_file = 'frames_all.txt'
|
||||
data_to_convert = ['mesh_posed', 'mesh_static', 'mesh_curvature', 'body_posed'] # 'mesh_unposed',
|
||||
|
||||
print("skirt" if args.skirt == 1 else "not skirt")
|
||||
print(f'params: -f {args.folder} -s {args.start} -e {args.end} -n {args.name} -skirt {args.skirt}')
|
||||
|
||||
skirt_modifier = '_skirt' if is_skirt else ''
|
||||
orient_mod = '_no_orient' if use_no_orient else ''
|
||||
shape_mod = '_no_shape' if no_shape else ''
|
||||
|
||||
frames = []
|
||||
with open(os.path.join(folder, frames_file), 'r') as f:
|
||||
lines = f.readlines()
|
||||
lines = [line.strip() for line in lines]
|
||||
frames = lines#[int(args.start):int(args.end)]
|
||||
ids = [frame.split('_')[0] for frame in frames]
|
||||
|
||||
print(f'params: -f {args.folder} -s {args.start} -e {args.end} -n {args.name} -skirt {args.skirt}')
|
||||
|
||||
# ids = os.listdir(os.path.join(local_folder, 'pose_shape'))
|
||||
# ids = [id.split('_')[0] for id in ids]
|
||||
frames = lines
|
||||
ids = [frame.split()[0] for frame in frames]
|
||||
ids = sorted(list(set(ids)))[int(args.start):int(args.end)]
|
||||
|
||||
shapedirs = get_shapedirs()
|
||||
|
||||
use_no_orient = True
|
||||
no_shape = False
|
||||
data_to_convert = ['mesh_posed', 'mesh_unposed', 'mesh_static', 'mesh_curvature', 'body_posed']
|
||||
root = '/'.join(folder.split('/')[:-1])
|
||||
type = folder.split('/')[-1]
|
||||
h5file = tb.open_file(os.path.join(root, f'{type}_extras.h5'), mode='a')
|
||||
|
||||
|
||||
for id in tqdm.tqdm(ids):
|
||||
|
||||
|
||||
info = loadInfo(os.path.join(folder, id, 'info.mat'))
|
||||
garments = info['outfit']
|
||||
garments = list(info['outfit'].keys())
|
||||
assert info['poses'].shape[1] <= 300
|
||||
|
||||
# put all this in a function and call for all garments
|
||||
|
||||
# also masking is not the same as just filling the empty values with neighbouring
|
||||
# values, at least the plots are different
|
||||
|
||||
garment = garments[0]
|
||||
|
||||
mask = read_garment_mask(folder, id, garment)
|
||||
|
||||
if 'mesh_posed' in data_to_convert:
|
||||
mesh_posed = read_posed_garment(folder, id, garment, mask=mask, shape=info['shape'], poses=info['poses'], use_no_orient=use_no_orient, no_shape=no_shape)
|
||||
mesh_posed_frame = read_posed_garment_frame(folder, id, garment, 0, mask=mask, shape=info['shape'], pose=info['poses'][:,0], deorient=use_no_orient, unshape=no_shape)
|
||||
mesh_posed = read_posed_garment(folder, id, garment, mask=mask, shape=info['shape'], poses=info['poses'], deorient=use_no_orient, unshape=no_shape)
|
||||
if 'mesh_unposed' in data_to_convert:
|
||||
mesh_unposed = read_unposed_garment(folder, id, garment, mask=mask, shape=info['shape'], no_shape=no_shape)
|
||||
mesh_unposed = read_unposed_garment(folder, id, garment, mask=mask, shape=info['shape'], unshape=no_shape)
|
||||
if 'mesh_static' in data_to_convert:
|
||||
mesh_static = read_garment_template(folder, id, garment, mask)
|
||||
if 'mesh_curvature' in data_to_convert:
|
||||
mesh_curvature = compute_curvature(mesh_posed, F)
|
||||
mesh_curvature = read_curvatures(h5file, id, frames, neighbourhood=None)
|
||||
if 'body_posed' in data_to_convert:
|
||||
body_posed = read_posed_body(folder, id, info['poses'], use_no_orient)
|
||||
|
||||
@@ -442,33 +454,35 @@ if __name__ == '__main__':
|
||||
|
||||
start = time.perf_counter()
|
||||
|
||||
uv_verts_static, garment_uv_mask, garment_uv_mask_border = convert_to_uv(uv_res, m2uv, uv_map, verts_static, neighbours=3, mask=mask, method='rbf', garment_uv_mask=None)
|
||||
uv_verts_static = uv_verts_static.astype(np.float32)
|
||||
uv_static, uv_mask, garment_uv_mask_border = convert_to_uv(uv_res, m2uv, uv_map, mesh_static, neighbours=3, mask=mask, method='rbf', garment_uv_mask=None)
|
||||
uv_static = uv_static.astype(np.float32)
|
||||
|
||||
if 'mesh_posed' in data_to_convert:
|
||||
uv_posed = convert_to_uv_batch(uv_res, m2uv, uv_map, gt[:, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
|
||||
uv_posed = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_posed[:, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
|
||||
if 'mesh_unposed' in data_to_convert:
|
||||
uv_unposed = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_unposed[:, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
|
||||
uv_unposed = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_unposed[:, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
|
||||
if 'mesh_curvature' in data_to_convert:
|
||||
uv_curvature = convert_to_uv_batch_label(uv_res, m2uv, uv_map, curvature[:, :], neighbours=3, mask=mask, method='nearest', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
|
||||
uv_curvature = convert_to_uv_batch_label(uv_res, m2uv, uv_map, mesh_curvature[:, :], neighbours=3, mask=mask, method='nearest', garment_uv_mask=uv_mask, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
|
||||
if 'body_posed' in data_to_convert:
|
||||
uv_body_posed = convert_to_uv_batch(uv_res, m2uv, uv_map, body_posed[:, :, :], neighbours=3, mask=None, method='rbf', garment_uv_mask=None, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
|
||||
|
||||
print(time.perf_counter() - start)
|
||||
|
||||
|
||||
if 'mesh_static' in data_to_convert:
|
||||
# np.save(os.path.join(folder, id, garment + '_offsets_static_uv.npy'), uv_verts_static)
|
||||
# np.save(os.path.join(folder, id, 'mask_uv.npy'), garment_uv_mask)
|
||||
# mesh_static
|
||||
save_to_h5file(h5file, id, 0, garment, uv_static, 'uv_static', 'float32')
|
||||
save_to_h5file(h5file, id, 0, garment, uv_mask, 'uv_mask', 'float32')
|
||||
if 'mesh_posed' in data_to_convert:
|
||||
mesh_posed = read_posed_garment(folder, id, garment, mask=mask, shape=info['shape'], poses=info['poses'], use_no_orient=use_no_orient, no_shape=no_shape)
|
||||
for i in range(uv_posed.shape[0]):
|
||||
save_to_h5file(h5file, id, i, garment, uv_posed[i, :, :, :], 'uv_posed' + orient_mod + shape_mod, 'float32')
|
||||
if 'mesh_unposed' in data_to_convert:
|
||||
mesh_unposed = read_unposed_garment(folder, id, garment, mask=mask, shape=info['shape'], no_shape=no_shape)
|
||||
for i in range(uv_unposed.shape[0]):
|
||||
save_to_h5file(h5file, id, i, garment, uv_unposed[i, :, :, :], 'uv_unposed' + orient_mod + shape_mod, 'float32')
|
||||
if 'mesh_curvature' in data_to_convert:
|
||||
mesh_curvature = compute_curvature(mesh_posed, F)
|
||||
for i in range(uv_curvature.shape[0]):
|
||||
save_to_h5file(h5file, id, i, garment, uv_curvature[i, :, :, :], 'uv_curvature', 'uint8')
|
||||
if 'body_posed' in data_to_convert:
|
||||
# for i in range(uv_body_posed.shape[0]):
|
||||
# np.savez_compressed(os.path.join(folder, id, 'uv_body_posed', garment + '_' + str(i) + '.npz'), uv_body=uv_body[i, :, :, :])
|
||||
for i in range(uv_body_posed.shape[0]):
|
||||
save_to_h5file(h5file, id, i, garment, uv_body_posed[i, :, :, :], 'uv_body_posed', 'float32')
|
||||
|
||||
|
||||
# start = time.perf_counter()
|
||||
|
||||
Reference in New Issue
Block a user