新手小白的pytorch学习第十一弹-----Computer Vision创建基础模型使用FashionMNIST

news2024/9/23 1:21:01

目录

  • PyTorch Computer Vision
    • 0 PyTorch 中 Computer vision 的库
    • 1 获得一个数据集
      • 1.1 查看数据的输入和输出形状
      • 1.2 可视化数据
    • 2 准备 DataLoader
    • 3 Model 0: 创建一个 baseline model
      • 3.1 设置损失函数、优化器和评估指标
      • 3.2 创建一个函数来给我们的实验计时
      • 3.3 在批量数据集上创建训练和测试循环
    • 4 预测获得model 0 的结果

PyTorch Computer Vision

0 PyTorch 中 Computer vision 的库

  • torchvision:PyTorch Computer Vision基本库
  • torchvision.datasets:获取数据和数据加载函数
  • torchvision.models:获得预训练模型,可以利用它来解决自己的问题
  • torchvision.transforms:操作视觉数据(图片)使得它能够很好的适用于机器学习模型
  • torch.utils.data.Datasets:PyTorch的基本数据集类
  • torch.utils.data.DataLoader:从数据集上创建一个python可迭代的对象
# 导入 PyTorch 包
import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import DataLoader

# 导入 torchvision 包
import torchvision
from torchvision import datasets
from torchvision import transforms
from torchvision.transforms import ToTensor

# 导入可视化包
import matplotlib.pyplot as plt

# 查看包的版本
print(torch.__version__)
print(torchvision.__version__)

2.3.1+cu118
0.18.1+cpu

1 获得一个数据集

我们这里使用的数据集是 FashionMNIST

# 创建训练数据
train_data = datasets.FashionMNIST(root='data', # 存放数据的路径
                                   train=True, # 我们需要的是训练数据集
                                   download=True, # 是否需要下载数据
                                   transform=transforms.ToTensor(), # 我们需要如何转换数据
                                   target_transform=None #我们需要如何转换标签
                                   )

# 创建测试数据
test_data = datasets.FashionMNIST(root='data',
                                  train=False,
                                  download=True,
                                  transform=transforms.ToTensor(),
                                  target_transform=None
                                  )
len(train_data), len(test_data)

(60000, 10000)

# 查看一下数据
train_data[0]

(tensor([[[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000],

0.0000, 0.0000, 0.0000, 0.0000]]]),
9)
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings…

可以看出这里的数据分为两部分,前面是图片数据被转换成了 tensor, 后面的 9 就是标签

image, label = train_data[0]
image, label

(tensor([[[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000],

[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,
0.0000, 0.0000, 0.0000, 0.0000]]]),
9)
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings…

class_names = train_data.classes
class_names

[‘T-shirt/top’,
‘Trouser’,
‘Pullover’,
‘Dress’,
‘Coat’,
‘Sandal’,
‘Shirt’,
‘Sneaker’,
‘Bag’,
‘Ankle boot’]

class_to_idx = train_data.class_to_idx
class_to_idx

{‘T-shirt/top’: 0,
‘Trouser’: 1,
‘Pullover’: 2,
‘Dress’: 3,
‘Coat’: 4,
‘Sandal’: 5,
‘Shirt’: 6,
‘Sneaker’: 7,
‘Bag’: 8,
‘Ankle boot’: 9}

train_data.targets

tensor([9, 0, 0, …, 3, 0, 5])

1.1 查看数据的输入和输出形状

# 查看图片的形状
print(f"Image shape:{image.shape}")
print(f"Image label:{class_names[label]}")

Image shape:torch.Size([1, 28, 28])
Image label:Ankle boot

1.2 可视化数据

print(f"Image shape:{image.shape}")
plt.imshow(image.squeeze())
plt.title(label)

Image shape:torch.Size([1, 28, 28])
Text(0.5, 1.0, ‘9’)
在这里插入图片描述

plt.imshow(image.squeeze(), cmap="gray")
plt.title(class_names[label]);
plt.axis(False);

在这里插入图片描述

# 绘制更多的图像
# torch.manual_seed(42)
fig = plt.figure(figsize=(9,9))
rows, cols = 4, 4
for i in range(1, rows*cols + 1):
    random_idx = torch.randint(0, len(train_data), size=[1]).item()
    image, label = train_data[random_idx]
    fig.add_subplot(rows, cols, i)
    plt.imshow(image.squeeze(), cmap="gray")
    plt.title(class_names[label])
    plt.axis(False);

在这里插入图片描述
思考一下,为这些衣服的图片创建模型,模型中只包含纯粹的线性方法吗?还是我们需要非线性的方法?

train_data, test_data

(Dataset FashionMNIST
Number of datapoints: 60000
Root location: data
Split: Train
StandardTransform
Transform: ToTensor(),
Dataset FashionMNIST
Number of datapoints: 10000
Root location: data
Split: Test
StandardTransform
Transform: ToTensor())

2 准备 DataLoader

DataLoader 可以将我们的数据集转换为 python 的可迭代对象,更具体地说,就是将我们庞大的数据转换为小一点的数据,batches(mini-batches)
For more on mini-batches, see here: https://youtu.be/l4lSUAcvHFs

# 设置 batch 的超参数
BATCH_SIZE = 32

# 将数据集转换为可迭代对象 batch
train_dataloader = DataLoader(dataset=train_data,
                              shuffle=True, # 将顺序打断,以免模型学习的是顺序
                              batch_size=BATCH_SIZE)
test_dataloader = DataLoader(dataset=test_data,
                             shuffle=False, # 测试数据集模型没有见过,顺序的影响不大
                             batch_size=BATCH_SIZE)

train_dataloader, test_dataloader

(<torch.utils.data.dataloader.DataLoader at 0x1e9adcf8670>,
<torch.utils.data.dataloader.DataLoader at 0x1e9add46cd0>)

# 查看我们创建的数据
print(f"DataLoaders:{train_dataloader, test_dataloader}")
print(f"Length of train_dataloader:{len(train_dataloader)} batches of {BATCH_SIZE}...")
print(f"Length of test_dataloader:{len(test_dataloader)} batches of {BATCH_SIZE}...")

DataLoaders:(<torch.utils.data.dataloader.DataLoader object at 0x000001E9ADCF8670>, <torch.utils.data.dataloader.DataLoader object at 0x000001E9ADD46CD0>)
Length of train_dataloader:1875 batches of 32…
Length of test_dataloader:313 batches of 32…

# 查看 train_dataloader 具体数据
train_features_batch, train_labels_batch = next(iter(train_dataloader))
train_features_batch.shape, train_labels_batch.shape

(torch.Size([32, 1, 28, 28]), torch.Size([32]))

# 可视化一个样例
torch.manual_seed(42)
random_idx = torch.randint(0, len(train_features_batch), size=[1]).item()
image, label = train_features_batch[random_idx], train_labels_batch[random_idx]
plt.imshow(image.squeeze(), cmap="gray")
plt.title(class_names[label])
plt.axis(False)
print(f"Image size:{image.shape}")
print(f"Label:{label}, label size:{label.shape}")

Image size:torch.Size([1, 28, 28])
Label:4, label size:torch.Size([])

在这里插入图片描述

3 Model 0: 创建一个 baseline model

当我们开始创建一系列机器学习实验的时候,最好的方式是从一个基准模型开始。
一个基准模型就是一个简单的基本模型,其他的改进就是从这个模型开始的。
换句话说,从一个简单模型开始,添加复杂性和难度,慢慢增加

# 创建 flatten 层,展平,就是将数据展平展开
flatten_model = nn.Flatten()

# 获取一个单一的样本
x = train_features_batch[0]

# Flatten 样本
output = flatten_model(x)

print(f"Shape before flattening:{x.shape}")
print(f"Shape after flattening:{output.shape}")

Shape before flattening:torch.Size([1, 28, 28])
Shape after flattening:torch.Size([1, 784])

可以看出这个结果就是 28*28

class FashionMNISTModelV0(nn.Module):
    def __init__(self,
                 input_shape:int,
                 hidden_units:int,
                 output_shape:int
                 ):
        super().__init__()
        self.layer_stack = nn.Sequential(
            nn.Flatten(),
            nn.Linear(in_features=input_shape, 
                      out_features=hidden_units),
            nn.Linear(in_features=hidden_units, 
                      out_features=output_shape)
        )
    def forward(self, x):
        return self.layer_stack(x)
torch.manual_seed(42)

model_0 = FashionMNISTModelV0(
    input_shape=28*28,
    hidden_units=10,
    output_shape=len(class_names)
).to("cpu")

model_0

FashionMNISTModelV0(
(layer_stack): Sequential(
(0): Flatten(start_dim=1, end_dim=-1)
(1): Linear(in_features=784, out_features=10, bias=True)
(2): Linear(in_features=10, out_features=10, bias=True)
)
)

dummy_x = torch.rand([1, 1, 28, 28]) # batch_size, color_channel, width, height
model_0(dummy_x)

tensor([[-0.0315, 0.3171, 0.0531, -0.2525, 0.5959, 0.2112, 0.3233, 0.2694,
-0.1004, 0.0157]], grad_fn=)

model_0.state_dict()

OrderedDict([(‘layer_stack.1.weight’,
tensor([[ 0.0273, 0.0296, -0.0084, …, -0.0142, 0.0093, 0.0135],
[-0.0188, -0.0354, 0.0187, …, -0.0106, -0.0001, 0.0115],
[-0.0008, 0.0017, 0.0045, …, -0.0127, -0.0188, 0.0059],
…,
[-0.0116, 0.0273, -0.0344, …, 0.0176, 0.0283, -0.0011],
[-0.0230, 0.0257, 0.0291, …, -0.0187, -0.0087, 0.0001],
[ 0.0176, -0.0147, 0.0053, …, -0.0336, -0.0221, 0.0205]])),
(‘layer_stack.1.bias’,
tensor([-0.0093, 0.0283, -0.0033, 0.0255, 0.0017, 0.0037, -0.0302, -0.0123,
0.0018, 0.0163])),
(‘layer_stack.2.weight’,
tensor([[ 0.0614, -0.0687, 0.0021, 0.2718, 0.2109, 0.1079, -0.2279, -0.1063,
0.2019, 0.2847],
[-0.1495, 0.1344, -0.0740, 0.2006, -0.0475, -0.2514, -0.3130, -0.0118,
0.0932, -0.1864],
[ 0.2488, 0.1500, 0.1907, 0.1457, -0.3050, -0.0580, 0.1643, 0.1565,
-0.2877, -0.1792],
[ 0.2305, -0.2618, 0.2397, -0.0610, 0.0232, 0.1542, 0.0851, -0.2027,
0.1030, -0.2715],
[-0.1596, -0.0555, -0.0633, 0.2302, -0.1726, 0.2654, 0.1473, 0.1029,
0.2252, -0.2160],
[-0.2725, 0.0118, 0.1559, 0.1596, 0.0132, 0.3024, 0.1124, 0.1366,
-0.1533, 0.0965],
[-0.1184, -0.2555, -0.2057, -0.1909, -0.0477, -0.1324, 0.2905, 0.1307,

[-0.1310, 0.0645, -0.1171, 0.2168, -0.0245, -0.2820, 0.0736, 0.2621,
0.0012, -0.0810]])),
(‘layer_stack.2.bias’,
tensor([-0.0087, 0.1791, 0.2712, -0.0791, 0.1685, 0.1762, 0.2825, 0.2266,
-0.2612, -0.2613]))])
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings…

3.1 设置损失函数、优化器和评估指标

多分类问题: CrossEntropyLoss()
优化器: SGD()
评估指标:accuracy

import requests
from pathlib import Path

# 下载 helper functions from PyTorch repo
if Path("helper_functions.py").is_file():
    print("helper_functions.py is already exists, skipping download...")
else:
    print("Downloading helper_functions.py")
    request = requests.get("https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/helper_functions.py")
    with open("helper_functions.py", "wb") as f:
        f.write(request.content)

helper_functions.py is already exists, skipping download…

from helper_functions import accuracy_fn

loss_fn = nn.CrossEntropyLoss()
optimizer = optim.SGD(params=model_0.parameters(),
                      lr=0.1)

3.2 创建一个函数来给我们的实验计时

要跟踪的东西是:

  1. 模型的性能(loss和accuracy值)
  2. 它运行的速度
from timeit import default_timer as timer
def print_train_time(start:float,
                     end:float,
                     device:torch.device=None):
    """Prints difference between start and end time."""
    total_time = end - start
    print(f"Train time on {device}:{total_time:.3f} seconds")
    return total_time
start_time = timer()
# 一些代码
end_time = timer()
print_train_time(start=start_time,
                 end=end_time,
                 device="cpu")

Train time on cpu:0.000 seconds
1.3100000018084756e-05

3.3 在批量数据集上创建训练和测试循环

Note:由于我们在batches上进行计算,所以optimizer会一次性更新每一个batch而不是每一个epoch

# 进度条柱子,引入tqdm
from tqdm.auto import tqdm

如果报错的话可能是没有安装这个包,执行下面这个操作即可

pip install tqdm

Requirement already satisfied: tqdm in d:\anaconda3\envs\limu\lib\site-packages (4.66.4)
Requirement already satisfied: colorama in d:\anaconda3\envs\limu\lib\site-packages (from tqdm) (0.4.6)
Note: you may need to restart the kernel to use updated packages.

我这是已经安装过的提示。

torch.manual_seed(42)
train_time_start_on_cpu = timer()

# 设置训练周期(这里采用少量训练周期,可以花费更少的时间看看我们的模型性能如何)
epochs=3

# 这里加了tqdm,等会就知道它的作用啦
for epoch in tqdm(range(epochs)):
    print(f"Epoch:{epoch}\n-------")
    # Training
    train_loss = 0
    # 在每一个训练batch中加入循环进行遍历
    for batch, (X,y) in enumerate(train_dataloader):
        model_0.train()
        y_pred = model_0(X)
        
        loss = loss_fn(y_pred, y)
        train_loss += loss # 这是所有batch的loss,会进行累加
        
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
        
        if batch % 400 == 0:
            print(f"Look at {batch * len(X)}/{len(train_dataloader)} samples.")
            
    train_loss /= len(train_dataloader)
    
    # Testing
    test_loss, test_acc = 0, 0
    model_0.eval()
    with torch.inference_mode():
        for X_test, y_test in test_dataloader:
            test_pred = model_0(X_test)
            test_loss += loss_fn(test_pred, y_test)
            test_acc += accuracy_fn(y_true=y_test,
                                    y_pred=test_pred.argmax(dim=1))
        test_loss /= len(test_dataloader)
        test_acc /= len(test_dataloader)
        
    print(f"\nTrain loss:{train_loss:.4f} | Test loss:{test_loss:.4f} | Tess acc:{test_acc:.2f}%")
    
# 计算训练时间
train_time_end_on_cpu = timer()
total_train_time_on_model_0 = print_train_time(start=train_time_start_on_cpu,
                                               end=train_time_end_on_cpu,
                                               device=str(next(model_0.parameters()).device))

在这里插入图片描述

Epoch:0
Look at 0/1875 samples.
Look at 12800/1875 samples.
Look at 25600/1875 samples.
Look at 38400/1875 samples.
Look at 51200/1875 samples.

Train loss:0.5904 | Test loss:0.5095 | Tess acc:82.04%

Epoch:1
Look at 0/1875 samples.
Look at 12800/1875 samples.
Look at 25600/1875 samples.
Look at 38400/1875 samples.
Look at 51200/1875 samples.

Train loss:0.4763 | Test loss:0.4799 | Tess acc:83.20%

Epoch:2

Look at 0/1875 samples.
Look at 12800/1875 samples.
Look at 25600/1875 samples.
Look at 38400/1875 samples.
Look at 51200/1875 samples.

Train loss:0.4550 | Test loss:0.4766 | Tess acc:83.43%
Train time on cpu:24.777 seconds

4 预测获得model 0 的结果

torch.manual_seed(42)
device="cpu"
def eval_model(model:torch.nn.Module,
               data_loader: torch.utils.data.DataLoader,
               loss_fn:torch.nn.Module,
               accuracy_fn,
               device=device):
    """Return a dictionary containing the results of model predictioning on data_loader."""
    loss, acc = 0, 0
    model.eval()
    with torch.inference_mode():
        for X, y in tqdm(data_loader):
            # 将数据与设备无关
            X, y = X.to(device), y.to(device)
            y_pred = model(X)
            loss += loss_fn(y_pred, y)
            acc += accuracy_fn(y_true=y,
                               y_pred=y_pred.argmax(dim=1))
        loss /= len(data_loader)
        acc /= len(data_loader)
        
    return {"model_name":model.__class__.__name__,
            "model_loss":loss.item(),
            "model_acc":acc}

# 计算model 0在测试数据集上的结果

model_0_results = eval_model(model=model_0,
                             data_loader=test_dataloader,
                             loss_fn=loss_fn,
                             accuracy_fn=accuracy_fn,
                             device=device)

model_0_results

在这里插入图片描述
这里就是很需要注意这个per batch的loss和acc的计算。
ok,BB,如果文档对您有用的话,记得给俺点一个赞赞

谢谢啦!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1946724.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

09-软件易用性

易用性是用户体验的一个重要方面&#xff0c;网站建设者一般会沉溺于自己的思维习惯&#xff0c;而造成用户使用的不畅。易用性不仅是专业UI/UE人员需要研究&#xff0c;对于网站建设其他岗位的人也应该了解一定的方法去检验和提升网站的易用性。通常对易用性有如下定义: 易理解…

书生浦语多模态简述——学习笔记

多模态学习概念 多模态它是研究异构且相互连接数据的科学。它涵盖了从原始的器官信号到抽象概念的多种模态。 比如说我们语音和语言是我们理解人类交流的关键模态&#xff0c;而情感和图像就为我们提供了对环境和对象的感知&#xff0c;通过分析这些模态&#xff0c;我们就可…

视频生成【文章汇总】SVD, Sora, Latte, VideoCrafter12, DiT...

视频生成【文章汇总】SVD, Sora, Latte, VideoCrafter12, DiT... 数据集指标 【arXiv 2024】MiraData: A Large-Scale Video Dataset with Long Durations and Structured Captions【CVPR 2024】VBench : Comprehensive Benchmark Suite for Video Generative Models【arxiv 20…

SpringBoot自动配置(面试重点)

自动配置是指&#xff1a; 自动配置是指在应用程序启动时&#xff0c;SpringBoot根据classpath路径下的jar包自动配置应用程序所需的一系列bean和组件&#xff0c;从而减少开发者的配置工作&#xff0c;提高开发效率。 一&#xff1a;Condition Condition是spring4.0之后添加…

HTML5 + CSS3

HTML 基础 准备开发环境 1.vscode 使用 新建文件夹 ---> 左键拖入 vscode 中 2.安装插件 扩展 → 搜索插件 → 安装打开网页插件&#xff1a;open in browser汉化菜单插件&#xff1a;Chinese 3.缩放代码字号 放大,缩小&#xff1a;Ctrl 加号&#xff0c;减号 4.设…

【BUG】已解决:You are using pip version 10.0.1, however version 21.3.1 is available.

You are using pip version 10.0.1, however version 21.3.1 is available. 目录 You are using pip version 10.0.1, however version 21.3.1 is available. 【常见模块错误】 【解决方案】 欢迎来到英杰社区https://bbs.csdn.net/topics/617804998 欢迎来到我的主页&#…

硅纪元视角 | 语音克隆突破:微软VALL-E 2,Deepfake新纪元!

在数字化浪潮的推动下&#xff0c;人工智能&#xff08;AI&#xff09;正成为塑造未来的关键力量。硅纪元视角栏目紧跟AI科技的最新发展&#xff0c;捕捉行业动态&#xff1b;提供深入的新闻解读&#xff0c;助您洞悉技术背后的逻辑&#xff1b;汇聚行业专家的见解&#xff0c;…

SSL/TLS和SSL VPN

1、SSL/TLS SSL安全套接字层&#xff1a;是一种加密协议&#xff0c;用于在网络通信中建立安全连接。它在应用层和传输层&#xff08;TCP/IP&#xff09;之间提供数据加密、服务器身份验证以及信息完整性验证 SSL只保护TCP流量&#xff0c;不保护UDP协议 TLS&#xff1a;传输层…

自定义webIpad证件相机(webRTC)

该技术方案可用于各浏览器自定义相机开发 相机UI&#xff08;index.html&#xff09; <!DOCTYPE html> <html lang"zh" prew"-1"><head><meta charset"UTF-8"><meta name"viewport"content"user-sc…

江苏 | 南京恒建视角下混凝土企业的根基和未来

第一视角带您走进本期标杆企业&#xff1a;南京恒建混凝土有限公司 “有根基才有未来。” ——走进南京恒建混凝土有限公司的办公楼&#xff0c;首先映入眼帘的就是这句话。所谓万丈高楼平地起&#xff0c;一砖一瓦皆根基。简单几个字&#xff0c;既能看到脚踏实地的坚守&…

机器学习笔记-01-初识基础(问题-解答自查版)

前言 以下问题以Q&A形式记录&#xff0c;基本上都是笔者在初学一轮后&#xff0c;掌握不牢或者频繁忘记的点 Q&A的形式有助于学习过程中时刻关注自己的输入与输出关系&#xff0c;也适合做查漏补缺和复盘。 本文对读者可以用作自查&#xff0c;答案在后面&#xff0…

DNS续集

1、DNS多域名解析 [rootdns ~]# vim /etc/named.rfc1912.zones 复制5行放在最后面 zone "z.a" IN { type master; file "z.a.zone"; allow-update { none; }; }; zone "4.168.192.in-addr.arpa" IN { type ma…

<数据集>玉米地杂草识别数据集<目标检测>

数据集格式&#xff1a;VOCYOLO格式 图片数量&#xff1a;9900张 标注数量(xml文件个数)&#xff1a;9900 标注数量(txt文件个数)&#xff1a;9900 标注类别数&#xff1a;2 标注类别名称&#xff1a;[Maize, Weed] 序号类别名称图片数框数1Maize8439125142Weed959231048…

rk3588s 定制版 USB adb , USB2.0与USB3.0 区别,adb 由typeC 转换到USB3.0(第二部分)

硬件资源&#xff1a; rk3588s 核心板定制的地板 软件资源&#xff1a; 网盘上的 android12 源码 1 硬件上 客户只想使用 type c 接口中的 usb2.0 OTG 。在硬件上&#xff0c;甚至连 CC芯片都没有连接。 关于一些前置的知识。 1 USB2.0 与 USB3.0 的区别。 usb3.0 兼容2.0 …

USUART代码例程和库函数

USUART代码例程和库函数 一、USUART中重要的寄存器二、USART中发送数据。三、接收数据四、USART发送数据示例代码&#xff08;print重定向&#xff09;五、USART接收数据示例代码六、USART常用的库函数usart_deinit&#xff08;&#xff09;&#xff1a;复位外设USARTusart_bau…

什么是大型语言模型 (LLM)

本章探讨下&#xff0c;人工智能如何彻底改变我们理解和与语言互动的方式 大型语言模型 (LLM) 代表了人工智能的突破&#xff0c;它采用具有广泛参数的神经网络技术进行高级语言处理。 本文探讨了 LLM 的演变、架构、应用和挑战&#xff0c;重点关注其在自然语言处理 (NLP) 领…

【ARM】MDK-STM32g0xx.h文件与Define规则记录

【更多软件使用问题请点击亿道电子官方网站】 1、 文档目标 记录问题STM32g0xx.h等有关ST的可读文件&#xff0c;尽量勿修改文件格式及对其代码进行添加和删减&#xff0c;记录查找问题的过程中的疑惑&#xff0c;并如何给予客户正确的回复&#xff0c;帮助销售完成验收&…

VBA实例-从Excel整理数据到Word

实现目录 功能需求数据结构复制数据到新sheet并分类数据添加序号、日期、时间三列数据添加序号列添加时间列 将名称和类别复制到word文件中将参数5和参数9中的一个复制到word文件中 实例 功能需求 1、将原始数据中不要的数据剔除 2、原始数据中增加序号、日期和时间三列数据&a…

富唯智能转运机器人:高效、智能、未来的选择

在现代工业中&#xff0c;高效的物流和物料处理是提升生产效率的关键。富唯智能转运机器人&#xff0c;以其卓越的技术和智能化的设计&#xff0c;为各行业提供了完美的解决方案。 产品概述 富唯智能转运机器人搭载ICD系列核心控制器&#xff0c;拥有多种移载平台&#xff0c…

【目标检测】Yolo5基本使用

前言 默认安装好所有配置&#xff0c;只是基于Yolo5项目文件开始介绍的。基于配置好的PyCharm进行讲解配置。写下的只是些基本内容&#xff0c;方便以后回忆用。避免配置好Yolo5的环境&#xff0c;拉取好Yolo5项目后&#xff0c;不知道该如何下手。如果有时间&#xff0c;我还是…