最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

pytorch 初始化

维修 admin 33浏览 0评论

pytorch 初始化

初始化

import matplotlib.pyplot as plt
import torch
import torch.nn as nn
from torch.utils.data import Dataset,DataLoader
import torch.optim as optim
import numpy as np
random_seed=1000
# np.random.seed(random_seed)
torch.manual_seed(random_seed)#自定义损失函数
class my_loss(nn.Module):def __init__(self):super().__init__()def forward(self, x, y):# loss = nn.L1Loss()(x,y)# loss=nn.MSELoss()(x,y)# total_sum=torch.sum(torch.pow(x,2)+torch.pow(y,2))# total_sum = torch.sum(torch.pow(x, 2))# loss=torch.div(loss,total_sum)# loss=torch.mean(torch.sub(y,x))loss=torch.mean(torch.pow(torch.abs(torch.sub(y,x)),1))return loss
# 定义模型
class TheModelClass(nn.Module):def __init__(self):hidden=15super(TheModelClass, self).__init__()self.fc1 = nn.Linear(1,hidden)# self.relu=nn.Sigmoid()

pytorch 初始化

初始化

import matplotlib.pyplot as plt
import torch
import torch.nn as nn
from torch.utils.data import Dataset,DataLoader
import torch.optim as optim
import numpy as np
random_seed=1000
# np.random.seed(random_seed)
torch.manual_seed(random_seed)#自定义损失函数
class my_loss(nn.Module):def __init__(self):super().__init__()def forward(self, x, y):# loss = nn.L1Loss()(x,y)# loss=nn.MSELoss()(x,y)# total_sum=torch.sum(torch.pow(x,2)+torch.pow(y,2))# total_sum = torch.sum(torch.pow(x, 2))# loss=torch.div(loss,total_sum)# loss=torch.mean(torch.sub(y,x))loss=torch.mean(torch.pow(torch.abs(torch.sub(y,x)),1))return loss
# 定义模型
class TheModelClass(nn.Module):def __init__(self):hidden=15super(TheModelClass, self).__init__()self.fc1 = nn.Linear(1,hidden)# self.relu=nn.Sigmoid()

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论