def setup(): os.chdir('../simulation/') if platform == 'darwin': os.system('open ./exec_mac.app') else: os.system('./linux_sim.x86_64') from unity_simulator.comm_unity import UnityCommunication comm = UnityCommunication() return comm
############################################################## writedir = stimulusdirname + '/apartment_' + str(env_id) + '/' if os.path.exists(writedir): print('folder already exists') else: os.mkdir(writedir) writedirjason = jasondirname + '/apartment_' + str(env_id) + '/' if os.path.exists(writedirjason): print('folder already exists') else: os.mkdir(writedirjason) # start simulation (only once for each apartment) comm = UnityCommunication() comm.reset(env_id) #comm.setBathroomTexture(env_id) #wantedgraph = pickle.load( open( graphdirname + '/apartment_' + str(env_id) + ".pkl", "rb" ) ) #print(wantedgraph) res, origraph = comm.environment_graph() for node in origraph['nodes']: target_id = node['id'] #target object to recognize targetprefabname = node['prefab_name'] #remove those objects not belong to these general cateogires if node['class_name'] not in wantedClass: continue
os.mkdir(graphdirname) #pre-setup rules for context and a list of wanted classes wanted = pickle.load( open( "wanted.pkl", "rb" ) ) SurfaceToRoom = np.array(wanted['SurfaceToRoom']) ItemToRoom = np.array(wanted['ItemToRoom']) RoomList = wanted['RoomList'] SurfaceList = wanted['SurfaceList'] wantedClass = wanted['wantedClass'] for target_classname in wantedClass: for env_id in range(7): # env_id ranges from 0 to 6 # start simulation (only once for each apartment) comm = UnityCommunication() comm.reset(env_id) #comm.setBathroomTexture(env_id) #============================ START PYTHON SCRIPT =========================== response, origraph = comm.environment_graph() origraph = deleteGraphByClassname(origraph, target_classname) success, message = comm.expand_scene(origraph) #print(origraph) #exit() #loop through all nodes and check whether we have wanted DestIds, DestPrefabs, destRooms, destSurface = findAllPossibleDestNodes(target_classname, wantedClass, ItemToRoom, SurfaceToRoom, RoomList, SurfaceList, origraph) #loop through missed classes #randomly sample prefab from it and add to the graph for i, destid in enumerate(DestIds):
random_seed=seed) messages_expand.append(message) _ = comm.camera_image(cameras_select, mode='normal', image_height=480, image_width=640) ok, imgs = comm.camera_image(cameras_select, mode='normal', image_height=480, image_width=640) images.append(imgs) return messages_expand, images comm = UnityCommunication() print('Inferring preconditions...') preconds = add_preconds.get_preconds_script(script).printCondsJSON() print(preconds) print('Loading graph') with open(graph_input, 'r') as f: graph_input = json.load(f) print('Executing script') print(script) info = check_programs.check_script(script, preconds, graph_path=None, inp_graph_dict=graph_input)
#!/usr/local/bin/python # Generate video for a program. Make sure you have the executable open import sys sys.path.append('../simulation/') from unity_simulator.comm_unity import UnityCommunication script = ['[Walk] <sofa> (1)', '[Sit] <sofa> (1)'] # Add here your script print('Starting Unity...') comm = UnityCommunication() print('Starting scene...') comm.reset(4) print('Generating video...') comm.render_script(script, output_folder='unity_vol/Output/', image_synthesis='seg_inst', capture_screenshot=True) print('Generated, find video in simulation/unity_simulator/output/')
# Generate video for a program. Make sure you have the executable open import sys sys.path.append('../simulation/') from unity_simulator.comm_unity import UnityCommunication script = ['[Walk] <sofa> (1)', '[Sit] <sofa> (1)'] # Add here your script print('Starting Unity...') comm = UnityCommunication() print('Starting scene...') comm.reset() print('Generating video...') comm.render_script(script, capture_screenshot=True) print('Generated, find video in simulation/unity_simulator/output/')
# Generate video for a program. Make sure you have the executable open import sys sys.path.append('../simulation/') from unity_simulator.comm_unity import UnityCommunication script = [ '<char0> [Walk] <tv> (1)', '<char0> [switchon] <tv> (1)', '<char0> [Walk] <sofa> (1)', '<char0> [Sit] <sofa> (1)', '<char0> [Watch] <tv> (1)' ] # Add here your script print('Starting Unity...') comm = UnityCommunication() print('Starting scene...') comm.reset() comm.add_character('Chars/Female1') print('Generating video...') comm.render_script(script, recording=True, find_solution=True) print('Generated, find video in simulation/unity_simulator/output/')
cameras_select = [cameras_select[x] for x in cameras_ids] seed = random.randint(1,100) messages_expand, images = [], [] for graph_state in tqdm(graph_state_list): comm.reset(0) message = comm.expand_scene(graph_state, randomize=True, random_seed=seed) messages_expand.append(message) _ = comm.camera_image(cameras_select, mode='normal', image_height=480, image_width=640) ok, imgs = comm.camera_image(cameras_select, mode='normal', image_height=480, image_width=640) images.append(imgs) return messages_expand, images comm = UnityCommunication() print('Inferring preconditions...') preconds = add_preconds.get_preconds_script(script).printCondsJSON() print(preconds) print('Loading graph') comm.reset(0) _, graph_input = comm.environment_graph() print('Executing script') print(script) info = check_programs.check_script( script, preconds, graph_path=None, inp_graph_dict=graph_input) message, final_state, graph_state_list, graph_dict, id_mapping, info, helper, modif_script = info success = (message == 'Script is executable')
############################################################## writedir = stimulusdirname + '/apartment_' + str(env_id) + '/' if os.path.exists(writedir): print('folder already exists') else: os.mkdir(writedir) writedirjason = jasondirname + '/apartment_' + str(env_id) + '/' if os.path.exists(writedirjason): print('folder already exists') else: os.mkdir(writedirjason) # start simulation (only once for each apartment) comm = UnityCommunication() comm.reset(env_id) #comm.setBathroomTexture(env_id) #wantedgraph = pickle.load( open( graphdirname + '/apartment_' + str(env_id) + ".pkl", "rb" ) ) #print(wantedgraph) _, message = comm.expand_scene(wantedgraph) #============================ START PYTHON SCRIPT =========================== res, origraph = comm.environment_graph() totalnodes = len(origraph['nodes']) #print(origraph) #for node in origraph['nodes']: material_id = random.randint(0, NumTotalMaterials - 1) target_id = node['id'] #target object to recognize #for debugging; comment out