import os import pandas as pd import pickle import numpy as np from torch.utils.data import Dataset CLASSES = ["Bag", "Bed", "Bowl","Clock", "Dishwasher", "Display", "Door", "Earphone", "Faucet", "Hat", "StorageFurniture", "Keyboard", "Knife", "Laptop", "Microwave", "Mug", "Refrigerator", "Chair", "Scissors", "Table", "TrashCan", "Vase", "Bottle"] AFFORD_CL = ['lay','sit','support','grasp','lift','contain','open','wrap_grasp','pour', 'move','display','push','pull','listen','wear','press','cut','stab'] def pc_normalize(pc): centroid = np.mean(pc, axis=0) pc = pc - centroid m = np.max(np.sqrt(np.sum(pc**2, axis=1))) pc = pc / m return pc, centroid, m class Corrupt(Dataset): def __init__(self, corrupt_type='scale', level=0 ): #replace with the path to the LASO-C/PIAD-C dataset data_root='LASO-C' file_name = f'{corrupt_type}_{level}.pkl' self.corrupt_type = corrupt_type self.level = level self.cls2idx = {cls.lower():np.array(i).astype(np.int64) for i, cls in enumerate(CLASSES)} self.aff2idx = {cls:np.array(i).astype(np.int64) for i, cls in enumerate(AFFORD_CL)} with open(os.path.join(data_root, 'point', file_name), 'rb') as f: self.anno = pickle.load(f) self.question_df = pd.read_csv(os.path.join(data_root, 'text', 'Affordance-Question.csv')) def find_rephrase(self, df, object_name, affordance): qid = 'Question0' result = df.loc[(df['Object'] == object_name) & (df['Affordance'] == affordance), [qid]] if not result.empty: return result.iloc[0][qid] else: raise NotImplementedError def __getitem__(self, index): data = self.anno[index] cls = data['class'] affordance = data['affordance'] gt_mask = data['mask'] point_set = data['point'] point_set,_,_ = pc_normalize(point_set) question = self.find_rephrase(self.question_df, cls, affordance) affordance = self.aff2idx[affordance] point_input = point_set.transpose() return point_input, self.cls2idx[cls], gt_mask, question, affordance def __len__(self): return len(self.anno)