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不对应的问题

相关推荐
IVEN_2 天前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发
python·全栈
Ray Liang2 天前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮2 天前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
千寻girling2 天前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python
AI攻城狮2 天前
用 Playwright 实现博客一键发布到稀土掘金
python·自动化运维
曲幽2 天前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
孟健2 天前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞2 天前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽3 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers