def _new_episode(self, args, episode):
        """ New navigation episode. """
        scene = episode["scene"]

        if self._env is None:
            self._env = Environment(
                offline_data_dir=args.offline_data_dir,
                use_offline_controller=True,
                grid_size=args.grid_size,
                images_file_name=args.images_file_name,
                local_executable_path=args.local_executable_path,
                rotate_by=args.rotate_by,
                state_decimal=args.state_decimal,
                actions = self.actions
            )
            self._env.start(scene)
        else:
            self._env.reset(scene)

        self.environment.controller.state = episode["state"]

        self.task_data = episode["task_data"]
        self.target_object = episode["goal_object_type"]

        if args.verbose:
            print("Scene", scene, "Navigating towards:", self.target_object)

        self.glove_embedding = gpuify(episode["glove_embedding"], self.gpu_id)

        return True
Пример #2
0
    def _new_episode(self, args, episode):
        """ New navigation episode. """
        scene = episode["scene"]

        if self._env is None:
            self._env = Environment(
                offline_data_dir=args.offline_data_dir,
                use_offline_controller=True,
                grid_size=0.25,
                images_file_name=args.images_file_name,
                local_executable_path=args.local_executable_path,
            )
            # print('###################')
            self._env.start(scene)
            # print('$$$$$$$$$$$$$$$$$$$')
        else:
            # print("^^^^^^^^^^^^^^^^^^^^")
            self._env.reset(scene)
            # print('&&&&&&&&&&&&')
        # print('@@@@@@@@@@@@@@@@@@@@@@@')
        self.environment.controller.state = episode["state"]

        self.task_data = episode["task_data"]
        self.target_object = episode["goal_object_type"]

        if args.verbose:
            # print("!!!!!!!!!!!!!!!!!!!!!!")
            print("Scene", scene, "Navigating towards:", self.target_object)

        self.glove_embedding = gpuify(episode["glove_embedding"], self.gpu_id)

        return True
Пример #3
0
 def eval_at_state(self):
     model_input = ModelInput()
     model_input.state = self.preprocess_frame(
         self.episode.state_for_agent())
     model_input.hidden = self.hidden
     model_input.additional_state_info = gpuify(
         torch.Tensor(self.info[1]).unsqueeze(0), self.gpu_id)
     model_output = self.model.forward(model_input)
     return model_output
Пример #4
0
 def reset_hidden(self):
     if self.gpu_id >= 0:
         with torch.cuda.device(self.gpu_id):
             self.hidden = (
                 torch.zeros(1, self.hidden_state_sz).cuda(),
                 torch.zeros(1, self.hidden_state_sz).cuda(),
             )
     else:
         self.hidden = (
             torch.zeros(1, self.hidden_state_sz),
             torch.zeros(1, self.hidden_state_sz),
         )
     self.last_action_probs = gpuify(torch.zeros((1, self.action_space)),
                                     self.gpu_id)
Пример #5
0
    def eval_at_state(self, model_options, frame):
        model_input = ModelInput()
        #         if self.episode.current_frame is None:
        #             model_input.state = self.state()
        #         else:
        #             model_input.state = self.episode.current_frame
        #process_frame to shape [1,3,224,224], for input to resnet18
        processed_frame = self.preprocess_frame(
            resnet_input_transform(frame, 224).unsqueeze(0))
        resnet18_features = self.resnet18(processed_frame)

        model_input.state = resnet18_features
        model_input.hidden = self.hidden
        model_input.target_class_embedding = gpuify(torch.Tensor(
            self.target_glove_embedding),
                                                    gpu_id=self.gpu_id)
        model_input.action_probs = self.last_action_probs

        return model_input, self.model.forward(model_input, model_options)
Пример #6
0
 def preprocess_frame(self, frame):
     """ Preprocess the current frame for input into the model. """
     state = torch.Tensor(frame)
     return gpuify(state, self.gpu_id)
Пример #7
0
 def target_object_index(self, target_object_index):
     """ Set the target object by specifying the index. """
     self._target_object_index = gpuify(
         torch.LongTensor([target_object_index]), self.gpu_id)
Пример #8
0
 def preprocess_frame(self, frame):
     """ Preprocess the current frame for input into the model. """
     frame = resnet_input_transform(frame, 84)
     state = torch.Tensor(frame)
     return gpuify(state.unsqueeze(0), self.gpu_id)
Пример #9
0
 def preprocess_memory(self, memory):
     """ Preprocess the current memory for input into the model. """
     memory = torch.Tensor(memory)
     return gpuify(memory.unsqueeze(0), self.gpu_id)
Пример #10
0
 def augState(self):
     ## convert self.episode.additional_state_info to tensor compatible with agent
     augTensor = torch.tensor(
         self.episode.additional_state_info.astype(float))
     return gpuify(augTensor.unsqueeze(0), self.gpu_id)
Пример #11
0
 def preprocess_frame(self, frame):
     """ Preprocess the current frame for input into the model. """
     frame_numpy = np.ascontiguousarray(frame)
     state = torch.Tensor(frame_numpy)
     return gpuify(state, self.gpu_id)
Пример #12
0
 def preprocess_triedFind(self, triedFind):
     state = torch.Tensor([triedFind['Tomato'], triedFind['Bowl']])
     return gpuify(state.unsqueeze(0), self.gpu_id)
Пример #13
0
 def eval_at_state(self, params=None):
     critic = torch.ones(1, 1)
     actor = torch.ones(1, self.action_space)
     critic = gpuify(critic, self.gpu_id)
     actor = gpuify(actor, self.gpu_id)
     return ModelInput(), ModelOutput(value=critic, logit=actor)