当前位置: 首页> 游戏> 游戏 > 网站的优化哪个好_如何做免费的网站推广_温州网站建设_关键词搜索排名公司

网站的优化哪个好_如何做免费的网站推广_温州网站建设_关键词搜索排名公司

时间:2025/7/10 13:51:19来源:https://blog.csdn.net/qq358660877/article/details/144918320 浏览次数:0次
网站的优化哪个好_如何做免费的网站推广_温州网站建设_关键词搜索排名公司

1.准备好网络模型代码

import torch
import torch.nn as nn
import torch.optim as optim# BP_36: 输入2个节点,中间层36个节点,输出25个节点
class BP_36(nn.Module):def __init__(self):super(BP_36, self).__init__()self.fc1 = nn.Linear(2, 36)  # 输入2个节点,中间层36个节点self.fc2 = nn.Linear(36, 25)  # 输出25个节点def forward(self, x):x = torch.relu(self.fc1(x))  # 使用ReLU激活函数x = self.fc2(x)return x# BP_64: 输入2个节点,中间层64个节点,输出25个节点
class BP_64(nn.Module):def __init__(self):super(BP_64, self).__init__()self.fc1 = nn.Linear(2, 64)  # 输入2个节点,中间层64个节点self.fc2 = nn.Linear(64, 25)  # 输出25个节点def forward(self, x):x = torch.relu(self.fc1(x))  # 使用ReLU激活函数x = self.fc2(x)return x# Bi-LSTM: 输入2个节点,中间层36个节点,线性层输入72个节点,输出25个节点
class Bi_LSTM(nn.Module):def __init__(self):super(Bi_LSTM, self).__init__()self.lstm = nn.LSTM(input_size=2, hidden_size=36, bidirectional=True, batch_first=True)  # 双向LSTMself.fc1 = nn.Linear(72, 25)  # LSTM的输出72维,经过线性层后输出25个节点def forward(self, x):# x的形状应该是(batch_size, seq_len, input_size)x, _ = self.lstm(x)  # 输出LSTM的结果x = self.fc1(x)return x# Bi-GRU: 输入2个节点,中间层36个节点,线性层输入72个节点,输出25个节点
class Bi_GRU(nn.Module):def __init__(self):super(Bi_GRU, self).__init__()self.gru = nn.GRU(input_size=2, hidden_size=36, bidirectional=True, batch_first=True)  # 双向GRUself.fc1 = nn.Linear(72, 25)  # GRU的输出72维,经过线性层后输出25个节点def forward(self, x):# x的形状应该是(batch_size, seq_len, input_size)x, _ = self.gru(x)  # 输出GRU的结果x = self.fc1(x)return x

2.运行计算参数量和复杂度的脚本

import torch
# from net import BP_36
# from net import BP_64
# from net import Bi_LSTM
from net import Bi_GRUfrom ptflops import get_model_complexity_info
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")# 统计Transformer模型的参数量和计算复杂度
model_transformer = Bi_GRU()
model_transformer.to(device)
flops_transformer, params_transformer = get_model_complexity_info(model_transformer, (256,2), as_strings=True, print_per_layer_stat=False)
print('模型参数量:' + params_transformer)
print('模型计算复杂度:' + flops_transformer)
关键字:网站的优化哪个好_如何做免费的网站推广_温州网站建设_关键词搜索排名公司

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: