学习pytorch7 神经网络的基本骨架--nn,module的使用

神经网络的基本骨架--nn,module的使用

B站小土堆视频学习笔记

官网Module介绍

https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module



Python父类子类继承关系

https://www.php.cn/faq/555151.html

前向神经网络

前向传播

与之对应的还有反向传播

推荐课程

吴恩达卷积

李宏毅深度学习 cnn

同济子豪兄神经网络

pycharm快捷键重写类方法

code-->Generate-->override Methods-->init 重写init方法


code

py 复制代码
import torch
from torch import nn
class my_neural_network(nn.Module):
    def __init__(self):
        super().__init__()
    def forward(self, input):
        output = input + 1
        return output
my_net = my_neural_network()
# x = torch.Tensor(1.0)  # TypeError: new(): data must be a sequence (got float)
x = torch.tensor(1.0)
output = my_net(x)
print(output)

debug

torch.tensor和torch.Tensor的区别

torch.tensor是方法,可以将参数转换为tensor数据类型,输入可以是序列【列表】、元组、ndarray,也可以是单独一个数等多种数据类型

torch.Tensor是一个类 输入参数需要是一个序列比如列表

https://blog.csdn.net/qq_36930266/article/details/104602792

相关推荐
花酒锄作田6 小时前
Pydantic校验配置文件
python
hboot6 小时前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi17 小时前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi18 小时前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽18 小时前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户83580861879119 小时前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L1 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅1 天前
海天线算法的前世今生
python·计算机视觉
韩师傅2 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L2 天前
LangGraph的MessageState and HumanMessage
python