def forward(self, obs): h = self.pre_fc(obs) mu, log_std = self.fc(h).chunk(2, dim=-1) # constrain log_std inside [log_std_min, log_std_max] log_std = torch.tanh(log_std) log_std_min, log_std_max = self.log_std_bounds log_std = log_std_min + 0.5 * (log_std_max - log_std_min) * (log_std + 1) std = log_std.exp() dist = utils.SquashedNormal(mu, std) return dist
def forward(self, obs, detach_encoder=False): obs = self.encoder(obs, detach=detach_encoder) mu, log_std = self.trunk(obs).chunk(2, dim=-1) # constrain log_std inside [log_std_min, log_std_max] log_std = torch.tanh(log_std) log_std_min, log_std_max = self.log_std_bounds log_std = log_std_min + 0.5 * (log_std_max - log_std_min) * (log_std + 1) std = log_std.exp() self.outputs['mu'] = mu self.outputs['std'] = std dist = utils.SquashedNormal(mu, std) return dist
def forward(self, observation, desired_goal, detach_encoder=False): observation = self.encoder(observation, desired_goal, detach=detach_encoder) mu, log_std = self.trunk(observation).chunk(2, dim=-1) # constrain log_std inside [log_std_min, log_std_max] log_std = torch.tanh(log_std) log_std_min, log_std_max = self.log_std_bounds log_std = log_std_min + 0.5 * (log_std_max - log_std_min) * (log_std + 1) std = log_std.exp() dist = utils.SquashedNormal(mu, std) return dist
def noise(self, obs, n, detach_encoder=False): obs = self.encoder(obs, detach=detach_encoder) obs[0][np.random.choice(range(len(obs[0])), n, replace=False)] = 0 mu, log_std = self.trunk(obs).chunk(2, dim=-1) # constrain log_std inside [log_std_min, log_std_max] log_std = torch.tanh(log_std) log_std_min, log_std_max = self.log_std_bounds log_std = log_std_min + 0.5 * (log_std_max - log_std_min) * (log_std + 1) std = log_std.exp() self.outputs['mu'] = mu self.outputs['std'] = std dist = utils.SquashedNormal(mu, std) return dist
def forward(self, obs, detach_encoder=False): img, robot_state = split_obs(obs) conv_features = self.encoder(img, detach=detach_encoder) robot_state_out = self.state_input(robot_state) h1 = torch.cat((conv_features, robot_state_out), 1) mu, log_std = self.trunk(h1).chunk(2, dim=-1) # constrain log_std inside [log_std_min, log_std_max] log_std = torch.tanh(log_std) log_std_min, log_std_max = self.log_std_bounds log_std = log_std_min + 0.5 * (log_std_max - log_std_min) * (log_std + 1) std = log_std.exp() self.outputs['mu'] = mu self.outputs['std'] = std dist = utils.SquashedNormal(mu, std) return dist
def forward(self, obs, state_goals=None, detach_encoder=False): obs = self.encoder(obs, detach=detach_encoder) if state_goals is not None: if len(state_goals.shape) > len(obs.shape): state_goals = torch.squeeze(state_goals, 1) obs = torch.cat((obs, state_goals), axis=-1) mu, log_std = self.trunk(obs).chunk(2, dim=-1) # constrain log_std inside [log_std_min, log_std_max] log_std = torch.tanh(log_std) log_std_min, log_std_max = self.log_std_bounds log_std = log_std_min + 0.5 * (log_std_max - log_std_min) * (log_std + 1) std = log_std.exp() self.outputs['mu'] = mu self.outputs['std'] = std dist = utils.SquashedNormal(mu, std) return dist