def __init__(self, traj_dir, house_id=args.house_id, traj_id=None, load_graph=True): self.house_id = house_id self.traj_dir = traj_dir if house_id != None: self.create_env(args.config_path, house_id, args.render_width, args.render_height) # Contains methods for calculataing distances, room location, etc self.hp = HouseParse(dataDir=args.data_dir) # Loads house graph and generates shortest paths self.utils = House3DUtils( self.env, rotation_sensitivity=45, target_obj_conn_map_dir=False, # Changed load_graph method to use pickle directly and Graph(g) initialisation; # self.graph.load(path) left the graph empty! build_graph=load_graph, graph_dir=args.graph_dir) self.house = {} self.current_room = None self.env_coors = None self.traj_id = None if traj_id != None: self.update_trajectory(traj_id)
parser.add_argument('--HouseApiDir', default='../pyutils/House3D', help='house3d api dir') parser.add_argument('--cacheDir', default='../cache/question-gen-outputs', help='directory for saving generated questions') parser.add_argument('--outputJson', default='questions_from_engine_v2.json', help='output json file') parser.add_argument('--object_counts_by_room_file', default='env_lists/800env_object_counts_by_room.json', help='roomTp to objT to cnt') parser.add_argument('--env_obj_colors_file', default='env_lists/env_obj_colors_v2.json', help='obj to color mapping') args = parser.parse_args() # load splits splits = json.load(open(osp.join(args.dataDir, 'eqa_v1', args.dataJson), 'r'))['splits'] for split, hids in splits.items(): print('There are %s %s house_ids.' % (len(hids), split)) house_ids = [hid for split, hids in splits.items() for hid in hids] print('There are in all %s house_ids.' % len(house_ids)) # HouseParse and QA-engine Hp = HouseParse(dataDir=osp.join(args.dataDir, 'SUNCGdata'), objrenderPath=osp.join(args.HouseApiDir, 'House3D')) E = Engine(args.object_counts_by_room_file, args.env_obj_colors_file) # # try one house # hid = splits['train'][2] # Hp.parse(hid); E.cacheHouse(Hp) # qns = E.executeFn(E.template_defs['room_size_compare']) # pprint(qns) # SAVE QUESTIONS TO A JSON FILE T = ['object_dist_compare', 'object_color_compare', 'object_size_compare', 'room_size_compare'] # T = E.template_defs.keys() num_envs = len(house_ids) idx, all_qns = 0, [] empty_envs = [] for i in tqdm(range(num_envs)):
default="data/working/questions.json") parser.add_argument("-dataDir", help="Directory that has the SUNCG dataset", default="/path/to/suncg/") parser.add_argument("-numEnvs", help="No. of environments to read", default=False) args = parser.parse_args() data = json.load(open(args.inputJson, 'r')) house_ids = list(data.keys()) num_envs = len(house_ids) if args.numEnvs != False: num_envs = int(args.numEnvs) Hp = HouseParse(dataDir=args.dataDir) E = Engine() # SAVE QUESTIONS TO A JSON FILE # # -- STARTS HERE idx, all_qns = 1, [] empty_envs = [] for i in tqdm(range(num_envs)): Hp.parse(house_ids[i]) num_qns_for_house = 0 for j in E.template_defs: if j == 'global_object_count': continue E.cacheHouse(Hp) qns = E.executeFn(E.template_defs[j])