generate curv with different radius
This commit is contained in:
@@ -384,9 +384,9 @@ def test(verts, faces, values):
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-f", "--folder", help = "end of range", default='/home/workspace/local-data/valid')
|
||||
parser.add_argument("-f", "--folder", help = "end of range", default='/home/workspace/local-data/valid_skirt')
|
||||
parser.add_argument("-s", "--start", help = "start of range", default=0)
|
||||
parser.add_argument("-e", "--end", help = "end of range", default=1500)
|
||||
parser.add_argument("-e", "--end", help = "end of range", default=30000)
|
||||
parser.add_argument("-n", "--name", help = "end of range", default='lhunor')
|
||||
parser.add_argument("-sk", "--skirt", help = "end of range", default=1)
|
||||
args = parser.parse_args()
|
||||
@@ -408,7 +408,7 @@ if __name__ == '__main__':
|
||||
m2uv = np.load('custom_utils/m2uv' + ("_skirt" if args.skirt == 1 else "") + '.npy', allow_pickle=True).item()
|
||||
m2uv = m2uv_array(m2uv)
|
||||
uv_mask = np.load('custom_utils/mask_256x512' + ("_skirt" if args.skirt == 1 else "") + '.npy')
|
||||
curvature_label_type = '6_25'
|
||||
curvature_label_type = '6_25 '
|
||||
|
||||
uv_res = 256
|
||||
uv_mask = (cv2.resize(uv_mask * 255.0, (uv_res, uv_res * 2)) / 255).astype(bool)[:, :, np.newaxis]
|
||||
@@ -436,9 +436,23 @@ if __name__ == '__main__':
|
||||
|
||||
# ids = os.listdir(os.path.join(local_folder, 'mesh_static'))[int(args.start):int(args.end)]
|
||||
# ids = [id.split('.')[0] for id in ids]
|
||||
ids = os.listdir(os.path.join(local_folder, 'pose_shape'))
|
||||
ids = [id.split('_')[0] for id in ids]
|
||||
ids = sorted(list(set(ids)))[int(args.start):int(args.end)]
|
||||
|
||||
is_skirt = True if args.skirt == 1 else False
|
||||
skirt_modifier = '_skirt' if is_skirt else ''
|
||||
|
||||
folder = args.folder
|
||||
frames_file = 'frames' + skirt_modifier + '_10p.txt'
|
||||
neighbourhood = 10
|
||||
|
||||
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 = os.listdir(os.path.join(local_folder, 'pose_shape'))
|
||||
ids = [frame.split('_')[0] for frame in frames]
|
||||
ids = sorted(list(set(ids)))#[int(args.start):int(args.end)]
|
||||
|
||||
for id in tqdm.tqdm(ids):
|
||||
|
||||
@@ -452,16 +466,16 @@ if __name__ == '__main__':
|
||||
# plt.show()
|
||||
# pass
|
||||
|
||||
frames = glob.glob(os.path.join(local_folder, 'pose_shape', id + '_*'))
|
||||
frames = len(frames)
|
||||
assert frames <= 300
|
||||
frames_len = glob.glob(os.path.join(local_folder, 'pose_shape', id + '_*'))
|
||||
frames_len = len(frames_len)
|
||||
assert frames_len <= 300
|
||||
|
||||
# offsets = sio.loadmat(os.path.join(folder, id, garment + '_offsets_static.mat'))['label'][:,:3]
|
||||
verts_static = np.load(os.path.join(local_folder, 'mesh_static', id + '.npz'))['mesh_static']
|
||||
mask = np.load(os.path.join(local_folder, 'mesh_mask', id + '.npy')).astype(bool)
|
||||
# body = readPC2(os.path.join(folder, id, 'Body_posed.pc16'), True)['V']
|
||||
# gt = readPC2(os.path.join(folder, id, garment + '_registered.pc16'), True)['V']
|
||||
# curvature = np.load(os.path.join(folder, id, 'curvature_label_' + curvature_label_type + '.npy'))
|
||||
curvature = np.stack([np.load(os.path.join(local_folder, f'mesh_curvature_{neighbourhood}', 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])]
|
||||
@@ -470,8 +484,8 @@ if __name__ == '__main__':
|
||||
# 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)]
|
||||
# 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
|
||||
@@ -491,11 +505,11 @@ if __name__ == '__main__':
|
||||
# uv_body = convert_to_uv_batch(uv_res, m2uv, uv_map, body[:, :, :], neighbours=3, mask=None, method='rbf', garment_uv_mask=None, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
|
||||
# uv_posed_body_no_orient = convert_to_uv_batch(uv_res, m2uv, uv_map, body_no_orient[:, :, :], neighbours=3, mask=None, method='rbf', garment_uv_mask=None, garment_uv_mask_border=garment_uv_mask_border).astype(np.float32)
|
||||
# uv_gt = 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_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, 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_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_no_shape = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_unposed_no_shape[:, :, :], 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_no_shape_one_hot = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_unposed_no_shape_one_hot, neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border, id=id)
|
||||
uv_posed_no_orient = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_posed_no_orient, neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border, id=id)
|
||||
# uv_posed_no_orient = convert_to_uv_batch(uv_res, m2uv, uv_map, mesh_posed_no_orient, neighbours=3, mask=mask, method='rbf', garment_uv_mask=garment_uv_mask, garment_uv_mask_border=garment_uv_mask_border, id=id)
|
||||
# uv_shaped_body = convert_to_uv(uv_res, m2uv, uv_map, shaped_body, neighbours=3, mask=None, method='rbf', garment_uv_mask=None).astype(np.float32)
|
||||
print(time.perf_counter() - start)
|
||||
|
||||
@@ -516,9 +530,9 @@ if __name__ == '__main__':
|
||||
# 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, id, 'curvature_uv'), exist_ok=True)
|
||||
# for i in range(uv_curvature.shape[0]):
|
||||
# np.savez_compressed(os.path.join(folder, id, 'curvature_uv', garment + '_' + str(i) + '.npz'), curvature_uv=uv_curvature[i, :, :])
|
||||
os.makedirs(os.path.join(folder, id, f'curvature_uv_{neighbourhood}'), exist_ok=True)
|
||||
for i in range(uv_curvature.shape[0]):
|
||||
np.savez_compressed(os.path.join(folder, id, f'curvature_uv_{neighbourhood}', 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]):
|
||||
|
||||
+20
-52
@@ -153,41 +153,23 @@ def get_bins(values, nr_of_bins):
|
||||
return bins
|
||||
|
||||
|
||||
def generate_curvature_labels(folder, bins, curvatures):
|
||||
def generate_curvature_labels(folder, bins, curvatures, frames, neighbourhood):
|
||||
|
||||
ids = os.listdir(folder)#[:10]
|
||||
os.makedirs(os.path.join(folder, f'mesh_curvature_{neighbourhood}'), exist_ok=True)
|
||||
labels = np.linspace(0, bins.shape[0] - 2, bins.shape[0] - 1)
|
||||
|
||||
i = 0
|
||||
for id in tqdm.tqdm(ids):
|
||||
garment_dir = os.path.join(folder, id)
|
||||
|
||||
if not os.path.isdir(garment_dir):
|
||||
continue
|
||||
|
||||
garments = [f.replace('.pc16','') for f in os.listdir(garment_dir) if f.find('_') == -1 and f != 'info.mat' and not f.endswith('.obj')]
|
||||
# assert len (garments) == 1
|
||||
if len (garments) != 1:
|
||||
continue
|
||||
garment = garments[0]
|
||||
mask = np.squeeze(sio.loadmat(os.path.join(garment_dir, garment + '_mask.mat'))['mask'].astype(bool))
|
||||
|
||||
for i, frame in enumerate(tqdm.tqdm(frames)):
|
||||
# id = frame.split('_')[0]
|
||||
# mask = np.load(os.path.join(folder, 'mesh_mask', f'{id}.npy'))
|
||||
# print(i)
|
||||
curvature = curvatures[i]
|
||||
i += 1
|
||||
|
||||
curvature_label = np.zeros((curvature.shape[0], curvature.shape[1]))
|
||||
frame = 0
|
||||
for frame in range(curvature.shape[0]):
|
||||
frame_labels = np.zeros((curvature.shape[1]), dtype=np.float32)
|
||||
for j in range(bins.shape[0] - 2):
|
||||
frame_labels[(curvature[frame, :] >= bins[j]) * (curvature[frame, :] < bins[j+1])] = labels[j]
|
||||
frame_labels[curvature[frame, :] >= bins[-2]] = labels[-1]
|
||||
curvature_label[frame, :] = frame_labels
|
||||
frame += 1
|
||||
frame_labels = np.zeros((curvature.shape[0]), dtype=np.float32)
|
||||
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]
|
||||
|
||||
unmasked_label = np.zeros((curvature.shape[0], 14475), dtype=np.float32)
|
||||
unmasked_label[:, mask] = curvature_label
|
||||
np.save(os.path.join(garment_dir, "curvature_label_" + str(nr_of_labels) + "_" + str(neighbourhood) + ".npy"), unmasked_label)
|
||||
np.savez_compressed(os.path.join(folder, f'mesh_curvature_{neighbourhood}', f'{frame}.npz'), mesh_curvature=frame_labels)
|
||||
# writePC2(os.path.join(garment_dir, "curvature_label_" + str(nr_of_labels) + "_" + str(neighbourhood) + ".pc16"), unmasked_label, True)
|
||||
|
||||
|
||||
@@ -258,24 +240,10 @@ def visualize_curvature_labels(folder):
|
||||
print()
|
||||
|
||||
|
||||
def read_raw_curvatures(folder):
|
||||
|
||||
ids = os.listdir(folder)[int(args.start):int(args.end)]
|
||||
|
||||
def read_raw_curvatures(folder, frames, neighbourhood):
|
||||
curvatures_all = []
|
||||
|
||||
for id in tqdm.tqdm(ids):
|
||||
garment_dir = os.path.join(folder, id)
|
||||
|
||||
if not os.path.isdir(garment_dir):
|
||||
continue
|
||||
|
||||
garments = [f.replace('.pc16','') for f in os.listdir(garment_dir) if f.find('_') == -1 and f != 'info.mat' and not f.endswith('.obj')]
|
||||
# assert len (garments) == 1
|
||||
if len (garments) != 1:
|
||||
continue
|
||||
|
||||
curv = np.load(garment_dir + '/curvature_25_raw.npy')
|
||||
for frame in tqdm.tqdm(frames):
|
||||
curv = np.load(os.path.join(folder, f'mesh_curvature_raw_{neighbourhood}', f'{frame}.npz'))['mesh_curvature_raw']
|
||||
curvatures_all.append(curv)
|
||||
|
||||
return curvatures_all
|
||||
@@ -283,9 +251,9 @@ def read_raw_curvatures(folder):
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-f", "--folder", help = "process the given folder", default=r'/home/workspace/local-data/valid_skirt')
|
||||
parser.add_argument("-f", "--folder", help = "process the given folder", default=r'/home/workspace/data/dataset/local-cache/train_skirt')
|
||||
parser.add_argument("-s", "--start", help = "start of range", default=0)
|
||||
parser.add_argument("-e", "--end", help = "end of range", default=10)
|
||||
parser.add_argument("-e", "--end", help = "end of range", default=30000)
|
||||
parser.add_argument("-n", "--name", help = "end of range", default="lhunor")
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -315,12 +283,12 @@ if __name__ == '__main__':
|
||||
lines = [line.strip() for line in lines]
|
||||
frames = lines[int(args.start):int(args.end)]
|
||||
|
||||
generate_curvatures(folder, neighbourhood, frames)
|
||||
# curvatures = read_raw_curvatures(folder)
|
||||
# generate_curvatures(folder, neighbourhood, frames)
|
||||
curvatures = read_raw_curvatures(folder, frames, neighbourhood)
|
||||
# bins = get_bins(curvatures, nr_of_labels)
|
||||
# np.save('train_bins_skirt.npy', bins)
|
||||
# bins = np.load('train_bins.npy')
|
||||
# generate_curvature_labels(folder, bins, curvatures)
|
||||
bins = np.load('custom_data/train_bins_skirt.npy')
|
||||
generate_curvature_labels(folder, bins, curvatures, frames, neighbourhood)
|
||||
# visualize_curvature_labels(folder)
|
||||
|
||||
pass
|
||||
Binary file not shown.
Binary file not shown.
+4
-4
@@ -4,7 +4,7 @@ import os
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
folder = '/home/workspace/data/dataset/test_skirt_ready_2'
|
||||
folder = '/home/workspace/data/dataset/local-cache/train_skirt'
|
||||
# folder = '/home/workspace/local-data/cape_processed/train/male'
|
||||
# folder = '/home/workspace/local-data/valid_skirt'
|
||||
# folder = '/home/workspace/local-data/valid'
|
||||
@@ -13,15 +13,15 @@ if __name__ == '__main__':
|
||||
skirt = 0
|
||||
|
||||
count = 0
|
||||
step = 2000
|
||||
step = 5000
|
||||
|
||||
# !!!!!!! change skirt parameter in script
|
||||
|
||||
while count < len(ids):
|
||||
while count < 30000:
|
||||
# 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 convert_to_uv_local_single.py -f ' + folder + ' -s ' + str(count) + ' -e ' + str(count + step) + ' -n ' + 'to_uv_posed_no_orient_test_skirt_ready_' + str(count) + '_' + str(count+step) + ' > nohup/to_uv_posed_no_orient_test_skirt_ready_' + 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_curv_10_train_skirt_' + str(count) + '_' + str(count+step) + ' > nohup/to_uv_curv_10_train_skirt_' + 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_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 &')
|
||||
|
||||
Reference in New Issue
Block a user