上一页 1 ··· 23 24 25 26 27 28 29 30 31 ··· 73 下一页
摘要: 1、均匀分布初始化 torch.nn.init.uniform_(tensor, a=0, b=1) 从均匀分布U(a, b)中采样,初始化张量。 参数: tensor - 需要填充的张量 a - 均匀分布的下界 b - 均匀分布的上界 例子: w = torch.empty(3, 5) nn.in 阅读全文
posted @ 2022-03-08 20:09 多发Paper哈 阅读(1025) 评论(0) 推荐(0) 编辑
摘要: 1 导入包 import torch import numpy as np import torch.nn as nn from torch.utils.data import TensorDataset,DataLoader import torchvision from IPython impo 阅读全文
posted @ 2022-03-08 17:46 多发Paper哈 阅读(546) 评论(0) 推荐(0) 编辑
摘要: 1 导入实验需要的包 import torch import numpy as np from torch import nn from torchvision.datasets import MNIST import torchvision.transforms as transforms imp 阅读全文
posted @ 2022-03-08 17:00 多发Paper哈 阅读(544) 评论(0) 推荐(0) 编辑
摘要: 1 保存和加载整个模型 torch.save(model_object, 'model.pth') model = torch.load('model.pth') 2 仅保存和加载模型参数 torch.save(model_obj.state_dict(), 'params.pth') model_ 阅读全文
posted @ 2022-03-08 16:54 多发Paper哈 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 1 导入包 import torch import torch.nn as nn from torch.utils.data import TensorDataset,DataLoader from torch.nn import init import torch.optim as optim f 阅读全文
posted @ 2022-03-07 20:30 多发Paper哈 阅读(474) 评论(0) 推荐(1) 编辑
摘要: 1 导入实验需要的包 import torch from torch import nn import numpy as np import matplotlib.pyplot as plt from torch.utils.data import DataLoader,TensorDataset 阅读全文
posted @ 2022-03-07 19:25 多发Paper哈 阅读(739) 评论(0) 推荐(0) 编辑
摘要: nn.Linear() PyTorch的 nn.Linear() 是用于设置网络中的全连接层的,需要注意在二维图像处理的任务中,全连接层的输入与输出一般都设置为二维张量,形状通常为[batch_size, size],不同于卷积层要求输入输出是四维张量。其用法与形参说明如下: torch.nn.Li 阅读全文
posted @ 2022-03-07 19:10 多发Paper哈 阅读(3878) 评论(0) 推荐(0) 编辑
摘要: 1、二维矩阵乘法 torch.mm() torch.mm(mat1, mat2, out=None) 其中 $\operatorname{mat} 1 \in \mathbb{R}^{n \times m}, \operatorname{mat} 2 \in \mathbb{R}^{m \times 阅读全文
posted @ 2022-03-07 15:40 多发Paper哈 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 1 导入实验需要的包 import numpy as np import torch from torch import nn from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt f 阅读全文
posted @ 2022-03-06 11:56 多发Paper哈 阅读(599) 评论(0) 推荐(0) 编辑
摘要: 这个东西,本质上和nn.BCELoss()没有区别,只是在BCELoss上加了个logits函数(也就是sigmoid函数),例子如下: import torch import torch.nn as nn label = torch.Tensor([1, 1, 0]) pred = torch.T 阅读全文
posted @ 2022-03-06 10:21 多发Paper哈 阅读(989) 评论(0) 推荐(0) 编辑
上一页 1 ··· 23 24 25 26 27 28 29 30 31 ··· 73 下一页
Live2D