trying to figx data generation

This commit is contained in:
2023-02-18 00:53:41 +00:00
parent a94be773d3
commit e0d1916901
6 changed files with 317 additions and 222 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"justMyCode": false, // true false
"cwd": "${workspaceFolder}"
}
]
+30 -15
View File
@@ -231,10 +231,6 @@ def read_posed_garment_frame(folder, id, garment, frame, map=None, mask=None, sh
map = sio.loadmat(os.path.join(folder, id, garment + '_map.mat'))['map'].reshape((-1))
verts = verts[map, :]
if unshape:
shape_offsets = np.tensordot(shape, shapedirs, axes=[[1], [2]])
verts[mask, :] = verts[mask, :] - np.squeeze(shape_offsets)[mask, :]
if deorient:
R = scipy.spatial.transform.Rotation.from_euler('xyz', pose[:3]).inv()
# R = scipy.spatial.transform.Rotation.from_euler([0,0,-zrot])
@@ -255,10 +251,6 @@ def read_posed_garment(folder, id, garment, map=None, mask=None, shape=None, sha
map = sio.loadmat(os.path.join(folder, id, garment + '_map.mat'))['map'].reshape((-1))
verts = verts[:, map, :]
if unshape:
shape_offsets = np.tensordot(shape, shapedirs, axes=[[1], [2]])
verts[:, mask, :] = verts[:, mask, :] - np.squeeze(shape_offsets)[None, mask, :]
if deorient:
for i in range(verts.shape[0]):
R = scipy.spatial.transform.Rotation.from_euler('xyz', poses[:3, i]).inv()
@@ -308,17 +300,40 @@ def read_posed_body(folder, id, poses=None, deorient=False):
return verts
def read_curvatures(h5file, id, garment, frames, neighbourhood=None):
# def read_curvatures(h5file, id, garment, frames, neighbourhood=None):
# frames_filtered = [frame for frame in frames if (frame.split()[0] == id and frame.split()[2] == garment)]
# if len(frames_filtered) == 0:
# print(f'No frames found for {id} {garment}')
# if len(frames_filtered[0].split()) < 3:
# print(f'No garment specified for {id} {garment}')
# print(frames_filtered[0].split())
# garment = frames_filtered[0].split()[2]
# curvatures_all = []
# for frame_nr in range(len(frames_filtered)):
# curv = h5file.get_node(f'/{id}/{frame_nr}/{garment}/curvature_raw').read()
# curvatures_all.append(curv)
# return np.array(curvatures_all)
def read_curvatures(folder, id, garment, frames=None, count=None, neighbourhood=None, per_garment=False):
if neighbourhood is not None:
raise NotImplementedError('Neighbourhood not implemented for reading curvatures')
if count is None:
frames_filtered = [frame for frame in frames if (frame.split()[0] == id and frame.split()[2] == garment)]
garment = frames_filtered[0].split()[2]
curvatures_all = []
for frame_nr in range(len(frames_filtered)):
curv = h5file.get_node(f'/{id}/{frame_nr}/{garment}/curvature_raw').read()
curvatures_all.append(curv)
return np.array(curvatures_all)
count = len(frames_filtered)
all = []
for i in range(count):
curv = np.load(os.path.join(folder, 'curvature_mesh_global' if not per_garment else 'curvature_mesh_garment', f'{id}_{i}_{garment}.npz'))['mesh_curvature_raw'] # not actually raw
all.append(curv)
return all
def read_curvature_frame(folder, id, garment, frame, neighbourhood=None, per_garment=False):
if neighbourhood is not None:
raise NotImplementedError('Neighbourhood not implemented for reading curvatures')
curv = np.load(os.path.join(folder, 'curvature_mesh_global' if not per_garment else 'curvature_mesh_garment', f'{id}_{frame}_{garment}.npz'))['mesh_curvature_raw'] # not actually raw
return curv
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')
+13 -74
View File
@@ -400,8 +400,8 @@ def get_shapedirs():
if __name__ == '__main__':
parser = argparse.ArgumentParser()
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=1000)
parser.add_argument("-s", "--start", help = "start of range", default=70500)
parser.add_argument("-e", "--end", help = "end of range", default=90000)
parser.add_argument("-n", "--name", help = "end of range", default='lhunor')
parser.add_argument("-sk", "--skirt", help = "end of range", default=0)
args = parser.parse_args()
@@ -463,16 +463,16 @@ if __name__ == '__main__':
root = '/'.join(folder.split('/')[:-1])
type = folder.split('/')[-1]
h5file_curv = tb.open_file(os.path.join(root, f'{type}_extras.h5'), mode='r')
# h5file_curv = tb.open_file(os.path.join(root, f'{type}_extras.h5'), mode='r')
# h5file = tb.open_file(os.path.join(root, f'{type}_extras_uv.h5'), mode='a')
extras_folder = os.path.join(root, f'{type}_extras')
os.makedirs(extras_folder, exist_ok=True)
os.makedirs(os.path.join(extras_folder, 'uv_posed'), exist_ok=True)
os.makedirs(os.path.join(extras_folder, 'uv_posed' + orient_mod), exist_ok=True)
os.makedirs(os.path.join(extras_folder, 'uv_static'), exist_ok=True)
os.makedirs(os.path.join(extras_folder, 'uv_curvature'), exist_ok=True)
os.makedirs(os.path.join(extras_folder, 'uv_unposed'), exist_ok=True)
os.makedirs(os.path.join(extras_folder, 'uv_body_posed'), exist_ok=True)
os.makedirs(os.path.join(extras_folder, 'uv_body_posed' + orient_mod), exist_ok=True)
os.makedirs(os.path.join(extras_folder, 'uv_mask'), exist_ok=True)
@@ -488,7 +488,12 @@ if __name__ == '__main__':
# also masking is not the same as just filling the empty values with neighbouring
# values, at least the plots are different
garment = garments[0]
for garment in garments:
# garment = garments[0]
# if all the uv maps have been generated, skip this id
# if all([os.path.exists(os.path.join(extras_folder, 'uv_body_posed' + orient_mod, f'{id}_{i}_{garment}.npz')) for i in range(info['poses'].shape[1])]):
# continue
mask = read_garment_mask(folder, id, garment)
@@ -501,38 +506,15 @@ if __name__ == '__main__':
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 = read_curvatures(h5file_curv, id, garment, frames, neighbourhood=None)
mesh_curvature = read_curvatures(folder + '_extras', id, garment, count=info['poses'].shape[1])
if 'body_posed' in data_to_convert:
body_posed = read_posed_body(folder, id, info['poses'], use_no_orient)
# verts_static = read_garment_template(folder, id, garment, mask)
# body = read_posed_body(folder, id, info['poses'], use_no_orient)
# gt = read_posed_garment(folder, id, garment, mask=mask, shape=info['shape'], ...)
# gt = readPC2(os.path.join(folder, id, garment + '_registered.pc16'), True)['V']
# curvature = np.stack([np.load(os.path.join(folder, f'mesh_curvature_{neighbourhood}_2', f'{id}_{i}.npz'))['mesh_curvature'] for i in range(frames_len)])
# mesh_unposed = [np.load(os.path.join(folder, id, 'mesh_unposed', id + '_' + str(i) + '.npz')) for i in range(gt.shape[0])]
# mesh_unposed = np.stack([mesh_unposed[i]['mesh_unposed'] for i in range(gt.shape[0])])
# mesh_unposed_no_shape = [np.load(os.path.join(folder, id, 'mesh_unposed_no_shape', id + '_' + str(i) + '.npz')) for i in range(gt.shape[0])]
# mesh_unposed_no_shape = np.stack([mesh_unposed_no_shape[i]['mesh_unposed_no_shape'] for i in range(gt.shape[0])])
# body_no_orient = [np.load(os.path.join(folder, id, 'mesh_posed_body_no_orient', id + '_' + str(i) + '.npz')) for i in range(gt.shape[0])]
# body_no_orient = np.stack([body_no_orient[i]['mesh_posed_body_no_orient'] for i in range(gt.shape[0])])
# mesh_unposed_no_shape_one_hot = [np.load(os.path.join(local_folder, 'mesh_unposed_no_shape_one_hot', id + '_' + str(i) + '.npz')) for i in range(frames)]
# mesh_unposed_no_shape_one_hot = [mesh_unposed_no_shape_one_hot[i]['mesh_unposed_no_shape'] for i in range(frames)]
# mesh_posed_no_orient = [np.load(os.path.join(local_folder, 'mesh_posed_no_orient', id + '_' + str(i) + '.npz')) for i in range(frames)]
# mesh_posed_no_orient = [mesh_posed_no_orient[i]['mesh_posed_no_orient'] for i in range(frames)]
# verts_dynamic = gt
# TODO: check if have to mask out non garment vertices or not? are they the same vertices erpeated many times? if remove, have to interpolate from almost nothing?
# test(data.f.Vt, data.f.Ft, verts)
# test(uv_map, data.f.Ft, verts)
start = time.perf_counter()
uv_static, uv_mask_local, 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 = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_static[None, :, :], neighbours=3, mask=mask, method='rbf', garment_uv_mask=uv_mask_local, garment_uv_mask_border=garment_uv_mask_border)
uv_static = uv_static.astype(np.float32)
if 'mesh_posed' in data_to_convert:
@@ -572,49 +554,6 @@ if __name__ == '__main__':
np.savez_compressed(os.path.join(extras_folder, 'uv_body_posed' + orient_mod, f'{id}_{i}_{garment}.npz'), uv_body_posed=uv_body_posed[i])
# save_to_h5file(h5file, id, i, garment, uv_body_posed[i, :, :, :], 'uv_body_posed', 'float32')
# start = time.perf_counter()
# np.save(os.path.join(folder, id, 'body_static_uv.npy'), uv_body_static)
# os.makedirs(os.path.join(folder, id, 'body_posed_uv'), exist_ok=True)
# for i in range(uv_body.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'body_posed_uv', garment + '_' + str(i) + '.npz'), uv_body=uv_body[i, :, :, :])
# os.makedirs(os.path.join(folder, id, 'uv_posed_body_no_orient'), exist_ok=True)
# for i in range(uv_posed_body_no_orient.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'uv_posed_body_no_orient', garment + '_' + str(i) + '.npz'), uv_posed_body_no_orient=uv_posed_body_no_orient[i, :, :, :])
# os.makedirs(os.path.join(folder, id, 'gt_uv'), exist_ok=True)
# for i in range(uv_gt.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'gt_uv', garment + '_' + str(i) + '.npz'), uv_gt=uv_gt[i, :, :, :])
# os.makedirs(os.path.join(folder, f'uv_curvature_{neighbourhood}_2'), exist_ok=True)
# for i in range(uv_curvature.shape[0]):
# np.savez_compressed(os.path.join(folder, f'uv_curvature_{neighbourhood}_2', id + '_' + str(i) + '.npz'), curvature_uv=uv_curvature[i, :, :])
# os.makedirs(os.path.join(folder, id, 'uv_unposed'), exist_ok=True)
# for i in range(uv_unposed.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'uv_unposed', garment + '_' + str(i) + '.npz'), uv_unposed=uv_unposed[i, :, :, :])
# os.makedirs(os.path.join(folder, id, 'uv_unposed_no_shape'), exist_ok=True)
# for i in range(uv_unposed_no_shape.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'uv_unposed_no_shape', garment + '_' + str(i) + '.npz'), uv_unposed_no_shape=uv_unposed_no_shape[i, :, :, :])
# os.makedirs(os.path.join(folder, id, 'uv_unposed_no_shape_one_hot'), exist_ok=True)
# for i in range(uv_unposed_no_shape_one_hot.shape[0]):
# np.savez_compressed(os.path.join(folder, id, 'uv_unposed_no_shape_one_hot', garment + '_' + str(i) + '.npz'), uv_unposed_no_shape=uv_unposed_no_shape_one_hot[i, :, :, :])
# os.makedirs(os.path.join(folder, id, 'uv_shaped_body'), exist_ok=True)
# np.savez_compressed(os.path.join(folder, id, 'uv_shaped_body.npz'), uv_shaped_body=uv_shaped_body)
# print(time.perf_counter() - start)
# mesh = uv_to_mesh(uv_verts_static, m2uv)
# verify_reconstruction(verts_static * mask[:, np.newaxis], mesh * mask[:, np.newaxis])
# mesh = uv_to_mesh(uv_body[0,:,:], m2uv)
# verify_reconstruction(body[0,:,:] * mask[:, np.newaxis], mesh * mask[:, np.newaxis])
pass
+70 -67
View File
@@ -103,37 +103,43 @@ class Cache:
def read(self, main_id):
frames = [frame for frame in self.frames if frame.split()[0] == main_id]
for frame in frames:
id = frame.split()[0]
garment = frame.split()[2]
if id in self.cache.keys():
continue
# frames = [frame for frame in self.frames if (frame.split()[0] == main_id.split()[0] and frame.split()[2] == main_id.split()[1])]
# for frame in frames:
id = main_id.split()[0]
garment = main_id.split()[1]
self.cache[id] = Data()
self.cache[f'{id} {garment}'] = Data()
is_skirt = (garment == 'Dress' or garment == 'Skirt')
mask = read_garment_mask(self.folder, id, garment)
_, faces = _maskFaces(np.zeros((14475,3)), F, mask)
_, faces = _maskFaces(np.zeros((14475,3)), F if not is_skirt else F_skirt, mask)
v = read_posed_garment_frame(folder, id, garment, 0)[mask,:]
m = tm.Trimesh(v, faces, process=False, validate=False)
outliers = np.array([len(v) for v in m.vertex_neighbors]) == 0
outliers = np.nonzero(outliers)[0]
outliers_n_neighbours = get_closest_n_points(v, outliers, 2)
outliers_faces = np.concatenate((outliers[:, np.newaxis], outliers_n_neighbours), axis=-1)
# sorted_faces = [sorted(f) for f in faces.astype(np.int64)]
# for outlier_face in outliers_faces:
# assert sorted(outlier_face) not in sorted_faces
faces = np.concatenate((faces, outliers_faces), axis=0)
m = tm.Trimesh(v, faces, process=False, validate=False)
if self.include_neighbours:
if not is_skirt:
k_neighbors = np.argsort(dist[mask, :][:, mask], axis=-1)[:, :self.neighbourhood]
self.cache[id].k_neighbors = k_neighbors
# G = tm.graph.vertex_adjacency_graph(m)
# for i in range(v.shape[0]):
# for k in range(25):
# assert nx.has_path(G, i, k_neighbors[i, k]), f'No path between {i} and {k_neighbors[i, k]}'
else:
k_neighbors = np.argsort(dist_skirt[mask, :][:, mask], axis=-1)[:, :self.neighbourhood]
self.cache[f'{id} {garment}'].k_neighbors = k_neighbors
G = tm.graph.vertex_adjacency_graph(m)
for i in range(v.shape[0]):
for k in range(25):
assert nx.has_path(G, i, k_neighbors[i, k]), f'No path between {i} and {k_neighbors[i, k]}'
self.cache[id].mask = mask
self.cache[id].faces = faces
self.cache[f'{id} {garment}'].mask = mask
self.cache[f'{id} {garment}'].faces = faces
def __getitem__(self, id):
if id not in self.cache.keys():
@@ -164,10 +170,10 @@ def calculate_dist(folder, neighbourhood, frames):
def generate_curvatures(folder, neighbourhood, frames):
# ids = os.listdir(folder)[int(args.start):int(args.end)]
# frames = frames[int(args.start):int(args.end)]
os.makedirs(os.path.join('/'.join(folder.split('/')[:-1]), 'backup', f'mesh_curvature_raw'), exist_ok=True)
os.makedirs(os.path.join(folder + '_extras', f'mesh_curvature_raw'), exist_ok=True)
cache = Cache(folder, neighbourhood, frames)
filters = tb.Filters(complevel=9, complib='blosc2')
# filters = tb.Filters(complevel=9, complib='blosc2')
for frame in tqdm.tqdm(frames):
@@ -175,29 +181,29 @@ def generate_curvatures(folder, neighbourhood, frames):
frame_nr = int(frame.split()[1])
garment = frame.split()[2]
mask = cache[id].mask
faces = cache[id].faces
mask = cache[f'{id} {garment}'].mask
faces = cache[f'{id} {garment}'].faces
v = read_posed_garment_frame(folder, id, garment, frame_nr)[mask,:]
m = tm.Trimesh(v, faces, process=False, validate=False)
export_to_ply(m, temp_file)
cloud = PyntCloud.from_file(temp_file)
k_neighbors = cache[id].k_neighbors
k_neighbors = cache[f'{id} {garment}'].k_neighbors
ev = cloud.add_scalar_field("eigen_values", k_neighbors=k_neighbors)
cloud.add_scalar_field("curvature", ev=ev)
curvature = np.array(cloud.points["curvature(" + str(neighbourhood+1) + ")"])
out = np.zeros((14475), dtype=np.float32)
out[mask] = curvature
out[mask] = curvature.real if str(curvature.dtype) == 'complex64' else curvature
np.savez_compressed(os.path.join('/'.join(folder.split('/')[:-1]), 'backup', f'mesh_curvature_raw', f'{id}_{frame_nr}_{garment}.npz'), mesh_curvature_raw=out)
group = h5file.get_node(f'/{id}/{frame_nr}/{garment}')
if f'curvature_raw' in group:
array = h5file.get_node(f'/{id}/{frame_nr}/{garment}/curvature_raw')
array[:] = out
else:
carray = h5file.create_carray(group, "curvature_raw", atom=tb.Float32Atom(), shape=out.shape, filters=filters)
carray[:] = out
np.savez_compressed(os.path.join(folder + '_extras', f'mesh_curvature_raw', f'{id}_{frame_nr}_{garment}.npz'), mesh_curvature_raw=out)
# group = h5file.get_node(f'/{id}/{frame_nr}/{garment}')
# if f'curvature_raw' in group:
# array = h5file.get_node(f'/{id}/{frame_nr}/{garment}/curvature_raw')
# array[:] = out
# else:
# carray = h5file.create_carray(group, "curvature_raw", atom=tb.Float32Atom(), shape=out.shape, filters=filters)
# carray[:] = out
return None
@@ -214,34 +220,34 @@ def get_bins(values, nr_of_bins):
def generate_curvature_labels(folder, bins, curvatures, frames, neighbourhood):
cache = Cache(folder, neighbourhood, frames, include_neighbours=False)
os.makedirs(os.path.join('/'.join(folder.split('/')[:-1]), 'backup', f'curvature_mesh_global'), exist_ok=True)
os.makedirs(os.path.join('/'.join(folder.split('/')[:-1]), 'backup', f'curvature_mesh_garment'), exist_ok=True)
os.makedirs(os.path.join(folder + '_extras', f'curvature_mesh_global'), exist_ok=True)
os.makedirs(os.path.join(folder + '_extras', f'curvature_mesh_garment'), exist_ok=True)
labels = np.linspace(0, bins.shape[0] - 2, bins.shape[0] - 1)
filters = tb.Filters(complevel=9, complib='blosc2')
# filters = tb.Filters(complevel=9, complib='blosc2')
for i, frame in enumerate(tqdm.tqdm(frames)):
id = frame.split()[0]
frame_nr = int(frame.split()[1])
garment = frame.split()[2]
curvature = curvatures[i][cache[id].mask]
curvature = curvatures[i][cache[f'{id} {garment}'].mask]
frame_labels = np.zeros((curvature.shape[0]), dtype=np.uint8)
for j in range(bins.shape[0] - 2):
frame_labels[(curvature >= bins[j]) * (curvature < bins[j+1])] = labels[j]
frame_labels[curvature >= bins[-2]] = labels[-1]
out = np.zeros((14475), dtype=np.uint8)
out[cache[id].mask] = frame_labels + 1
out[cache[f'{id} {garment}'].mask] = frame_labels + 1
group = h5file.get_node(f'/{id}/{frame_nr}/{garment}')
if f'curvature_mesh_global' in group:
array = h5file.get_node(f'/{id}/{frame_nr}/{garment}/curvature_mesh_global')
array[:] = out
else:
carray = h5file.create_carray(group, "curvature_mesh_global", atom=tb.UInt8Atom(), shape=out.shape, filters=filters)
carray[:] = out
# group = h5file.get_node(f'/{id}/{frame_nr}/{garment}')
# if f'curvature_mesh_global' in group:
# array = h5file.get_node(f'/{id}/{frame_nr}/{garment}/curvature_mesh_global')
# array[:] = out
# else:
# carray = h5file.create_carray(group, "curvature_mesh_global", atom=tb.UInt8Atom(), shape=out.shape, filters=filters)
# carray[:] = out
np.savez_compressed(os.path.join('/'.join(folder.split('/')[:-1]), 'backup', f'curvature_mesh_global', f'{id}_{frame_nr}_{garment}.npz'), mesh_curvature_raw=out)
np.savez_compressed(os.path.join(folder + '_extras', f'curvature_mesh_global', f'{id}_{frame_nr}_{garment}.npz'), mesh_curvature_raw=out)
# writePC2(os.path.join(garment_dir, "curvature_label_" + str(nr_of_labels) + "_" + str(neighbourhood) + ".pc16"), unmasked_label, True)
# redo it with local bins
@@ -251,17 +257,17 @@ def generate_curvature_labels(folder, bins, curvatures, frames, neighbourhood):
frame_labels[(curvature >= bins[j]) * (curvature < bins[j+1])] = labels[j]
frame_labels[curvature >= bins[-2]] = labels[-1]
out = np.zeros((14475), dtype=np.uint8)
out[cache[id].mask] = frame_labels + 1
out[cache[f'{id} {garment}'].mask] = frame_labels + 1
group = h5file.get_node(f'/{id}/{frame_nr}/{garment}')
if f'curvature_mesh_garment' in group:
array = h5file.get_node(f'/{id}/{frame_nr}/{garment}/curvature_mesh_garment')
array[:] = out
else:
carray = h5file.create_carray(group, "curvature_mesh_garment", atom=tb.UInt8Atom(), shape=out.shape, filters=filters)
carray[:] = out
# group = h5file.get_node(f'/{id}/{frame_nr}/{garment}')
# if f'curvature_mesh_garment' in group:
# array = h5file.get_node(f'/{id}/{frame_nr}/{garment}/curvature_mesh_garment')
# array[:] = out
# else:
# carray = h5file.create_carray(group, "curvature_mesh_garment", atom=tb.UInt8Atom(), shape=out.shape, filters=filters)
# carray[:] = out
np.savez_compressed(os.path.join('/'.join(folder.split('/')[:-1]), 'backup', f'curvature_mesh_garment', f'{id}_{frame_nr}_{garment}.npz'), mesh_curvature_raw=out)
np.savez_compressed(os.path.join(folder + '_extras', f'curvature_mesh_garment', f'{id}_{frame_nr}_{garment}.npz'), mesh_curvature_raw=out)
def visualize_curvature_labels(folder, frames):
@@ -319,6 +325,7 @@ def read_raw_curvatures(folder, frames, neighbourhood):
return curvatures_all
def read_raw_curvatures_2(folder, frames, neighbourhood):
curvatures_all = []
for frame in tqdm.tqdm(frames):
@@ -335,14 +342,13 @@ def read_raw_curvatures_2(folder, frames, neighbourhood):
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--folder", help = "process the given folder", default=r'/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=600000)
parser.add_argument("-s", "--start", help = "start of range", default=300)
parser.add_argument("-e", "--end", help = "end of range", default=600)
parser.add_argument("-n", "--name", help = "end of range", default="lhunor")
args = parser.parse_args()
is_skirt = False
skirt_modifier = '_skirt' if is_skirt else ''
F = np.load("custom_utils/smpl_faces" + skirt_modifier + ".npy").astype(np.int32)
F = np.load("custom_utils/smpl_faces.npy").astype(np.int32)
F_skirt = np.load("custom_utils/smpl_faces_skirt.npy").astype(np.int32)
# k_neighbours(k=25)
@@ -353,13 +359,10 @@ if __name__ == '__main__':
neighbourhood = 25
temp_file = '/home/workspace/local-data/temp/' + ''.join(random.choice(string.ascii_lowercase) for i in range(10)) + '.ply'
if not is_skirt:
dist = np.load('custom_data/dijkstra.npy')
else:
dist = np.load('custom_data/dijkstra_skirt.npy')
dist_skirt = np.load('custom_data/dijkstra_skirt.npy')
print('SKIRT' if is_skirt else 'NOT SKIRT')
print(f'params: -f {args.folder} -s {args.start} -e {args.end} -n {args.name} -skirt {is_skirt} -neigh {neighbourhood}')
print(f'params: -f {args.folder} -s {args.start} -e {args.end} -n {args.name} -neigh {neighbourhood}')
# frames = sorted(os.listdir(os.path.join(folder, 'mesh_posed')))[int(args.start):int(args.end)]
# frames = [frame.split('.')[0] for frame in frames]
@@ -372,21 +375,21 @@ if __name__ == '__main__':
root = '/'.join(folder.split('/')[:-1])
type = folder.split('/')[-1]
h5file = tb.open_file(os.path.join(root, f'{type}_extras.h5'), mode='a')
# h5file = tb.open_file(os.path.join(root, f'{type}_extras.h5'), mode='a')
start = time.perf_counter()
# frames = [f'05235 {i} Tshirt' for i in range(300)]
# generate_curvatures(folder, neighbourhood, frames)
curvatures = read_raw_curvatures(folder, frames, neighbourhood)
generate_curvatures(folder, neighbourhood, frames)
# curvatures = read_raw_curvatures_2(folder, frames, neighbourhood)
# bins = get_bins(curvatures, nr_of_labels)
# np.save(f'custom_data/{type}_bins{skirt_modifier}_{neighbourhood}.npy', bins)
# print(bins)
bins = np.load(f'custom_data/{type}_bins{skirt_modifier}_{neighbourhood}.npy')
generate_curvature_labels(folder, bins, curvatures, frames, neighbourhood)
# bins = np.load(f'custom_data/{type}_bins_{neighbourhood}.npy')
# generate_curvature_labels(folder, bins, curvatures, frames, neighbourhood)
# visualize_curvature_labels(folder, frames)
print(time.perf_counter() - start)
h5file.close()
pass
+138
View File
@@ -0,0 +1,138 @@
import os
import sys
import random
import numpy as np
import tables as tb
import plotly.graph_objects as go
import plotly.express as ex
from plotly.subplots import make_subplots
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, read_curvatures, read_curvature_frame
from custom_utils.custom_utils import _maskFaces
def get_frames(folder, frames_file):
frames = []
with open(os.path.join(folder, frames_file), 'r') as f:
for line in f:
frames.append(line.strip())
return frames
def verify_uv(folder, frame):
id, frame_nr, garment = frame.split()
uv_static = np.load(os.path.join(folder, 'uv_static', f'{id}_{garment}.npz'))['uv_static']
uv_mask = np.load(os.path.join(folder, 'uv_mask', f'{id}_{garment}.npz'))['uv_mask']
uv_posed = np.load(os.path.join(folder, 'uv_posed' + orient_mod, f'{id}_{frame_nr}_{garment}.npz'))['uv_posed']
uv_body_posed = np.load(os.path.join(folder, 'uv_body_posed' + orient_mod, f'{id}_{frame_nr}_{garment}.npz'))['uv_body_posed']
uv_curvature = np.load(os.path.join(folder, 'uv_curvature', f'{id}_{frame_nr}_{garment}.npz'))['uv_curvature']
all_1 = np.concatenate([uv_static, uv_posed, uv_body_posed], axis=1)
all_1 = (all_1 - all_1.min()) / (all_1.max() - all_1.min())
ex.imshow(all_1).show()
ex.imshow(uv_mask).show()
ex.imshow(uv_curvature).show()
def verify_mesh(folder, frame):
id, frame_nr, garment = frame.split()
frame_nr = int(frame_nr)
info = loadInfo(os.path.join(folder, id, 'info.mat'))
mask = read_garment_mask(folder, id, garment)
mesh_static = read_garment_template(folder, id, garment, mask)[mask,:]
mesh_posed = read_posed_garment_frame(folder, id, garment, frame_nr, mask=mask, shape=info['shape'], pose=info['poses'][:,frame_nr], deorient=use_no_orient, unshape=no_shape)[mask,:]
body_posed = read_posed_body_frame(folder, id, frame_nr, info['poses'], use_no_orient)
mesh_curvature = read_curvature_frame(folder + '_extras', id, garment, frame_nr)[mask]
fig = make_subplots(rows=1, cols=4, start_cell="top-left", specs = [ [{ 'type': 'scene' } for _ in range(4)] ])
F = np.load(f'custom_utils/smpl_faces{skirt_modifier}.npy').astype(np.int32)
_, faces = _maskFaces(np.zeros((14475,3)), F, mask)
fig.add_trace(go.Mesh3d(
x=mesh_static[:,0],
y=mesh_static[:,1],
z=mesh_static[:,2],
i = faces[:,0],
j = faces[:,1],
k = faces[:,2]
),
row=1, col=1)
fig.add_trace(go.Mesh3d(
x=mesh_posed[:,0],
y=mesh_posed[:,1],
z=mesh_posed[:,2],
i = faces[:,0],
j = faces[:,1],
k = faces[:,2]
),
row=1, col=2)
fig.add_trace(go.Mesh3d(
x=body_posed[:,0],
y=body_posed[:,1],
z=body_posed[:,2],
i = F[:,0],
j = F[:,1],
k = F[:,2],
),
row=1, col=3)
fig.add_trace(go.Mesh3d(
x=mesh_posed[:,0],
y=mesh_posed[:,1],
z=mesh_posed[:,2],
i = faces[:,0],
j = faces[:,1],
k = faces[:,2],
vertexcolor=np.tile(mesh_curvature[:,None], (1,3)) * 40,
),
row=1, col=4)
fig.update_layout(scene_aspectmode='manual', scene_aspectratio=dict(x=1, y=1, z=1),
scene2_aspectmode='manual', scene2_aspectratio=dict(x=1, y=1, z=1),
scene3_aspectmode='manual', scene3_aspectratio=dict(x=1, y=1, z=1),
scene4_aspectmode='manual', scene4_aspectratio=dict(x=1, y=1, z=1),
)
helper = dict(xaxis = dict(nticks=4, range=[-1,1],),
yaxis = dict(nticks=4, range=[-1,1],),
zaxis = dict(nticks=4, range=[-1,1],),)
fig.update_layout(scene = helper,
scene2 = helper,
scene3 = helper,
scene4 = helper,
)
fig.show()
pass
if __name__ == '__main__':
folder = '/home/workspace/data/dataset/cloth3d/train'
frames = get_frames(folder, 'frames_all.txt')
root = '/'.join(folder.split('/')[:-1])
type = folder.split('/')[-1]
# h5file_curv = tb.open_file(os.path.join(root, f'{type}_extras.h5'), mode='r')
use_no_orient = False
no_shape = False
is_skirt = True
skirt_modifier = '_skirt' if is_skirt else ''
orient_mod = '_no_orient' if use_no_orient else ''
shape_mod = '_no_shape' if no_shape else ''
while True:
frame = random.choice(frames)
frame = '05936 0 Dress'
verify_mesh(folder, frame)
verify_uv(folder + '_extras', frame)
pass
+4 -4
View File
@@ -12,16 +12,16 @@ if __name__ == '__main__':
# ids = os.listdir(folder + '/mesh_posed_no_orient')#[280000:]
skirt = 0
count = 0
step = 100
count = int(500 * 1e3)
step = 10000
# !!!!!!! change skirt parameter in script
while count < 2000:
while count < 510 * 1e3:
# os.system('nohup python convert_to_uv_cape.py -f ' + folder + ' -s ' + str(count) + ' -e ' + str(count + step) + ' -n ' + 'to_uv_2_cape_train_male_' + str(count) + '_' + str(count+step) + ' > nohup/to_uv_2_cape_train_male_' + str(count) + '_' + str(count+step) + '.out' + ' 2>&1 &')
# os.system('nohup python convert_to_uv.py -f ' + folder + ' -s ' + str(count) + ' -e ' + str(count + step) + ' -n ' + 'to_uv_train_unposed_onehot_' + str(count) + '_' + str(count+step) + ' > nohup/to_uv_train_unposed_onehot_' + str(count) + '_' + str(count+step) + '.out' + ' 2>&1 &')
# os.system('nohup python convert_to_uv_local.py -f ' + folder + ' -s ' + str(count) + ' -e ' + str(count + step) + ' -n ' + 'to_uv_train_local_unposed_onehot_' + str(count) + '_' + str(count+step) + ' > nohup/to_uv_train_local_unposed_onehot_' + str(count) + '_' + str(count+step) + '.out' + ' 2>&1 &')
os.system('nohup python data/convert_to_uv.py -f ' + folder + ' -s ' + str(count) + ' -e ' + str(count + step) + ' -n ' + 'to_uv_train_' + str(count) + '_' + str(count+step) + ' > nohup/to_uv/train_' + str(count) + '_' + str(count+step) + '.out' + ' 2>&1 &')
os.system('nohup python data/convert_to_uv.py -f ' + folder + ' -s ' + str(count) + ' -e ' + str(count + step) + ' -n ' + 'to_uv_train_2_' + str(count) + '_' + str(count+step) + ' > nohup/to_uv/train_2_' + str(count) + '_' + str(count+step) + '_again.out' + ' 2>&1 &')
# os.system('nohup python convert_to_uv_local_single.py -f ' + folder + ' -s ' + str(count) + ' -e ' + str(count + step) + ' -n ' + 'to_uv_train_skirt_local_unposed_onehot_3_' + str(count) + '_' + str(count+step) + ' > nohup/to_uv_train_skirt_local_unposed_onehot_3_' + str(count) + '_' + str(count+step) + '.out' + ' 2>&1 &')
# os.system('nohup python convert_to_uv_local_single.py -f ' + folder + ' -s ' + str(count) + ' -e ' + str(count + step) + ' -n ' + 'to_uv_valid_skirt_local_unposed_onehot_3_' + str(count) + '_' + str(count+step) + ' > nohup/to_uv_valid_skirt_local_unposed_onehot_' + str(count) + '_' + str(count+step) + '.out' + ' 2>&1 &')
# os.system('nohup python downscale.py -f ' + folder + ' -s ' + str(count) + ' -e ' + str(count + step) + ' -n ' + 'downscale_valid_posed_no_orient_' + str(count) + '_' + str(count+step) + ' > nohup/downscale_valid_posed_no_orient_' + str(count) + '_' + str(count+step) + '.out' + ' 2>&1 &')