深度学习
纵浪大化中,喜,惧
这个作者很懒,什么都没留下…
展开
-
rpg_vid2e环境配置问题
rpg_vid2e环境配置原创 2022-11-22 16:32:28 · 312 阅读 · 1 评论 -
networkx画multiplex图
networkx画多层网络原创 2021-12-12 10:11:52 · 1513 阅读 · 1 评论 -
pytorch交叉熵损失函数研究
使用这个损失函数可以很方便的避免上溢和下溢nn.CrossEntropyLoss()官方文档自己写的代码:def cross_entropy(y_hat=torch.tensor(0), y=torch.tensor(0)): numerator = y_hat[range(len(y_hat)),y] denominator = torch.log(torch.sum(torch.exp(y_hat),1)) l = -numerator+denominator .原创 2021-11-22 21:06:31 · 780 阅读 · 0 评论 -
pytorch广播机制
和numpy一样可以进行广播的条件:1Each tensor has at least one dimension.2When iterating over the dimension sizes, starting at the trailing dimension(从右向左), the dimension sizes must either be equal, one of them is 1, or one of them does not exist.怎么广播?dimensions wi原创 2021-11-21 16:04:20 · 347 阅读 · 0 评论 -
transforms的compose类
def load_data(batch_size,resize=None): trans = [transforms.ToTensor()] if resize: trans.insert(0,transforms.Resize(resize)) trans = transforms.Compose(trans) mnist_train = torchvision.datasets.FashionMNIST( root="../data", t原创 2021-11-21 12:17:29 · 542 阅读 · 0 评论 -
pytorch dataset类和os库的使用
from torch.utils.data import Datasetimport cv2from PIL import Imageimport osclass MyDate(Dataset): def __init__(self,root_dir,label_dir): self.root_dir=root_dir self.label_dir=label_dir self.path=os.path.join(self.root_dir,原创 2021-11-15 15:22:18 · 662 阅读 · 0 评论 -
使用pytorch高级api实现线性回归
import torchfrom matplotlib import pyplot as pltimport numpy as npfrom torch.utils import dataimport torchfrom torch import nnfrom collections.abc import Iterator,Iterable# y = 7*x1+8*x2+5true_w = torch.tensor([7.0,8.0])true_b = torch.tensor([5.0]原创 2021-11-08 22:38:27 · 1071 阅读 · 0 评论 -
线性回归实现
import torchfrom matplotlib import pyplot as pltimport numpy as np# y=5*x1+3*x2+4true_w = torch.tensor([5,3],dtype=torch.float32)true_b = torch.tensor([4])# 生成数据就def generate_data(w,b,num_examples): x = torch.normal(0,1,(num_examples,len(w)))原创 2021-11-07 11:16:22 · 43 阅读 · 0 评论