pytorch---1.基础知识

Mininet 2.2.1 图形可视化界面使用注意事项 前言 关于mininet的安装,网上教程不少,大致可以参考以下这篇文章: https://blog.csdn.net/linyixiao88/article/details/65651390 安装的时候,也可以不必根据上面这篇文章这么麻烦,直接sudo apt-get install mininet,即可。 Mininet可视化 Mininet 2.2.0以上版本内置了... 阅读详情

(从B站某个大佬搬过来的,在加上自己的一些笔记,仅供自己参考)
B站pytorch视频
第一课
什么是PyTorch?
PyTorch是一个基于Python的科学计算库,它有以下特点:

类似于NumPy,但是它可以使用GPU
可以用它定义深度学习模型,可以灵活地进行深度学习模型的训练和使用
Tensors
Tensor类似与NumPy的ndarray,唯一的区别是Tensor可以在GPU上加速运算。

Torch 自称为神经网络界的 Numpy, 因为他能将 torch 产生的 tensor 放在 GPU 中加速运算 (前提是你有合适的 GPU), 就像 Numpy 会把 array 放在 CPU 中加速运算. 所以神经网络的话, 当然是用 Torch 的 tensor 形式数据最好咯. 就像 Tensorflow 当中的 tensor 一样.

当然, 我们对 Numpy 还是爱不释手的, 因为我们太习惯 numpy 的形式了. 不过 torch 看出来我们的喜爱, 他把 torch 做的和 numpy 能很好的兼容. 比如这样就能自由地转换 numpy array 和 torch tensor 了(以下代码都是V1.0.1版本的)

from __future__ import print_function
import torch
#构造一个未初始化的5x3矩阵:
x = torch.empty(5, 3)
print(x)

构建一个随机初始化的矩阵:

x = torch.rand(5, 3)
print(x)

构建一个全部为0,类型为long的矩阵:

x = torch.zeros(5, 3, dtype=torch.long)
print(x)

从数据直接直接构建tensor:

x = torch.tensor([5.5, 3])
print(x)

也可以从一个已有的tensor构建一个tensor。这些方法会重用原来tensor的特征,例如,数据类型,除非提供新的数据。

x = x.new_ones(5, 3, dtype=torch.double)      # new_* methods take in sizes
print(x)

x = torch.randn_like(x, dtype=torch.float)    # override dtype!
print(x)                                      # result has the same size

得到tensor的形状:


print(x.size())
torch.Size([5, 3])
#注意
#``torch.Size`` 返回的是一个tuple

Operations

有很多种tensor运算。我们先介绍加法运算。

y = torch.rand(5, 3)
print(x + y)

另一种着加法的写法

print(torch.add(x, y))

加法:把输出作为一个变量

result = torch.empty(5, 3)
torch.add(x, y, out=result)
print(result)

in-place加法

#adds x to y
y.add_(x)
print(y)

注意
任何in-place的运算都会以_结尾。 举例来说:x.copy_(y), x.t_(), 会改变 x。

各种类似NumPy的indexing都可以在PyTorch tensor上面使用。

print(x[:, 1])

Resizing: 如果你希望resize/reshape一个tensor,可以使用torch.view:

x = torch.randn(4, 4)
y = x.view(16)
z = x.view(-1, 8)  # the size -1 is inferred from other dimensions
print(x.size(), y.size(), z.size())
torch.Size([4, 4]) torch.Size([16]) torch.Size([2, 8])

如果你有一个只有一个元素的tensor,使用.item()方法可以把里面的value变成Python数值。

x = torch.randn(1)
print(x)
print(x.item())

更多阅读
各种Tensor operations, 包括transposing, indexing, slicing, mathematical operations, linear algebra, random numbers在 pytorch文档

Numpy和Tensor之间的转化
在Torch Tensor和NumPy array之间相互转化非常容易。

Torch Tensor和NumPy array会共享内存,所以改变其中一项也会改变另一项。

把Torch Tensor转变成NumPy Array

a = torch.ones(5)
print(a)
b = a.numpy()
print(b)

改变numpy array里面的值。

Ia.add_(1)
print(a)
print(b)

把NumPy ndarray转成Torch Tensor

import numpy as np
a = np.ones(5)
b = torch.from_numpy(a)
np.add(a, 1, out=a)
print(a)
print(b)

所有CPU上的Tensor都支持转成numpy或者从numpy转成Tensor。

CUDA Tensors(只有计算tensorGPU才有用吧)
使用.to方法,Tensor可以被移动到别的device上。

# let us run this cell only if CUDA is available
# We will use ``torch.device`` objects to move tensors in and out of GPU

if torch.cuda.is_available():
    device = torch.device("cuda")          # a CUDA device object
    y = torch.ones_like(x, device=device)  # directly create a tensor on GPU
    x = x.to(device)                       # or just use strings ``.to("cuda")``
    z = x + y
    print(z)
    print(z.to("cpu", torch.double))       # ``.to`` can also change dtype together!

热身: 用numpy实现两层神经网络
一个全连接ReLU神经网络,一个隐藏层,没有bias。用来从x预测y,使用L2 Loss。

这一实现完全使用numpy来计算前向神经网络,loss,和反向传播。

numpy ndarray是一个普通的n维array。它不知道任何关于深度学习或者梯度(gradient)的知识,也不知道计算图(computation graph),只是一种用来计算数学运算的数据结构。

import numpy as np

# N is batch size; D_in is input dimension;
# H is hidden dimension; D_out is output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10

# Create random input and output data
x = np.random.randn(N, D_in)
y = np.random.randn(N, D_out)

# Randomly initialize weights
w1 = np.random.randn(D_in, H)
w2 = np.random.randn(H, D_out)

learning_rate = 1e-6
for t in range(500):
    # Forward pass: compute predicted y
    h = x.dot(w1)
    h_relu = np.maximum(h, 0)
    y_pred = h_relu.dot(w2)

    # Compute and print loss
    loss = np.square(y_pred - y).sum()
    print(t, loss)

    # Backprop to compute gradients of w1 and w2 with respect to loss
    
    # loss = (y_pred - y) ** 2
    grad_y_pred = 2.0 * (y_pred - y)
    # 
    grad_w2 = h_relu.T.dot(grad_y_pred)
    grad_h_relu = grad_y_pred.dot(w2.T)
    grad_h = grad_h_relu.copy()
    grad_h[h < 0] = 0
    grad_w1 = x.T.dot(grad_h)

    # Update weights
    w1 -= learning_rate * grad_w1
    w2 -= learning_rate * grad_w2

PyTorch: Tensors
这次我们使用PyTorch tensors来创建前向神经网络,计算损失,以及反向传播。

一个PyTorch Tensor很像一个numpy的ndarray。但是它和numpy ndarray最大的区别是,PyTorch Tensor可以在CPU或者GPU上运算。如果想要在GPU上运算,就需要把Tensor换成cuda类型。

import torch


dtype = torch.float
device = torch.device("cpu")
# device = torch.device("cuda:0") # Uncomment this to run on GPU

# N is batch size; D_in is input dimension;
# H is hidden dimension; D_out is output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10

# Create random input and output data
x = torch.randn(N, D_in, device=device, dtype=dtype)
y = torch.randn(N, D_out, device=device, dtype=dtype)

# Randomly initialize weights
w1 = torch.randn(D_in, H, device=device, dtype=dtype)
w2 = torch.randn(H, D_out, device=device, dtype=dtype)

learning_rate = 1e-6
for t in range(500):
    # Forward pass: compute predicted y
    h = x.mm(w1)
    h_relu = h.clamp(min=0)
    y_pred = h_relu.mm(w2)

    # Compute and print loss
    loss = (y_pred - y).pow(2).sum().item()
    print(t, loss)

    # Backprop to compute gradients of w1 and w2 with respect to loss
    grad_y_pred = 2.0 * (y_pred - y)
    grad_w2 = h_relu.t().mm(grad_y_pred)
    grad_h_relu = grad_y_pred.mm(w2.t())
    grad_h = grad_h_relu.clone()
    grad_h[h < 0] = 0
    grad_w1 = x.t().mm(grad_h)

    # Update weights using gradient descent
    w1 -= learning_rate * grad_w1
    w2 -= learning_rate * grad_w2

简单的autograd(反向传播):

# Create tensors.
x = torch.tensor(1., requires_grad=True)
w = torch.tensor(2., requires_grad=True)
b = torch.tensor(3., requires_grad=True)

# Build a computational graph.
y = w * x + b    # y = 2 * x + 3

# Compute gradients.
y.backward()

# Print out the gradients.
print(x.grad)    # x.grad = 2 
print(w.grad)    # w.grad = 1 
print(b.grad)    # b.grad = 1 

PyTorch: Tensor和autograd
PyTorch的一个重要功能就是autograd,也就是说只要定义了forward pass(前向神经网络),计算了loss之后,PyTorch可以自动求导计算模型所有参数的梯度。

一个PyTorch的Tensor表示计算图中的一个节点。如果x是一个Tensor并且x.requires_grad=True那么x.grad是另一个储存着x当前梯度(相对于一个scalar,常常是loss)的向量。

import torch

dtype = torch.float
device = torch.device("cpu")
# device = torch.device("cuda:0") # Uncomment this to run on GPU

# N 是 batch size; D_in 是 input dimension;
# H 是 hidden dimension; D_out 是 output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10

# 创建随机的Tensor来保存输入和输出
# 设定requires_grad=False表示在反向传播的时候我们不需要计算gradient
x = torch.randn(N, D_in, device=device, dtype=dtype)
y = torch.randn(N, D_out, device=device, dtype=dtype)

# 创建随机的Tensor和权重。
# 设置requires_grad=True表示我们希望反向传播的时候计算Tensor的gradient
w1 = torch.randn(D_in, H, device=device, dtype=dtype, requires_grad=True)
w2 = torch.randn(H, D_out, device=device, dtype=dtype, requires_grad=True)

learning_rate = 1e-6
for t in range(500):
    # 前向传播:通过Tensor预测y;这个和普通的神经网络的前向传播没有任何不同,
    # 但是我们不需要保存网络的中间运算结果,因为我们不需要手动计算反向传播。
    y_pred = x.mm(w1).clamp(min=0).mm(w2)

    # 通过前向传播计算loss
    # loss是一个形状为(1,)的Tensor
    # loss.item()可以给我们返回一个loss的scalar
    loss = (y_pred - y).pow(2).sum()#(类似计算图)
    print(t, loss.item())

    # PyTorch给我们提供了autograd的方法做反向传播。如果一个Tensor的requires_grad=True,
    # backward会自动计算loss相对于每个Tensor的gradient。在backward之后,
    # w1.grad和w2.grad会包含两个loss相对于两个Tensor的gradient信息。
    loss.backward()

    # 我们可以手动做gradient descent(后面我们会介绍自动的方法)。
    # 用torch.no_grad()包含以下statements,因为w1和w2都是requires_grad=True,
    # 但是在更新weights之后我们并不需要再做autograd。
    # 另一种方法是在weight.data和weight.grad.data上做操作,这样就不会对grad产生影响。
    # tensor.data会我们一个tensor,这个tensor和原来的tensor指向相同的内存空间,
    # 但是不会记录计算图的历史。

	#加了with就不会保存上一次的w1和w2了
    with torch.no_grad():
        w1 -= learning_rate * w1.grad
        w2 -= learning_rate * w2.grad

        # Manually zero the gradients after updating weights
        #下面必须加上,把它置0,才不会梯度一直涨(w1和w2会变得非常大。。。)
        w1.grad.zero_()
        w2.grad.zero_()

PyTorch: nn
这次我们使用PyTorch中nn这个库来构建网络。 用PyTorch autograd来构建计算图和计算gradients, 然后PyTorch会帮我们自动计算gradient。

import torch

# N is batch size; D_in is input dimension;
# H is hidden dimension; D_out is output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10

# Create random Tensors to hold inputs and outputs
x = torch.randn(N, D_in)
y = torch.randn(N, D_out)

# Use the nn package to define our model as a sequence of layers. nn.Sequential
# is a Module which contains other Modules, and applies them in sequence to
# produce its output. Each Linear Module computes output from input using a
# linear function, and holds internal Tensors for its weight and bias.
**#就是顶一个一个有序的容器,神经网络模块将按照在传入构造器的顺序依次被添加到计算图中执行,同时以神经网络模块为元素的有序字典也可以作为传入参数,就是来定义w1,w2,激活函数等.。。**
model = torch.nn.Sequential(
    torch.nn.Linear(D_in, H),
    torch.nn.ReLU(),
    torch.nn.Linear(H, D_out),
)

# The nn package also contains definitions of popular loss functions; in this
# case we will use Mean Squared Error (MSE) as our loss function.
**#nn.MSELoss就是个均方差损失函数,顶替了pow(2).sum()**
loss_fn = torch.nn.MSELoss(reduction='sum')

learning_rate = 1e-4
for t in range(500):
    # Forward pass: compute predicted y by passing x to the model. Module objects
    # override the __call__ operator so you can call them like functions. When
    # doing so you pass a Tensor of input data to the Module and it produces
    # a Tensor of output data.
    y_pred = model(x)

    # Compute and print loss. We pass Tensors containing the predicted and true
    # values of y, and the loss function returns a Tensor containing the
    # loss.
    loss = loss_fn(y_pred, y)
    print(t, loss.item())

    # Zero the gradients before running the backward pass.
    #类似上面的把上次的清空,一定得加,一定放在求导(反向传播)前面
    model.zero_grad()

    # Backward pass: compute gradient of the loss with respect to all the learnable
    # parameters of the model. Internally, the parameters of each Module are stored
    # in Tensors with requires_grad=True, so this call will compute gradients for
    # all learnable parameters in the model.
    loss.backward()

    # Update the weights using gradient descent. Each parameter is a Tensor, so
    # we can access its gradients like we did before.
    with torch.no_grad():
    	#param是个(tensor,grad)
    	#model.parameters()是放这很多参数,eg:w1,w2...
        for param in model.parameters():
            param -= learning_rate * param.grad

PyTorch: optim,比nn又简化点了,越往下代码越简洁(封装度越高了。。。)
这一次我们不再手动更新模型的weights,而是使用optim这个包来帮助我们更新参数。 optim这个package提供了各种不同的模型优化方法,包括SGD(随机梯度下降法)+momentum, RMSProp, Adam等等.各种优化器比较:优化器比较

optimizer都实现了step()方法,这个方法会更新所有的参数。它能按两种方式来使用:
这是大多数optimizer所支持的简化版本。一旦梯度被如backward()之类的函数计算好后,我们就可以调用它。

import torch

# N is batch size; D_in is input dimension;
# H is hidden dimension; D_out is output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10

# Create random Tensors to hold inputs and outputs
x = torch.randn(N, D_in)
y = torch.randn(N, D_out)

# Use the nn package to define our model and loss function.
#定义模型,就类似定义w1,w2的东西啦
model = torch.nn.Sequential(
    torch.nn.Linear(D_in, H),
    torch.nn.ReLU(),
    torch.nn.Linear(H, D_out),
)
#若把学习率改为1e-6的话,加下下面两句初始化变量,就会收敛快很多
#torch.nn.init.normal_(model[0].weight)
#torch.nn.init.normal_(model[2].weight)


#输出model:
#Sequential(
  #(0): Linear(in_features=1000, out_features=100, bias=True)
  #(1): ReLU()
  #(2): Linear(in_features=100, out_features=10, bias=True)
#)


loss_fn = torch.nn.MSELoss(reduction='sum')

# Use the optim package to define an Optimizer that will update the weights of
# the model for us. Here we will use Adam; the optim package contains many other
# optimization algoriths. The first argument to the Adam constructor tells the
# optimizer which Tensors it should update.
learning_rate = 1e-4
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)#优化器更新所有参数
for t in range(500):
    # Forward pass: compute predicted y by passing x to the model.
    y_pred = model(x)

    # Compute and print loss.
    loss = loss_fn(y_pred, y)
    print(t, loss.item())

    # Before the backward pass, use the optimizer object to zero all of the
    # gradients for the variables it will update (which are the learnable
    # weights of the model). This is because by default, gradients are
    # accumulated in buffers( i.e, not overwritten) whenever .backward()
    # is called. Checkout docs of torch.autograd.backward for more details.
    #再求导前清空,一定放在求导前面
    optimizer.zero_grad()

    # Backward pass: compute gradient of the loss with respect to model
    # parameters
    #反向传播就是求导
    loss.backward()

    # Calling the step function on an Optimizer makes an update to its
    # parameters
    #求导之后做一步更新参数
    optimizer.step()

`PyTorch: 自定义 nn Modules
我们可以定义一个模型,这个模型继承自nn.Module类。如果需要定义一个比Sequential模型更加复杂的模型,就需要定义nn.Module模型。

import torch


class TwoLayerNet(torch.nn.Module):
    def __init__(self, D_in, H, D_out):
        """
        In the constructor we instantiate two nn.Linear modules and assign them as
        member variables.
        """
        super(TwoLayerNet, self).__init__()
        self.linear1 = torch.nn.Linear(D_in, H)
        self.linear2 = torch.nn.Linear(H, D_out)

    def forward(self, x):
        """
        In the forward function we accept a Tensor of input data and we must return
        a Tensor of output data. We can use Modules defined in the constructor as
        well as arbitrary operators on Tensors.
        """
        h_relu = self.linear1(x).clamp(min=0)
        y_pred = self.linear2(h_relu)
        return y_pred


# N is batch size; D_in is input dimension;
# H is hidden dimension; D_out is output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10

# Create random Tensors to hold inputs and outputs
x = torch.randn(N, D_in)
y = torch.randn(N, D_out)

# Construct our model by instantiating the class defined above
model = TwoLayerNet(D_in, H, D_out)

# Construct our loss function and an Optimizer. The call to model.parameters()
# in the SGD constructor will contain the learnable parameters of the two
# nn.Linear modules which are members of the model.
criterion = torch.nn.MSELoss(reduction='sum')
optimizer = torch.optim.SGD(model.parameters(), lr=1e-4)
for t in range(500):
    # Forward pass: Compute predicted y by passing x to the model
    y_pred = model(x) #这就是调用forward()

    # Compute and print loss
    loss = criterion(y_pred, y)
    print(t, loss.item())

    # Zero gradients, perform a backward pass, and update the weights.
    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
掌控板玩板指南1:初识掌控板、扩展板、Mind+编辑器 掌控板、I/O扩展板入门 阅读详情

相关推荐

计算光刻效率革命:为什么Hopkins模型比Abbe模型快?深入解析TCC的魔力

本文深入解析了计算光刻中Hopkins模型相比Abbe模型的效率优势,重点探讨了TCC(透射交叉系数)的工程智慧。通过预计算光学系统特性并复用TCC矩阵,Hopkins模型实现了数量级的加速,特别适用于复杂照明条件下的光刻仿真。文章详细介绍了TCC的物理意义、模态分解技术以及GPU并行计算等关键加速策略,为半导体制造中的光刻工艺优化提供了实用见解。

weixin_33364627的博客 387

【pytorch进阶】| tensor张量的T和H 分别是什么?转置和共轭转置

在调试过程中,可以看到tensor张量有T和H的属性。

专注于人工智能的算法与应用 3941

【Codesys】获取从站信息,判断是否从站断联,总线丢失

获取EtherCAT从站信息,判断是否从站断联,总线丢失

qq_35316470的博客 5729

熟练掌握Tensor的基本操作

来源:AI有温度本文介绍了张量的创建、维度、索引、视图等常用操作与基本概念,帮助大家熟练掌握Tensor的使用技巧!一、张量的创建与类型张量最基本创建方法和Numpy中创建Array的格式...

Python数据之道 5061

电磁场可视化

电磁场可视化 如题,做了电磁场可视化这么久了,也是颇有些心得了,简单描述一下怎么做这个项目的。 开始时是从最基本的OpenGL开始做的,必不可少的翻了许多的文献,后来是直接在unity中做,发现效果挺好,而且可控性强好多。反复琢磨后,发现可视化的渲染,有几种思路,第一就是用linerender,画线的方法,另一种就是用shader。 第一种我通过unity自带的linewave插件可以做到 详细的就是,linewave插件可以轻松画出曲线等,并且可以添加碰撞,控制频率幅度长度等一切的条件数值,而且令人惊喜

weixin_43979140的博客 1670

【深度学习-番外1】Win10系统搭建VSCode+Anaconda+Pytorch+CUDA深度学习环境和框架全过程

本文将介绍在Windows 10系统下搭建深度学习环境的完整过程,包括安装Anaconda、CUDA、NVIDIA显卡驱动以及Pytorch框架。后续本专栏的Python语言下的深度学习环境都以本篇搭建的为准。

fengzhuqiaoqiu的博客 3996

Pytorch中关于Tensor的操作

10.Tensor的变换。1.Tensor的创建。9.Tensor的查询。2.矩阵的叉乘和点乘。

2301_78848414的博客 681

STM32鱼塘水质监测系统设计与实现

物联网技术在农业领域的应用正逐步深入,其中传感器网络作为关键基础设施,通过实时数据采集与传输实现环境监测。基于STM32微控制器的嵌入式系统因其高性能和低功耗特性,成为物联网终端设备的理想选择。该系统通过DS18B20水温传感器、PH传感器和浊度传感器组成的多参数检测网络,配合4G通信模块实现水质数据的远程监控。在农业物联网场景中,这种解决方案不仅大幅降低了传统人工检测的成本,更能通过实时预警有效预防养殖损失。本文介绍的鱼塘水质监测系统正是这一技术的典型应用,展示了如何通过STM32和常见传感器构建高性价比

weixin_42173218的博客 620

python pytorch 张量 (Tensor)

python 张量详解

我是Python虫!!! 1993

SAP会计凭证导入ABAP开发模板+注意点—附带源码

开发并不仅仅只要考虑实现的功能,只实现功能的是程序,考虑到使用场景的是工程。使用bapi校验创建会计凭证的数据,报错和参数和正式创建一致。用途,防止产生错误的凭证,即使财务凭证可以冲销。正式创建会计凭证。隐藏的坑。

小九啥也不会 1232

Ubuntu 22.04+/WSL2 中解决 `error: externally-managed-environment` 并成功安装 PyTorch + vLLM 的完整指南

Ubuntu 22.04+/WSL2 因遵循 PEP 668 规范,系统 Python 被标记为“外部管理”,导致直接使用 pip install 安装包时报错 externally-managed-environment。解决方案是创建虚拟环境: 通过 python3 -m venv ~/vllm-env 创建隔离环境 激活环境后安装 PyTorch(CUDA 12.1)和 vLLM 避免使用 sudo pip 或 --break-system-packages,防止破坏系统依赖 关键点: 虚拟环

刘一说的IT专栏 296

深度学习中的Tensor 数据格式(N,C,H,W)

文章目录深度学习中的Tensor 数据格式(N,C,H,W)一、深度学习框架中的图像格式2、数据格式3、物理存储3.1、NCHW3.2、NHWC3.3、CHWN:StridesBlocked layout4、RGB图像数据举例5、不同框架的支持 深度学习中的Tensor 数据格式(N,C,H,W) 参考: 数据格式- 图解NCHW与NHWC数据格式 NCHW-NHWC-NC/32HW32 一、深度学习框架中的图像格式 4DTensor格式:使用4D张量描述符来定义具有4个字母的2D图像批处理的格式 数

d_b_的博客 2万+

华为OD机试 - 小扇和小船的数字游戏 - 二进制(Python/JS/C/C++ 2024 C卷 200分)

二进制表示:任何数 n 的二进制表示中,要找到下一个有相同数量的1的数,我们需要在最低位的0后面的最低位的1进行操作。右侧交换法则:找到右侧的第一个0,位于第一个1的左边,将这个0变成1(提升这个位),并将这个1变成0(下移这个位)。调整尾部1:为了得到最小的数,将所有低于已交换的1的位重置,使得所有1尽可能靠右。

学Java,找哪吒 1160

Pytorch基础知识1

张量和数组的区别,Tensor可以在GPU上运行,张量和数组可使用同一片内存空间Tensor支持自动微分(Pytorch中)Pytorch中导入是a=[1,2,3]type(b) ##显示的是b的类型b.dtype ##显示的是b中数据的类型也可以用numpy数组创建tensorc=torch.ones_like(b) ##创建成相同形状和数据类型的张量​也可以用另一个张两种a.dtypea.shapea.device张量是在cpu还是GPU上面创建的​。

qq_74831294的博客 918

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

【PyTorch入门教程】1. 基础知识

这是一个面向初学者的PyTorch教程。 PyTorch项目的基本流程,与每个步骤相关的重要模块 张量是PyTorch中使用的核心数据结构。

youcans的博客 2176

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

【Pytorch学习笔记1】Pytorch的安装与基础知识

个人笔记,用于DataWhale组织的pytorch开源学习

edifier_wy的博客 925

PyTorch学习(1):基础知识

PyTorch学习(1):基础知识 Pytorch官方文档: https://pytorch-cn.readthedocs.io/zh/latest/ Pytorch学习文档: https://github.com/tensor-yu/PyTorch_Tutorial 参考: https://blog.csdn.net/u011995719/article/details/85102770    https://blog.csdn.net/weicao1990/article/details/93177

小花生的博客 704

pytorch学习1-基础知识

pytorch基础1.张量(1)创建一个没有初始化的5*3矩阵(2)创建一个随机初始化矩阵(3)构造一个填满0且数据类型为long的矩阵(4)直接从数据构造张量(5)根据已有的tensor建立新的tensor。除非用户提供新的值,否则这些方法将重用输入张量的属性。2.运算(1)加法:形式一(2)加法:形式二(3)加法:形式三,给定一个输出张量作为参数(4)加法:原位/原地操作(in-place)(5)也可以使用像标准的NumPy一样的各种索引操作(6)改变形状:如果想改变形状,可以使用torch.view(

u014168855的博客 636

1、PyTorch Basics(PyTorch 一些基础知识)

1、2、关于梯度、求导...一个简单的神经网络过程 3、numpy与torch的转换 4、构建输入数据流(利用已有的CIFAR10数据集) 5、构建输入数据流(自己定制数据流) 6、怎么使用一个预训练模型,然后fine-tune 7、保存和加载模型 1、2、关于梯度、求导...一个简单的神经网络过程 前向传播得到预测值-->求预测值与真实值的损失--> 优化器梯度清零-->反向传播求所有参数的梯度 -->优化器更新梯度 # =======...

Drug discovery 530

pytorch学习历程1, pytorch基础知识要点autograd,detach等

本教程整理自书籍《深度学习框架PyTorch:入门与实践》 torch.Size 是python tuple的子类,.size() 查看tensor的大小 x.add_(y)会改变x本身,x.add(y)不会改变x本身 tensor 和 numpy的转换 numpy = tensor.numpy() tensor = torch.from_numpy(numpy_obj) ...

墨流觞的博客 920

Pytorch系列 1.张量基础知识

pytorch基础知识(菜鸟写的,仅供参考)

qq_43888865的博客 908

【Pytorch深度学习实战】(1)Pytorch基础知识

1. 基本 autograd 示例。2. 从 numpy 加载数据。4. 自定义数据集的输入管道。6. 保存并加载模型。

sikh_0529的博客 1万+

PyTorch基础知识1.0

PyTorch基础知识1.0 1.Tensor的基本概念和操作 import torch import numpy as np # 1. 标量 a = torch.tensor(4.0) print('标量: ', a) 标量: tensor(4.) # 2. 向量 b = torch.tensor([1, 5, 2]) print('向量: ', b) 向量: tensor([1, 5, 2]) # 3. 矩阵(张量) c = torch.tensor([[1, 2, 5],

QT-Smile 1514

pytorch基础知识之Tensor(1)

pytorch中关于Tensor的一些基础操作 以下是创建一些张量代码实例 import torch #传数据(FlotTensor类型) a = torch.Tensor( [ [1,2],[3,4] ] ) #基础构造函数 a = torch.Tensor(2,3) #几种特殊 b = torch.zeros(3,5) b = torch.ones(2,2) b = torch.eye(3,3) c = torch.zeros_like(a)

go___on的博客 1745

第二章:PyTorch基础知识1

链接 PyTorch相关资源 PyTorch之所以被越来越多的人使用,不仅在于其完备的教程,还受益于许多相关的资源,在这里,我们列举了相关的优质资源希望能帮助到各位同学。 Awesome-pytorch-list:目前已获12K Star,包含了NLP,CV,常见库,论文实现以及Pytorch的其他项目。 PyTorch官方文档:官方发布的文档,十分丰富。 Pytorch-handbook:GitHub上已经收获14.8K,pytorch手中书。 PyTorch官方社区:在这里你可以和开发pytorch的人

qq_36744449的博客 208

【材料整理】 --Pytorch基础知识1

文章目录 文章目录写在前面Pytorch加载数据初认识TensorboardTransformdataloader的使用 写在前面 本系列内容主要是对小土堆的《操作系统》课程的笔记整理。 b站地址:https://www.bilibili.com/video/BV1hE411t7RN?spm_id_from=333.337.search-card.all.click Pytorch加载数据初认识 1、pytorch加载数据主要涉及两个类,dataset、dataloder 假如有一堆数据 Dataset .

银尘博客 2215

Pytorch基础知识(1)操作PyTorch的Tensor

Pytorch基础知识(1)操作PyTorch的Tensor定义Tensor数据类型改变tensor的数据类型把tensor转换为numpy数组把numpy数组转换为tensor在设备之间移动tensor 定义Tensor数据类型 Tensor默认的数据类型是torch.float32。让我们来看一个例子: 定义一个默认数据类型的tensor 下面展示一些 内联代码片。 x = torch.ones(2, 2) print(x) print(x.dtype()) tensor([[1., 1.],

weixin_43229348的博客 427
上一篇: 计算机组成原理笔记(bytes\bit)
下一篇: Pytorch笔记---2.CNN
Mike-H
博客等级 码龄8年 27粉丝 141原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值