sac网络搭建(遇到的各种坑)

1.actor网络居然是两个分支????

答:

以下面代码为例,与ddpg的actor网络不同,该网络有两个返回值,两个返回值通常用于构建一个正太分布,从而生成动作。

复制代码
class Actor(nn.Module):
    def __init__(self, state_dim, min_log_std=-20, max_log_std=2):
        super(Actor, self).__init__()
        self.fc1 = nn.Linear(state_dim, 256)
        self.fc2 = nn.Linear(256, 256)
        self.mu_head = nn.Linear(256, 1)
        self.log_std_head = nn.Linear(256, 1)
        self.min_log_std = min_log_std
        self.max_log_std = max_log_std

    def forward(self, x):
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        mu = self.mu_head(x)
        log_std_head = F.relu(self.log_std_head(x))
        log_std_head = torch.clamp(log_std_head, self.min_log_std, self.max_log_std)
        return mu, log_std_head

2.actor网络需要return两个数值:mean和std

答:

使用两个返回值得到具体的动作

复制代码
import torch
import torch.distributions as D

# 假设 x 是状态输入
mu, log_std = actor(x)  # actor 是你的 Actor 实例

# 计算标准差
std = torch.exp(log_std)

# 创建正态分布
dist = D.Normal(mu, std)

3.critc与actor网络之间的对应关系

答:在第一次调试sac代码过程中出现tensor.shape不对应的问题

相关推荐
田里的水稻1 天前
ubuntu22.04_openclaw_ROS2
人工智能·python·机器人
梁正雄1 天前
Python前端-2-css练习
前端·css·python
wefly20171 天前
开发者效率神器!jsontop.cn一站式工具集,覆盖开发全流程高频需求
前端·后端·python·django·flask·前端开发工具·后端开发工具
6+h1 天前
【java】基本数据类型与包装类:拆箱装箱机制
java·开发语言·python
GDAL1 天前
MANIFEST.in简介
linux·服务器·前端·python
MoRanzhi12031 天前
pillow 图像合成、透明叠加与蒙版处理
python·计算机视觉·pillow·图片处理·图像合成·透明叠加·多图层叠加
双叶8361 天前
(Python)Python爬虫入门教程:从零开始学习网页抓取(爬虫教学)(Python教学)
后端·爬虫·python·学习
泥壳AI1 天前
[特殊字符] OpenClaw + 飞书集成超详细教程
人工智能·python·深度学习·阿里云·飞书
威联通网络存储1 天前
编织数智转型的底座:某中型服装制造企业基于威联通的存储实践
python
6+h1 天前
【Spring】Bean的生命周期详解
java·python·spring