Spaces:
Paused
Paused
File size: 52,377 Bytes
27bc948 9c92c05 27bc948 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 |
import numpy as np
import os
import json
from scipy.spatial.transform import Rotation as R
import numpy as np
from scipy.spatial.transform import Rotation as R
# Import centralized configuration for path management
try:
from cube3d.config import get_mapping_paths
print("Successfully imported config from cube3d.config")
except ImportError as e:
print(f"Import from cube3d.config failed: {e}")
try:
from config import get_mapping_paths
print("Successfully imported config from config")
except ImportError as e:
print(f"Failed to import config: {e}")
raise ImportError("Failed to import get_mapping_paths from cube3d.config or config")
# from cube3d.training.check_rotation_onehot import rot_to_onehot24, onehot24_to_rot
# #from check_rotation_onehot import rot_to_onehot24, onehot24_to_rot
try:
from cube3d.training.check_rotation_onehot import (
rot_to_onehot24,
onehot24_to_rot,
signed_perm_mats_det_plus_1
)
print("Successfully imported from cube3d.training.check_rotation_onehot")
except ImportError as e:
print(f"Import from cube3d.training.check_rotation_onehot failed: {e}")
try:
from check_rotation_onehot import (
rot_to_onehot24,
onehot24_to_rot,
signed_perm_mats_det_plus_1
)
print("Successfully imported from check_rotation_onehot")
except ImportError as e:
print(f"Import from check_rotation_onehot failed: {e}")
raise ImportError(
"Failed to import rot_to_onehot24, onehot24_to_rot, "
"and signed_perm_mats_det_plus_1 from both "
"cube3d.training.check_rotation_onehot and check_rotation_onehot"
)
def rotation_to_onehot(rotation_matrix):
possible_angles = [0, 90, 180, 270]
# 初始化一个64维的one-hot编码
one_hot = np.zeros(64)
#import ipdb; ipdb.set_trace()
try:
#import ipdb; ipdb.set_trace()
x_angle = possible_angles.index(round(np.arctan2(np.round(rotation_matrix[2, 1], 1), np.round(rotation_matrix[2, 2],1)) * 180 / np.pi) % 360)
y_angle = possible_angles.index(round(np.arctan2(np.round(rotation_matrix[2, 0], 1), np.round(rotation_matrix[2, 2],1)) * 180 / np.pi) % 360)
z_angle = possible_angles.index(round(np.arctan2(np.round(rotation_matrix[1, 0], 1), np.round(rotation_matrix[0, 0],1)) * 180 / np.pi) % 360)
# 根据x, y, z的旋转角度组合确定one-hot的索引
index = x_angle * 16 + y_angle * 4 + z_angle
except Exception as e:
modified_matrix = rotation_matrix.copy()
max_vals = np.max(np.abs(modified_matrix), axis=1) # 每行最大绝对值
sign_matrix = np.sign(modified_matrix)
modified_matrix = sign_matrix * (np.abs(modified_matrix) == max_vals[:, None])
x_angle = possible_angles.index(round(np.arctan2(np.round(modified_matrix[2, 1], 1), np.round(modified_matrix[2, 2],1)) * 180 / np.pi) % 360)
y_angle = possible_angles.index(round(np.arctan2(np.round(modified_matrix[2, 0], 1), np.round(modified_matrix[2, 2],1)) * 180 / np.pi) % 360)
z_angle = possible_angles.index(round(np.arctan2(np.round(modified_matrix[1, 0], 1), np.round(modified_matrix[0, 0],1)) * 180 / np.pi) % 360)
index = x_angle * 16 + y_angle * 4 + z_angle
if index >= 64:
print(f"Error occurred: {e}")
with open("rotation_matrix_300_afterroundafter1_error_log.txt", "a") as file: # 使用 "a" 模式追加内容
file.write(f"Error with rotation matrix:\n{np.round(modified_matrix, 1)}\n")
file.write("-" * 50 + "\n") # 可选:添加分隔符,帮助区分不同错误
one_hot[index] = 1
return one_hot
import numpy as np
def onehot_to_rotation(one_hot):
# 定义可能的角度
possible_angles = [0, 90, 180, 270]
# 获取one-hot编码中的索引位置
index = one_hot.argmax() # 找到值为1的那个位置,即索引
# 根据索引推导出x、y、z的角度
x_angle = possible_angles[(index // 16) % 4] # x轴旋转角度
y_angle = possible_angles[(index // 4) % 4] # y轴旋转角度
z_angle = possible_angles[index % 4] # z轴旋转角度
# 根据这些角度构建旋转矩阵
# 构建绕X轴旋转矩阵
Rx = np.array([[1, 0, 0],
[0, np.cos(np.radians(x_angle)), -np.sin(np.radians(x_angle))],
[0, np.sin(np.radians(x_angle)), np.cos(np.radians(x_angle))]])
# 构建绕Y轴旋转矩阵
Ry = np.array([[np.cos(np.radians(y_angle)), 0, np.sin(np.radians(y_angle))],
[0, 1, 0],
[-np.sin(np.radians(y_angle)), 0, np.cos(np.radians(y_angle))]])
# 构建绕Z轴旋转矩阵
Rz = np.array([[np.cos(np.radians(z_angle)), -np.sin(np.radians(z_angle)), 0],
[np.sin(np.radians(z_angle)), np.cos(np.radians(z_angle)), 0],
[0, 0, 1]])
# 将这三个矩阵相乘得到总的旋转矩阵
rotation_matrix = np.dot(Rz, np.dot(Ry, Rx))
return rotation_matrix
def load_mappings(label_mapping_file, label_inverse_mapping_file):
print(f"🔍 [DEBUG] load_mappings() called")
print(f" Forward file: {label_mapping_file}")
print(f" Inverse file: {label_inverse_mapping_file}")
try:
with open(label_mapping_file, 'r') as f:
label_mapping = json.load(f)
print(f" ✅ Forward mapping loaded: {len(label_mapping)} entries")
except Exception as e:
print(f" ❌ Failed to load forward mapping: {e}")
raise
try:
with open(label_inverse_mapping_file, 'r') as f:
label_inverse_mapping = json.load(f)
print(f" ✅ Inverse mapping loaded: {len(label_inverse_mapping)} entries")
except Exception as e:
print(f" ❌ Failed to load inverse mapping: {e}")
raise
return label_mapping, label_inverse_mapping
# 读取LDR文件,逐行读取
def read_ldr_file(file_path):
with open(file_path, 'r') as f:
return f.readlines()
# 处理LDR文件并提取数据
def process_ldr_data(lines):
data = []
filenames = []
all_coords = []
all_colors = []
all_labels = []
label_mapping = {}
label_inverse_mapping = {}
# Use config-based paths (works in both local and HF Space environments)
forward_path, inverse_path = get_mapping_paths("subset_self")
label_mapping, label_inverse_mapping = load_mappings(forward_path, inverse_path)
label_counter = 0
max_x = 212
max_y = 216
max_z = 528
for line in lines:
if line.startswith('1'): # 只处理零件数据行
parts = line.split() # 按空格分割每一列数据
# if len(parts) != 15: # 检查是否每行都有15个部分 #这里也有问题
# print(f"Skipping line due to unexpected length: {line.strip()}")
# continue # 如果数据不完整,则跳过该行
color = int(parts[1]) # 颜色
x, y, z = round(float(parts[2])), round(float(parts[3])), round(float(parts[4]))
rx = list(map(float, parts[5:8])) # 旋转矩阵第一行
ry = list(map(float, parts[8:11])) # 旋转矩阵第二行
rz = list(map(float, parts[11:14])) # 旋转矩阵第三行
filename = parts[14] # 文件名
all_coords.append([x, y, z])
all_colors.append(color)
if ".DAT" in filename:
filename = filename.replace(".DAT", ".dat")
if filename not in label_mapping:
# import ipdb; ipdb.set_trace()
label_mapping[filename] = label_counter
label_inverse_mapping[label_counter] = filename
label_counter += 1
all_labels.append(label_mapping[filename])
rotation_matrix = np.array([rx + ry + rz]).reshape(3, 3)
# r = R.from_matrix(rotation_matrix)
# quaternion = r.as_quat()
rotation_onehot, _ = rot_to_onehot24(rotation_matrix)
#data.append([color, x, y, z] + rotation_onehot.tolist())
#data.append([x, y, z] + rotation_onehot.tolist())
data.append(rotation_onehot.tolist())
#data.append([x, y, z] + quaternion.tolist())
filenames.append(filename)
all_coords = np.array(all_coords)
# min_vals = np.min(all_coords, axis=0) # 每个坐标轴的最小值
# max_vals = np.max(all_coords, axis=0) # 每个坐标轴的最大值
# print(max_vals, min_vals)
# normalized_coords = (all_coords - min_vals) / (max_vals - min_vals)
# normalized_coords = 2 * normalized_coords - 1
# for i, entry in enumerate(data):
# entry[0:3] = normalized_coords[i] # 更新 x, y, z 坐标
one_hot_x = np.eye(max_x+1)[all_coords[:, 0].astype(int)]
one_hot_y = np.eye(max_y+1)[all_coords[:, 1].astype(int)]
one_hot_z = np.eye(max_z+1)[all_coords[:, 2].astype(int)]
for i, entry in enumerate(data):
#entry.append(normalized_labels[i]) # 添加标准化标签到数据中
entry.extend(np.concatenate([one_hot_x[i], one_hot_y[i], one_hot_z[i]])) # Using numpy to concatenate
# color_min = np.min(all_colors)
# color_max = np.max(all_colors)
# normalized_colors = (np.array(all_colors) - color_min) / (color_max - color_min)
# 更新数据:将每个零件的颜色替换为标准化后的颜色
# for i, entry in enumerate(data):
# entry[0] = normalized_colors[i] # 更新颜色
if label_mapping is None:
label_mapping = {filename: idx for idx, filename in enumerate(sorted(set(all_labels)))}
else:
label_mapping = label_mapping
#all_labels = [label_mapping[label] for label in all_labels]
#label_min = np.min(all_labels) # 获取标签的最小值
#label_max = np.max(all_labels) # 获取标签的最大值
label_max = len(label_mapping) # 获取标签的最大值
# 将标签标准化到 [0, 1] 范围
#normalized_labels = (all_labels - label_min) / (label_max - label_min)
one_hot_labels = np.eye(label_max)[all_labels]
# 更新数据:将每个零件的标签替换为标准化后的标签
for i, entry in enumerate(data):
#entry.append(normalized_labels[i]) # 添加标准化标签到数据中
entry.extend(one_hot_labels[i]) # 添加one-hot编码标签到数据中
for i, entry in enumerate(data):
#entry.append(normalized_labels[i]) # 添加标准化标签到数据中
entry.extend([1,0]) #
#import ipdb; ipdb.set_trace()
return np.array(data), label_inverse_mapping # 将数据转换为NumPy数组
def process_ldr_flatten(lines):
data = []
filenames = []
all_coords = []
all_colors = []
all_labels = []
label_mapping = {}
label_inverse_mapping = {}
# Use config-based paths (works in both local and HF Space environments)
forward_path, inverse_path = get_mapping_paths("subset_1k")
label_mapping, label_inverse_mapping = load_mappings(forward_path, inverse_path)
label_counter = 0
max_x = 250
max_y = 214
max_z = 524
#print(lines)
for line in lines:
if line.startswith('1'):
parts = line.split()
#if len(parts) != 15:
# if len(parts) < 15:
# print(f"Skipping line due to unexpected length: {line.strip()}")
# continue
#print(parts)
color = int(parts[1])
x, y, z = round(float(parts[2])), round(float(parts[3])), round(float(parts[4]))
rx = list(map(float, parts[5:8]))
ry = list(map(float, parts[8:11]))
rz = list(map(float, parts[11:14]))
filename = parts[14].lower()
all_coords.append([x, y, z])
all_colors.append(color)
if ".DAT" in filename:
filename = filename.replace(".DAT", ".dat")
if filename not in label_mapping:
# import ipdb; ipdb.set_trace()
label_mapping[filename] = label_counter
label_inverse_mapping[label_counter] = filename
label_counter += 1
all_labels.append(label_mapping[filename])
rotation_matrix = np.array([rx + ry + rz]).reshape(3, 3)
# r = R.from_matrix(rotation_matrix)
# quaternion = r.as_quat()
rotation_onehot, _ = rot_to_onehot24(rotation_matrix)
rotation_id = rotation_onehot.argmax()
#data.append([color, x, y, z] + rotation_onehot.tolist())
#data.append([x, y, z] + rotation_onehot.tolist())
#data.append(rotation_onehot.tolist())
data.append([rotation_id])
#data.append([x, y, z] + quaternion.tolist())
filenames.append(filename)
all_coords = np.array(all_coords)
# min_vals = np.min(all_coords, axis=0)
# max_vals = np.max(all_coords, axis=0)
# print(max_vals, min_vals)
# normalized_coords = (all_coords - min_vals) / (max_vals - min_vals)
# normalized_coords = 2 * normalized_coords - 1
# for i, entry in enumerate(data):
# entry[0:3] = normalized_coords[i]
#print(all_coords)
one_hot_x = np.eye(max_x+1)[all_coords[:, 0].astype(int)]
one_hot_y = np.eye(max_y+1)[all_coords[:, 1].astype(int)]
one_hot_z = np.eye(max_z+1)[all_coords[:, 2].astype(int)]
# for i, entry in enumerate(data):
# #entry.append(normalized_labels[i])
# entry.extend(np.concatenate([one_hot_x[i], one_hot_y[i], one_hot_z[i]])) # Using numpy to concatenate
# color_min = np.min(all_colors)
# color_max = np.max(all_colors)
# normalized_colors = (np.array(all_colors) - color_min) / (color_max - color_min)
# for i, entry in enumerate(data):
# entry[0] = normalized_colors[i]
if label_mapping is None:
label_mapping = {filename: idx for idx, filename in enumerate(sorted(set(all_labels)))}
else:
label_mapping = label_mapping
#all_labels = [label_mapping[label] for label in all_labels]
#label_min = np.min(all_labels)
#label_max = np.max(all_labels)
label_max = len(label_mapping)
# 将标签标准化到 [0, 1] 范围
#normalized_labels = (all_labels - label_min) / (label_max - label_min)
one_hot_labels = np.eye(label_max)[all_labels]
for i, entry in enumerate(data):
#entry.append(normalized_labels[i]) #
#entry.extend(one_hot_labels[i]) #
entry.extend([all_labels[i]]) #
entry.extend(np.concatenate([
np.array([all_coords[i, 0].astype(int)]),
np.array([all_coords[i, 1].astype(int)]),
np.array([all_coords[i, 2].astype(int)])
]))
for i, entry in enumerate(data):
#entry.append(normalized_labels[i])
entry.extend([1,0]) #
#import ipdb; ipdb.set_trace()
return np.array(data), label_inverse_mapping
def process_ldr_flatten_bottom(lines):
data = []
filenames = []
all_coords = []
all_colors = []
all_labels = []
label_mapping = {}
label_inverse_mapping = {}
label_mapping, label_inverse_mapping = load_mappings('/public/home/wangshuo/gap/assembly/data/car_1k/subset_bottom_300/label_mapping.json', '/public/home/wangshuo/gap/assembly/data/car_1k/subset_bottom_300/label_inverse_mapping.json')
label_counter = 0
max_x = 212
max_y = 72
max_z = 410
for line in lines:
if line.startswith('1'):
parts = line.split()
# if len(parts) != 15:
# print(f"Skipping line due to unexpected length: {line.strip()}")
# continue
color = int(parts[1])
x, y, z = round(float(parts[2])), round(float(parts[3])), round(float(parts[4]))
rx = list(map(float, parts[5:8]))
ry = list(map(float, parts[8:11]))
rz = list(map(float, parts[11:14]))
filename = parts[14].lower()
all_coords.append([x, y, z])
all_colors.append(color)
if ".DAT" in filename:
filename = filename.replace(".DAT", ".dat")
if filename not in label_mapping:
# import ipdb; ipdb.set_trace()
label_mapping[filename] = label_counter
label_inverse_mapping[label_counter] = filename
label_counter += 1
all_labels.append(label_mapping[filename])
rotation_matrix = np.array([rx + ry + rz]).reshape(3, 3)
# r = R.from_matrix(rotation_matrix)
# quaternion = r.as_quat()
rotation_onehot, _ = rot_to_onehot24(rotation_matrix)
rotation_id = rotation_onehot.argmax()
#data.append([color, x, y, z] + rotation_onehot.tolist())
#data.append([x, y, z] + rotation_onehot.tolist())
#data.append(rotation_onehot.tolist())
data.append([rotation_id])
#data.append([x, y, z] + quaternion.tolist())
filenames.append(filename)
all_coords = np.array(all_coords)
# min_vals = np.min(all_coords, axis=0)
# max_vals = np.max(all_coords, axis=0)
# print(max_vals, min_vals)
# normalized_coords = (all_coords - min_vals) / (max_vals - min_vals)
# normalized_coords = 2 * normalized_coords - 1
# for i, entry in enumerate(data):
# entry[0:3] = normalized_coords[i]
one_hot_x = np.eye(max_x+1)[all_coords[:, 0].astype(int)]
one_hot_y = np.eye(max_y+1)[all_coords[:, 1].astype(int)]
one_hot_z = np.eye(max_z+1)[all_coords[:, 2].astype(int)]
# for i, entry in enumerate(data):
# #entry.append(normalized_labels[i])
# entry.extend(np.concatenate([one_hot_x[i], one_hot_y[i], one_hot_z[i]])) # Using numpy to concatenate
# color_min = np.min(all_colors)
# color_max = np.max(all_colors)
# normalized_colors = (np.array(all_colors) - color_min) / (color_max - color_min)
# for i, entry in enumerate(data):
# entry[0] = normalized_colors[i]
if label_mapping is None:
label_mapping = {filename: idx for idx, filename in enumerate(sorted(set(all_labels)))}
else:
label_mapping = label_mapping
#all_labels = [label_mapping[label] for label in all_labels]
#label_min = np.min(all_labels)
#label_max = np.max(all_labels)
label_max = len(label_mapping)
# 将标签标准化到 [0, 1] 范围
#normalized_labels = (all_labels - label_min) / (label_max - label_min)
one_hot_labels = np.eye(label_max)[all_labels]
for i, entry in enumerate(data):
#entry.append(normalized_labels[i]) #
#entry.extend(one_hot_labels[i]) #
entry.extend([all_labels[i]]) #
entry.extend(np.concatenate([
np.array([all_coords[i, 0].astype(int)]),
np.array([all_coords[i, 1].astype(int)]),
np.array([all_coords[i, 2].astype(int)])
]))
for i, entry in enumerate(data):
#entry.append(normalized_labels[i])
entry.extend([1,0]) #
#import ipdb; ipdb.set_trace()
return np.array(data), label_inverse_mapping
def save_data_as_npy(data, output_file):
np.save(output_file, data)
def logits2ldr(normalized_data, label_inverse_mapping=None, max_vals=None, min_vals=None, label_max=None, label_min=None, max_color=None, min_color=None, output_file='restored_data.ldr'):
dat_num = 604
x_num = 213
y_num = 217
z_num = 529
rot_num = 24
x = x_num
xy = x_num + y_num + rot_num
xyz = x_num + y_num + z_num + rot_num
# Use config-based paths (works in both local and HF Space environments)
forward_path, inverse_path = get_mapping_paths("subset_self")
label_mapping, label_inverse_mapping = load_mappings(forward_path, inverse_path)
if label_inverse_mapping is None:
# import ipdb; ipdb.set_trace()
# #label_inverse_mapping = {0: '98281.dat', 1: '3005.dat', 2: '3004.dat', 3: '3795.dat', 4: '3020.dat', 5: '3710.dat', 6: '3666.dat', 7: '3021.dat', 8: '2431.dat', 9: '4488.dat', 10: '3829a.dat', 11: '3829b.dat', 12: '43723.dat', 13: '3068b.dat', 14: '43722.dat', 15: '3832.dat', 16: '2432.dat', 17: '2437.dat', 18: '6231.dat', 19: '3040b.dat', 20: '3024.dat', 21: '11211.dat', 22: '2540.dat', 23: '61678.dat', 24: '3665.dat', 25: '11477.dat', 26: '93594.dat', 27: '50951.dat', 28: '4073.dat', 29: '6019.dat', 30: '6091.dat', 31: '3821.dat', 32: '3822.dat', 33: '98138.dat', 34: '3794a.dat', 35: '4081b.dat', 36: '3022.dat', 37: '30039.dat', 38: '50946.dat', 39: '4095.dat'} #blue_classic_car
label_inverse_mapping = {0: '24308b.dat', 1: '3031.dat', 2: '4079.dat', 3: '3021.dat', 4: '3024.dat', 5: '3020.dat', 6: '29120.dat', 7: '71076a.dat', 8: '3023.dat', 9: '29119.dat', 10: '2412b.dat', 11: '86876.dat', 12: '11211.dat', 13: '87087.dat', 14: '3004.dat', 15: '15068.dat', 16: '3829c01.dat', 17: '11477.dat', 18: '79393.dat', 19: '63864.dat', 20: '3710.dat', 21: 'm17f5892b_2023521_010804.dat', 22: '6141.dat', 23: '85984pc2.dat', 24: '3010.dat', 25: '30414.dat', 26: '2431pt0.dat'}
normalized_labels = normalized_data[:, xyz:xyz+dat_num].argmax(1)
#normalized_colors = normalized_data[:, 0] # 颜色列
normalized_coords_x = normalized_data[:, rot_num:rot_num+x].argmax(1)
normalized_coords_y = normalized_data[:, rot_num+x:xy].argmax(1)
normalized_coords_z = normalized_data[:, xy:xyz].argmax(1)
restored_coords = np.stack((normalized_coords_x, normalized_coords_y, normalized_coords_z), axis=-1)
#import ipdb; ipdb.set_trace()
#restored_coords = ((normalized_coords + 1) / 2) * (max_vals - min_vals) + min_vals
#restored_labels = (normalized_labels * (label_max - label_min)) + label_min
#restored_colors = normalized_colors * (max_color - min_color) + min_color
flag = normalized_data[:, xyz+dat_num:xyz+dat_num+2].argmax(1)
ldr_lines = []
for i, entry in enumerate(normalized_data):
color = 0 #int(restored_colors[i])
x, y, z = restored_coords[i]
label = label_inverse_mapping[str(np.clip(np.round(normalized_labels[i]), 0, dat_num).astype(int))]
# quaternion = entry[4:8] #
# quaternion = quaternion / np.linalg.norm(quaternion) #
# r = R.from_quat(quaternion)
rotation_matrix = onehot24_to_rot(entry[:rot_num])#r.as_matrix()
f = 1 - flag[i]
ldr_line = f"{f} {color} {x:.6f} {y:.6f} {z:.6f} " \
f"{rotation_matrix[0, 0]:.6f} {rotation_matrix[0, 1]:.6f} {rotation_matrix[0, 2]:.6f} " \
f"{rotation_matrix[1, 0]:.6f} {rotation_matrix[1, 1]:.6f} {rotation_matrix[1, 2]:.6f} " \
f"{rotation_matrix[2, 0]:.6f} {rotation_matrix[2, 1]:.6f} {rotation_matrix[2, 2]:.6f} " \
f"{label}\n"
ldr_lines.append(ldr_line)
with open(output_file, 'w') as f:
f.writelines(ldr_lines)
print(f"Restored LDR data saved to {output_file}")
return ldr_lines
def logits2ldrot(normalized_data, input_data, label_inverse_mapping='', max_vals='', min_vals='', label_max='', label_min='', max_color='', min_color='', output_file='restored_data_rot_wop.ldr'):
dat_num = 604
x_num = 213
y_num = 217
z_num = 529
rot_num = 24
x = x_num
xy = x_num + y_num + rot_num
xyz = x_num + y_num + z_num + rot_num
# Use config-based paths (works in both local and HF Space environments)
forward_path, inverse_path = get_mapping_paths("subset_self")
label_mapping, label_inverse_mapping = load_mappings(forward_path, inverse_path)
if label_inverse_mapping is None:
# import ipdb; ipdb.set_trace()
# #label_inverse_mapping = {0: '98281.dat', 1: '3005.dat', 2: '3004.dat', 3: '3795.dat', 4: '3020.dat', 5: '3710.dat', 6: '3666.dat', 7: '3021.dat', 8: '2431.dat', 9: '4488.dat', 10: '3829a.dat', 11: '3829b.dat', 12: '43723.dat', 13: '3068b.dat', 14: '43722.dat', 15: '3832.dat', 16: '2432.dat', 17: '2437.dat', 18: '6231.dat', 19: '3040b.dat', 20: '3024.dat', 21: '11211.dat', 22: '2540.dat', 23: '61678.dat', 24: '3665.dat', 25: '11477.dat', 26: '93594.dat', 27: '50951.dat', 28: '4073.dat', 29: '6019.dat', 30: '6091.dat', 31: '3821.dat', 32: '3822.dat', 33: '98138.dat', 34: '3794a.dat', 35: '4081b.dat', 36: '3022.dat', 37: '30039.dat', 38: '50946.dat', 39: '4095.dat'} #blue_classic_car
label_inverse_mapping = {0: '24308b.dat', 1: '3031.dat', 2: '4079.dat', 3: '3021.dat', 4: '3024.dat', 5: '3020.dat', 6: '29120.dat', 7: '71076a.dat', 8: '3023.dat', 9: '29119.dat', 10: '2412b.dat', 11: '86876.dat', 12: '11211.dat', 13: '87087.dat', 14: '3004.dat', 15: '15068.dat', 16: '3829c01.dat', 17: '11477.dat', 18: '79393.dat', 19: '63864.dat', 20: '3710.dat', 21: 'm17f5892b_2023521_010804.dat', 22: '6141.dat', 23: '85984pc2.dat', 24: '3010.dat', 25: '30414.dat', 26: '2431pt0.dat'}
input_labels = input_data[:, xyz:xyz+dat_num].argmax(1)
input_coords_x = input_data[:, rot_num:rot_num+x].argmax(1)
input_coords_y = input_data[:, rot_num+x:xy].argmax(1)
input_coords_z = input_data[:, xy:xyz].argmax(1)
restored_coords = np.stack((input_coords_x, input_coords_y, input_coords_z), axis=-1)
#flag = normalized_data[:, xyz+dat_num:xyz+dat_num+2].argmax(1)
flag = normalized_data[:, -2:].argmax(1)
ldr_lines = []
for i, entry in enumerate(normalized_data[:-1]):
color = 0 #int(restored_colors[i])
x, y, z = restored_coords[i]
label = label_inverse_mapping[str(np.clip(np.round(input_labels[i]), 0, dat_num).astype(int))]
# quaternion = entry[4:8] #
# quaternion = quaternion / np.linalg.norm(quaternion) #
# r = R.from_quat(quaternion)
rotation_matrix = onehot24_to_rot(entry[:rot_num])#r.as_matrix()
f = 1 - flag[i]
ldr_line = f"{f} {color} {x:.6f} {y:.6f} {z:.6f} " \
f"{rotation_matrix[0, 0]:.6f} {rotation_matrix[0, 1]:.6f} {rotation_matrix[0, 2]:.6f} " \
f"{rotation_matrix[1, 0]:.6f} {rotation_matrix[1, 1]:.6f} {rotation_matrix[1, 2]:.6f} " \
f"{rotation_matrix[2, 0]:.6f} {rotation_matrix[2, 1]:.6f} {rotation_matrix[2, 2]:.6f} " \
f"{label}\n"
ldr_lines.append(ldr_line)
with open(output_file, 'w') as f:
f.writelines(ldr_lines)
print(f"Restored LDR data saved to {output_file}")
return ldr_lines
def logits2ldrp(normalized_data, input_data, label_inverse_mapping='', max_vals='', min_vals='', label_max='', label_min='', max_color='', min_color='', output_file='restored_data_rot_wop.ldr'):
dat_num = 604
x_num = 213
y_num = 217
z_num = 529
rot_num = 24
x = x_num
xy = x_num + y_num + rot_num
xyz = x_num + y_num + z_num + rot_num
# Use config-based paths (works in both local and HF Space environments)
forward_path, inverse_path = get_mapping_paths("subset_self")
label_mapping, label_inverse_mapping = load_mappings(forward_path, inverse_path)
if label_inverse_mapping is None:
# import ipdb; ipdb.set_trace()
# #label_inverse_mapping = {0: '98281.dat', 1: '3005.dat', 2: '3004.dat', 3: '3795.dat', 4: '3020.dat', 5: '3710.dat', 6: '3666.dat', 7: '3021.dat', 8: '2431.dat', 9: '4488.dat', 10: '3829a.dat', 11: '3829b.dat', 12: '43723.dat', 13: '3068b.dat', 14: '43722.dat', 15: '3832.dat', 16: '2432.dat', 17: '2437.dat', 18: '6231.dat', 19: '3040b.dat', 20: '3024.dat', 21: '11211.dat', 22: '2540.dat', 23: '61678.dat', 24: '3665.dat', 25: '11477.dat', 26: '93594.dat', 27: '50951.dat', 28: '4073.dat', 29: '6019.dat', 30: '6091.dat', 31: '3821.dat', 32: '3822.dat', 33: '98138.dat', 34: '3794a.dat', 35: '4081b.dat', 36: '3022.dat', 37: '30039.dat', 38: '50946.dat', 39: '4095.dat'} #blue_classic_car
label_inverse_mapping = {0: '24308b.dat', 1: '3031.dat', 2: '4079.dat', 3: '3021.dat', 4: '3024.dat', 5: '3020.dat', 6: '29120.dat', 7: '71076a.dat', 8: '3023.dat', 9: '29119.dat', 10: '2412b.dat', 11: '86876.dat', 12: '11211.dat', 13: '87087.dat', 14: '3004.dat', 15: '15068.dat', 16: '3829c01.dat', 17: '11477.dat', 18: '79393.dat', 19: '63864.dat', 20: '3710.dat', 21: 'm17f5892b_2023521_010804.dat', 22: '6141.dat', 23: '85984pc2.dat', 24: '3010.dat', 25: '30414.dat', 26: '2431pt0.dat'}
input_labels = input_data[:, xyz:xyz+dat_num].argmax(1)
# input_coords_x = input_data[:, rot_num:rot_num+x].argmax(1)
# input_coords_y = input_data[:, rot_num+x:xy].argmax(1)
# input_coords_z = input_data[:, xy:xyz].argmax(1)
input_coords_x = normalized_data[:, rot_num:rot_num+x].argmax(1)
input_coords_y = normalized_data[:, rot_num+x:xy].argmax(1)
input_coords_z = normalized_data[:, xy:xyz].argmax(1)
restored_coords = np.stack((input_coords_x, input_coords_y, input_coords_z), axis=-1)
#flag = normalized_data[:, xyz+dat_num:xyz+dat_num+2].argmax(1)
flag = normalized_data[:, -2:].argmax(1)
ldr_lines = []
#for i, entry in enumerate(normalized_data[:-1]):
for i, entry in enumerate(input_data[:-1]):
color = 0 #int(restored_colors[i])
x, y, z = restored_coords[i]
label = label_inverse_mapping[str(np.clip(np.round(input_labels[i]), 0, dat_num).astype(int))]
# quaternion = entry[4:8] #
# quaternion = quaternion / np.linalg.norm(quaternion) #
# r = R.from_quat(quaternion)
rotation_matrix = onehot24_to_rot(entry[:rot_num])#r.as_matrix()
f = 1# - flag[i]
ldr_line = f"{f} {color} {x:.6f} {y:.6f} {z:.6f} " \
f"{rotation_matrix[0, 0]:.6f} {rotation_matrix[0, 1]:.6f} {rotation_matrix[0, 2]:.6f} " \
f"{rotation_matrix[1, 0]:.6f} {rotation_matrix[1, 1]:.6f} {rotation_matrix[1, 2]:.6f} " \
f"{rotation_matrix[2, 0]:.6f} {rotation_matrix[2, 1]:.6f} {rotation_matrix[2, 2]:.6f} " \
f"{label}\n"
ldr_lines.append(ldr_line)
with open(output_file, 'w') as f:
f.writelines(ldr_lines)
print(f"Restored LDR data saved to {output_file}")
return ldr_lines
def logits2flatldrp(normalized_data, input_data, label_inverse_mapping='', max_vals='', min_vals='', label_max='', label_min='', max_color='', min_color='', output_file='restored_data_rot_wop.ldr'):
dat_num = 604
x_num = 213
y_num = 217
z_num = 529
rot_num = 24
R24 = signed_perm_mats_det_plus_1()
x = x_num
xy = x_num + y_num + rot_num
xyz = x_num + y_num + z_num + rot_num
stride = 3
# Use config-based paths (works in both local and HF Space environments)
forward_path, inverse_path = get_mapping_paths("subset_self")
label_mapping, label_inverse_mapping = load_mappings(forward_path, inverse_path)
if label_inverse_mapping is None:
# import ipdb; ipdb.set_trace()
# #label_inverse_mapping = {0: '98281.dat', 1: '3005.dat', 2: '3004.dat', 3: '3795.dat', 4: '3020.dat', 5: '3710.dat', 6: '3666.dat', 7: '3021.dat', 8: '2431.dat', 9: '4488.dat', 10: '3829a.dat', 11: '3829b.dat', 12: '43723.dat', 13: '3068b.dat', 14: '43722.dat', 15: '3832.dat', 16: '2432.dat', 17: '2437.dat', 18: '6231.dat', 19: '3040b.dat', 20: '3024.dat', 21: '11211.dat', 22: '2540.dat', 23: '61678.dat', 24: '3665.dat', 25: '11477.dat', 26: '93594.dat', 27: '50951.dat', 28: '4073.dat', 29: '6019.dat', 30: '6091.dat', 31: '3821.dat', 32: '3822.dat', 33: '98138.dat', 34: '3794a.dat', 35: '4081b.dat', 36: '3022.dat', 37: '30039.dat', 38: '50946.dat', 39: '4095.dat'} #blue_classic_car
label_inverse_mapping = {0: '24308b.dat', 1: '3031.dat', 2: '4079.dat', 3: '3021.dat', 4: '3024.dat', 5: '3020.dat', 6: '29120.dat', 7: '71076a.dat', 8: '3023.dat', 9: '29119.dat', 10: '2412b.dat', 11: '86876.dat', 12: '11211.dat', 13: '87087.dat', 14: '3004.dat', 15: '15068.dat', 16: '3829c01.dat', 17: '11477.dat', 18: '79393.dat', 19: '63864.dat', 20: '3710.dat', 21: 'm17f5892b_2023521_010804.dat', 22: '6141.dat', 23: '85984pc2.dat', 24: '3010.dat', 25: '30414.dat', 26: '2431pt0.dat'}
input_labels = input_data[:, -6]
input_coords_x = input_data[:, -5] #normalized_data[1:-2:stride, :x_num+1].argmax(1)
input_coords_y = input_data[:, -4] #normalized_data[0:-3:stride, :y_num+1].argmax(1)
input_coords_z = input_data[:, -3] #normalized_data[2:-1:stride, :z_num+1].argmax(1)
restored_coords = np.stack((input_coords_x, input_coords_y, input_coords_z), axis=-1)
#flag = normalized_data[:, xyz+dat_num:xyz+dat_num+2].argmax(1)
#flag = normalized_data[:, -2:].argmax(1)
ldr_lines = []
#for i, entry in enumerate(normalized_data[:-1]):
for i, entry in enumerate(input_data[:-1]):
color = 0 #int(restored_colors[i])
x, y, z = restored_coords[i]
label = label_inverse_mapping[str(np.clip(np.round(input_labels[i]), 0, dat_num).astype(int))]
# quaternion = entry[4:8] #
# quaternion = quaternion / np.linalg.norm(quaternion) #
# r = R.from_quat(quaternion)
#import ipdb; ipdb.set_trace()
rotation_matrix = R24[entry[-7]]#r.as_matrix()
f = 1# - flag[i]
ldr_line = f"{f} {color} {x:.6f} {y:.6f} {z:.6f} " \
f"{rotation_matrix[0, 0]:.6f} {rotation_matrix[0, 1]:.6f} {rotation_matrix[0, 2]:.6f} " \
f"{rotation_matrix[1, 0]:.6f} {rotation_matrix[1, 1]:.6f} {rotation_matrix[1, 2]:.6f} " \
f"{rotation_matrix[2, 0]:.6f} {rotation_matrix[2, 1]:.6f} {rotation_matrix[2, 2]:.6f} " \
f"{label}\n"
ldr_lines.append(ldr_line)
with open(output_file, 'w') as f:
f.writelines(ldr_lines)
print(f"Restored LDR data saved to {output_file}")
return ldr_lines
def logits2flatldrpr(normalized_data, input_data, stride, given, label_inverse_mapping='', max_vals='', min_vals='', label_max='', label_min='', max_color='', min_color='', output_file='restored_data_rot_wop.ldr'):
dat_num = 604
x_num = 213
y_num = 217
z_num = 529
rot_num = 24
R24 = signed_perm_mats_det_plus_1()
x = x_num
xy = x_num + y_num + rot_num
xyz = x_num + y_num + z_num + rot_num
stride = stride
attr_shift = stride-3 #+1 for bert
bert_shift = 1
# Use config-based paths (works in both local and HF Space environments)
forward_path, inverse_path = get_mapping_paths("subset_self")
label_mapping, label_inverse_mapping = load_mappings(forward_path, inverse_path)
if label_inverse_mapping is None:
# import ipdb; ipdb.set_trace()
# #label_inverse_mapping = {0: '98281.dat', 1: '3005.dat', 2: '3004.dat', 3: '3795.dat', 4: '3020.dat', 5: '3710.dat', 6: '3666.dat', 7: '3021.dat', 8: '2431.dat', 9: '4488.dat', 10: '3829a.dat', 11: '3829b.dat', 12: '43723.dat', 13: '3068b.dat', 14: '43722.dat', 15: '3832.dat', 16: '2432.dat', 17: '2437.dat', 18: '6231.dat', 19: '3040b.dat', 20: '3024.dat', 21: '11211.dat', 22: '2540.dat', 23: '61678.dat', 24: '3665.dat', 25: '11477.dat', 26: '93594.dat', 27: '50951.dat', 28: '4073.dat', 29: '6019.dat', 30: '6091.dat', 31: '3821.dat', 32: '3822.dat', 33: '98138.dat', 34: '3794a.dat', 35: '4081b.dat', 36: '3022.dat', 37: '30039.dat', 38: '50946.dat', 39: '4095.dat'} #blue_classic_car
label_inverse_mapping = {0: '24308b.dat', 1: '3031.dat', 2: '4079.dat', 3: '3021.dat', 4: '3024.dat', 5: '3020.dat', 6: '29120.dat', 7: '71076a.dat', 8: '3023.dat', 9: '29119.dat', 10: '2412b.dat', 11: '86876.dat', 12: '11211.dat', 13: '87087.dat', 14: '3004.dat', 15: '15068.dat', 16: '3829c01.dat', 17: '11477.dat', 18: '79393.dat', 19: '63864.dat', 20: '3710.dat', 21: 'm17f5892b_2023521_010804.dat', 22: '6141.dat', 23: '85984pc2.dat', 24: '3010.dat', 25: '30414.dat', 26: '2431pt0.dat'}
#input_labels = normalized_data[0:-4:stride, :dat_num+1].argmax(1) #
input_labels = input_data[:, -6]
#input_labels[:given] = input_data[:given, -6] #normalized_data[0:-4:stride, :dat_num+1].argmax(1)
input_rot = normalized_data[1+bert_shift:-3:stride, :rot_num+1].argmax(1) # #normalized_data[1:-3:stride, :rot_num+1].argmax(1)
#input_rot = input_data[:, 0]
input_coords_x = normalized_data[1+attr_shift+bert_shift:-1:stride, rot_num+1:x+rot_num+1+1].argmax(1)
input_coords_y = normalized_data[0+attr_shift+bert_shift:-2:stride, x+rot_num+2:xy+3].argmax(1)
input_coords_z = normalized_data[2+attr_shift+bert_shift::stride, xy+3:xyz+4].argmax(1)
# input_coords_x[:given] = input_data[:given, -5]
# input_coords_y[:given] = input_data[:given, -4]
# input_coords_z[:given] = input_data[:given, -3]
restored_coords = np.stack((input_coords_x, input_coords_y, input_coords_z), axis=-1)
#flag = normalized_data[:, xyz+dat_num:xyz+dat_num+2].argmax(1)
#flag = normalized_data[:, -2:].argmax(1)
input_colors = np.zeros_like(input_data[:, 0])
#input_colors[:given] = (input_colors[:given] + 4)
ldr_lines = []
#for i, entry in enumerate(normalized_data[:-1]):
for i, entry in enumerate(input_data[:-1]):
color = int(input_colors[i])
x, y, z = restored_coords[i]
label = label_inverse_mapping[str(np.clip(np.round(input_labels[i]), 0, dat_num-1).astype(int))]
# quaternion = entry[4:8] #
# quaternion = quaternion / np.linalg.norm(quaternion) #
# r = R.from_quat(quaternion)
rotation_matrix = R24[np.clip(input_rot[i], 0, rot_num-1)] #R24[entry[-7]]#r.as_matrix()
if x>212:
f = 0# - flag[i]
else:
f = 1
ldr_line = f"{f} {color} {x:.6f} {y:.6f} {z:.6f} " \
f"{rotation_matrix[0, 0]:.6f} {rotation_matrix[0, 1]:.6f} {rotation_matrix[0, 2]:.6f} " \
f"{rotation_matrix[1, 0]:.6f} {rotation_matrix[1, 1]:.6f} {rotation_matrix[1, 2]:.6f} " \
f"{rotation_matrix[2, 0]:.6f} {rotation_matrix[2, 1]:.6f} {rotation_matrix[2, 2]:.6f} " \
f"{label}\n"
ldr_lines.append(ldr_line)
with open(output_file, 'w') as f:
f.writelines(ldr_lines)
print(f"Restored LDR data saved to {output_file}")
return ldr_lines
# def logits2botldrpr(normalized_data, input_data, stride, given, label_inverse_mapping='', max_vals='', min_vals='', label_max='', label_min='', max_color='', min_color='', output_file='restored_data_rot_wop.ldr'):
# dat_num = 286
# x_num = 213
# y_num = 73
# z_num = 411
# rot_num = 24
# R24 = signed_perm_mats_det_plus_1()
# x = x_num
# xy = x_num + y_num + rot_num
# xyz = x_num + y_num + z_num + rot_num
# stride = stride
# attr_shift = stride-3 #+1 for bert
# bert_shift = 1
# label_mapping, label_inverse_mapping = load_mappings('../data/car_1k/subset_bottom_300/label_mapping.json', '../data/car_1k/subset_bottom_300/label_inverse_mapping.json')
# if label_inverse_mapping is None:
# import ipdb; ipdb.set_trace()
# # #label_inverse_mapping = {0: '98281.dat', 1: '3005.dat', 2: '3004.dat', 3: '3795.dat', 4: '3020.dat', 5: '3710.dat', 6: '3666.dat', 7: '3021.dat', 8: '2431.dat', 9: '4488.dat', 10: '3829a.dat', 11: '3829b.dat', 12: '43723.dat', 13: '3068b.dat', 14: '43722.dat', 15: '3832.dat', 16: '2432.dat', 17: '2437.dat', 18: '6231.dat', 19: '3040b.dat', 20: '3024.dat', 21: '11211.dat', 22: '2540.dat', 23: '61678.dat', 24: '3665.dat', 25: '11477.dat', 26: '93594.dat', 27: '50951.dat', 28: '4073.dat', 29: '6019.dat', 30: '6091.dat', 31: '3821.dat', 32: '3822.dat', 33: '98138.dat', 34: '3794a.dat', 35: '4081b.dat', 36: '3022.dat', 37: '30039.dat', 38: '50946.dat', 39: '4095.dat'} #blue_classic_car
# label_inverse_mapping = {0: '24308b.dat', 1: '3031.dat', 2: '4079.dat', 3: '3021.dat', 4: '3024.dat', 5: '3020.dat', 6: '29120.dat', 7: '71076a.dat', 8: '3023.dat', 9: '29119.dat', 10: '2412b.dat', 11: '86876.dat', 12: '11211.dat', 13: '87087.dat', 14: '3004.dat', 15: '15068.dat', 16: '3829c01.dat', 17: '11477.dat', 18: '79393.dat', 19: '63864.dat', 20: '3710.dat', 21: 'm17f5892b_2023521_010804.dat', 22: '6141.dat', 23: '85984pc2.dat', 24: '3010.dat', 25: '30414.dat', 26: '2431pt0.dat'}
# #input_labels = normalized_data[0:-4:stride, :dat_num+1].argmax(1) #
# input_labels = input_data[:, -6]
# #input_labels[:given] = input_data[:given, -6] #normalized_data[0:-4:stride, :dat_num+1].argmax(1)
# input_rot = normalized_data[1+bert_shift:-3:stride, :rot_num+1].argmax(1) # #normalized_data[1:-3:stride, :rot_num+1].argmax(1)
# #input_rot = input_data[:, 0]
# input_coords_x = normalized_data[1+attr_shift+bert_shift:-1:stride, rot_num+1:x+rot_num+1+1].argmax(1)
# input_coords_y = normalized_data[0+attr_shift+bert_shift:-2:stride, x+rot_num+2:xy+3].argmax(1)
# input_coords_z = normalized_data[2+attr_shift+bert_shift::stride, xy+3:xyz+4].argmax(1)
# # input_coords_x[:given] = input_data[:given, -5]
# # input_coords_y[:given] = input_data[:given, -4]
# # input_coords_z[:given] = input_data[:given, -3]
# restored_coords = np.stack((input_coords_x, input_coords_y, input_coords_z), axis=-1)
# #flag = normalized_data[:, xyz+dat_num:xyz+dat_num+2].argmax(1)
# #flag = normalized_data[:, -2:].argmax(1)
# input_colors = np.zeros_like(input_data[:, 0])
# #input_colors[:given] = (input_colors[:given] + 4)
# ldr_lines = []
# #for i, entry in enumerate(normalized_data[:-1]):
# for i, entry in enumerate(input_data[:-1]):
# color = int(input_colors[i])
# x, y, z = restored_coords[i]
# label = label_inverse_mapping[str(np.clip(np.round(input_labels[i]), 0, dat_num-1).astype(int))]
# # quaternion = entry[4:8] #
# # quaternion = quaternion / np.linalg.norm(quaternion) #
# # r = R.from_quat(quaternion)
# rotation_matrix = R24[np.clip(input_rot[i], 0, rot_num-1)] #R24[entry[-7]]#r.as_matrix()
# if x>212:
# f = 0# - flag[i]
# else:
# f = 1
# ldr_line = f"{f} {color} {x:.6f} {y:.6f} {z:.6f} " \
# f"{rotation_matrix[0, 0]:.6f} {rotation_matrix[0, 1]:.6f} {rotation_matrix[0, 2]:.6f} " \
# f"{rotation_matrix[1, 0]:.6f} {rotation_matrix[1, 1]:.6f} {rotation_matrix[1, 2]:.6f} " \
# f"{rotation_matrix[2, 0]:.6f} {rotation_matrix[2, 1]:.6f} {rotation_matrix[2, 2]:.6f} " \
# f"{label}\n"
# ldr_lines.append(ldr_line)
# with open(output_file, 'w') as f:
# f.writelines(ldr_lines)
# print(f"Restored LDR data saved to {output_file}")
# return ldr_lines
def logits2botldrpr(normalized_data, input_data, stride, given, label_inverse_mapping='', max_vals='', min_vals='', label_max='', label_min='', max_color='', min_color='', output_file='restored_data_rot_wop.ldr'):
dat_num = 1217 #286
x_num = 251 #213
y_num = 215 #73
z_num = 525 #411
rot_num = 24
R24 = signed_perm_mats_det_plus_1()
x = x_num
xy = x_num + y_num + rot_num
xyz = x_num + y_num + z_num + rot_num
stride = stride
attr_shift = stride-3 #+1 for bert
bert_shift = 1
# Use config-based paths (works in both local and HF Space environments)
forward_path, inverse_path = get_mapping_paths("subset_1k")
label_mapping, label_inverse_mapping = load_mappings(forward_path, inverse_path)
if label_inverse_mapping is None:
# import ipdb; ipdb.set_trace()
# #label_inverse_mapping = {0: '98281.dat', 1: '3005.dat', 2: '3004.dat', 3: '3795.dat', 4: '3020.dat', 5: '3710.dat', 6: '3666.dat', 7: '3021.dat', 8: '2431.dat', 9: '4488.dat', 10: '3829a.dat', 11: '3829b.dat', 12: '43723.dat', 13: '3068b.dat', 14: '43722.dat', 15: '3832.dat', 16: '2432.dat', 17: '2437.dat', 18: '6231.dat', 19: '3040b.dat', 20: '3024.dat', 21: '11211.dat', 22: '2540.dat', 23: '61678.dat', 24: '3665.dat', 25: '11477.dat', 26: '93594.dat', 27: '50951.dat', 28: '4073.dat', 29: '6019.dat', 30: '6091.dat', 31: '3821.dat', 32: '3822.dat', 33: '98138.dat', 34: '3794a.dat', 35: '4081b.dat', 36: '3022.dat', 37: '30039.dat', 38: '50946.dat', 39: '4095.dat'} #blue_classic_car
label_inverse_mapping = {0: '24308b.dat', 1: '3031.dat', 2: '4079.dat', 3: '3021.dat', 4: '3024.dat', 5: '3020.dat', 6: '29120.dat', 7: '71076a.dat', 8: '3023.dat', 9: '29119.dat', 10: '2412b.dat', 11: '86876.dat', 12: '11211.dat', 13: '87087.dat', 14: '3004.dat', 15: '15068.dat', 16: '3829c01.dat', 17: '11477.dat', 18: '79393.dat', 19: '63864.dat', 20: '3710.dat', 21: 'm17f5892b_2023521_010804.dat', 22: '6141.dat', 23: '85984pc2.dat', 24: '3010.dat', 25: '30414.dat', 26: '2431pt0.dat'}
#input_labels = normalized_data[0:-4:stride, :dat_num+1].argmax(1) #
input_labels = input_data[:, -6]
#input_labels[:given] = input_data[:given, -6] #normalized_data[0:-4:stride, :dat_num+1].argmax(1)
input_rot = normalized_data[1+bert_shift:-3:stride, :rot_num+1].argmax(1) # #normalized_data[1:-3:stride, :rot_num+1].argmax(1)
#input_rot = input_data[:, 0]
input_coords_x = normalized_data[1+attr_shift+bert_shift:-1:stride, rot_num+1:x+rot_num+1+1].argmax(1)
input_coords_y = normalized_data[0+attr_shift+bert_shift:-2:stride, x+rot_num+2:xy+3].argmax(1)
input_coords_z = normalized_data[2+attr_shift+bert_shift::stride, xy+3:xyz+4].argmax(1)
# input_coords_x[:given] = input_data[:given, -5]
# input_coords_y[:given] = input_data[:given, -4]
# input_coords_z[:given] = input_data[:given, -3]
restored_coords = np.stack((input_coords_x, input_coords_y, input_coords_z), axis=-1)
#flag = normalized_data[:, xyz+dat_num:xyz+dat_num+2].argmax(1)
#flag = normalized_data[:, -2:].argmax(1)
input_colors = np.zeros_like(input_data[:, 0])
#input_colors[:given] = (input_colors[:given] + 4)
ldr_lines = []
#for i, entry in enumerate(normalized_data[:-1]):
for i, entry in enumerate(input_data[:-1]):
color = int(input_colors[i])
x, y, z = restored_coords[i]
label = label_inverse_mapping[str(np.clip(np.round(input_labels[i]), 0, dat_num-1).astype(int))]
# quaternion = entry[4:8] #
# quaternion = quaternion / np.linalg.norm(quaternion) #
# r = R.from_quat(quaternion)
rotation_matrix = R24[np.clip(input_rot[i], 0, rot_num-1)] #R24[entry[-7]]#r.as_matrix()
if x>(x_num-1):
f = 0# - flag[i]
else:
f = 1
ldr_line = f"{f} {color} {x:.6f} {y:.6f} {z:.6f} " \
f"{rotation_matrix[0, 0]:.6f} {rotation_matrix[0, 1]:.6f} {rotation_matrix[0, 2]:.6f} " \
f"{rotation_matrix[1, 0]:.6f} {rotation_matrix[1, 1]:.6f} {rotation_matrix[1, 2]:.6f} " \
f"{rotation_matrix[2, 0]:.6f} {rotation_matrix[2, 1]:.6f} {rotation_matrix[2, 2]:.6f} " \
f"{label}\n"
ldr_lines.append(ldr_line)
with open(output_file, 'w') as f:
f.writelines(ldr_lines)
print(f"Restored LDR data saved to {output_file}")
return ldr_lines
def ids2flatldrpr(normalized_data, input_data, stride, given, label_inverse_mapping='', max_vals='', min_vals='', label_max='', label_min='', max_color='', min_color='', output_file='restored_data_rot_wop.ldr'):
dat_num = 604
x_num = 213
y_num = 217
z_num = 529
rot_num = 24
R24 = signed_perm_mats_det_plus_1()
x = x_num
xy = x_num + y_num + rot_num
xyz = x_num + y_num + z_num + rot_num
stride = stride
attr_shift = stride-3
# Use config-based paths (works in both local and HF Space environments)
forward_path, inverse_path = get_mapping_paths("subset_self")
label_mapping, label_inverse_mapping = load_mappings(forward_path, inverse_path)
if label_inverse_mapping is None:
# import ipdb; ipdb.set_trace()
# #label_inverse_mapping = {0: '98281.dat', 1: '3005.dat', 2: '3004.dat', 3: '3795.dat', 4: '3020.dat', 5: '3710.dat', 6: '3666.dat', 7: '3021.dat', 8: '2431.dat', 9: '4488.dat', 10: '3829a.dat', 11: '3829b.dat', 12: '43723.dat', 13: '3068b.dat', 14: '43722.dat', 15: '3832.dat', 16: '2432.dat', 17: '2437.dat', 18: '6231.dat', 19: '3040b.dat', 20: '3024.dat', 21: '11211.dat', 22: '2540.dat', 23: '61678.dat', 24: '3665.dat', 25: '11477.dat', 26: '93594.dat', 27: '50951.dat', 28: '4073.dat', 29: '6019.dat', 30: '6091.dat', 31: '3821.dat', 32: '3822.dat', 33: '98138.dat', 34: '3794a.dat', 35: '4081b.dat', 36: '3022.dat', 37: '30039.dat', 38: '50946.dat', 39: '4095.dat'} #blue_classic_car
label_inverse_mapping = {0: '24308b.dat', 1: '3031.dat', 2: '4079.dat', 3: '3021.dat', 4: '3024.dat', 5: '3020.dat', 6: '29120.dat', 7: '71076a.dat', 8: '3023.dat', 9: '29119.dat', 10: '2412b.dat', 11: '86876.dat', 12: '11211.dat', 13: '87087.dat', 14: '3004.dat', 15: '15068.dat', 16: '3829c01.dat', 17: '11477.dat', 18: '79393.dat', 19: '63864.dat', 20: '3710.dat', 21: 'm17f5892b_2023521_010804.dat', 22: '6141.dat', 23: '85984pc2.dat', 24: '3010.dat', 25: '30414.dat', 26: '2431pt0.dat'}
input_labels = normalized_data[0:-4:stride, :dat_num+1] #
#input_labels[:given] = input_data[:given, -6] #normalized_data[0:-4:stride, :dat_num+1].argmax(1)
input_rot = normalized_data[1:-3:stride, :rot_num+1] #input_data[:, 0] #normalized_data[1:-3:stride, :rot_num+1].argmax(1)
#input_rot[:given] = input_data[:given, 0]
input_coords_x = normalized_data[1+attr_shift:-1:stride, :x_num+1]
input_coords_y = normalized_data[0+attr_shift:-2:stride, :y_num+1]
input_coords_z = normalized_data[2+attr_shift::stride, :z_num+1]
# input_coords_x[:given] = input_data[:given, -5]
# input_coords_y[:given] = input_data[:given, -4]
# input_coords_z[:given] = input_data[:given, -3]
restored_coords = np.stack((input_coords_x, input_coords_y, input_coords_z), axis=-1)
#flag = normalized_data[:, xyz+dat_num:xyz+dat_num+2].argmax(1)
#flag = normalized_data[:, -2:].argmax(1)
input_colors = np.zeros_like(input_data[:, 0])
#input_colors[:given] = (input_colors[:given] + 4)
ldr_lines = []
#for i, entry in enumerate(normalized_data[:-1]):
for i, entry in enumerate(input_data[:-1]):
color = int(input_colors[i])
x, y, z = np.squeeze(restored_coords, axis=1)[i]
label = label_inverse_mapping[str(np.clip(np.round(input_labels[i].item()), 0, dat_num-1).astype(int))]
# quaternion = entry[4:8] #
# quaternion = quaternion / np.linalg.norm(quaternion) #
# r = R.from_quat(quaternion)
rotation_matrix = R24[int(np.clip(input_rot[i].item(), 0, rot_num-1))] #R24[entry[-7]]#r.as_matrix()
if x>212:
f = 0# - flag[i]
else:
f = 1
ldr_line = f"{f} {color} {x:.6f} {y:.6f} {z:.6f} " \
f"{rotation_matrix[0, 0]:.6f} {rotation_matrix[0, 1]:.6f} {rotation_matrix[0, 2]:.6f} " \
f"{rotation_matrix[1, 0]:.6f} {rotation_matrix[1, 1]:.6f} {rotation_matrix[1, 2]:.6f} " \
f"{rotation_matrix[2, 0]:.6f} {rotation_matrix[2, 1]:.6f} {rotation_matrix[2, 2]:.6f} " \
f"{label}\n"
ldr_lines.append(ldr_line)
with open(output_file, 'w') as f:
f.writelines(ldr_lines)
print(f"Restored LDR data saved to {output_file}")
return ldr_lines
def main(input_file):
lines = read_ldr_file(input_file)
processed_data, label_inverse_mapping = process_ldr_data(lines) # 处理LDR数据
inverted_data = logits2ldr(processed_data, label_inverse_mapping) # 将标准化数据转换回原始数据格式
# import ipdb; ipdb.set_trace()
# output_file = os.path.splitext(input_file)[0] + '_wrdhot' + '.npy'
# save_data_as_npy(processed_data, output_file) # 保存为.npy文件
# print(f"Processed data has been saved to {output_file}")
# 示例
input_file = '/public/home/wangshuo/gap/assembly/data/blue classic car/modified_blue classic car.ldr' # 输入LDR文件路径
#main(input_file)
|