Paddle快速入门

PaddlePaddle快速入门

学会使用深度学习框架是解决深度学习任务的基本能力,这里我们推荐成熟易用的国产开源框架PaddlePaddle。以下内容将带你你快速入门PaddlePaddle,你可以尝试跑通一个小demo来熟悉PaddlePaddle的基本命令。

PaddlePaddle基础命令

PaddlePaddle是百度开源的深度学习框架,类似的深度学习框架还有谷歌的Tensorflow、Facebook的Pytorch等,在入门深度学习时,学会并使用一门常见的框架,可以让学习效率大大提升。在PaddlePaddle中,计算的对象是张量,我们可以先使用PaddlePaddle来计算一个[[1, 1], [1, 1]] * [[1, 1], [1, 1]]。

计算常量的加法:1+1

首先导入PaddlePaddle库

In [1]

arduino 复制代码
import paddle

paddle.__version__
arduino 复制代码
'2.1.0'

定义两个张量的常量x1和x2,并指定它们的形状是[2, 2],并赋值为1铺满整个张量,类型为int64.

In [2]

ini 复制代码
# 定义两个张量
x1 = paddle.ones([2,2], dtype='int64')
x2 = paddle.ones([2,2], dtype='int64')

接着定义一个操作,该计算是将上面两个张量进行加法计算,并返回一个求和的算子。PaddlePaddle提供了大量的操作,比如加减乘除、三角函数等。

In [3]

ini 复制代码
# 将两个张量求和
y1 = paddle.add(x1, x2)

# 查看结果
print(y1)
ini 复制代码
Tensor(shape=[2, 2], dtype=int64, place=CPUPlace, stop_gradient=True,
       [[2, 2],
        [2, 2]])

使用PaddlePaddle做线性回归

在上面的教学中,教大家学会用PaddlePaddle做基本的算子运算,下面来教大家如何用PaddlePaddle来做简单的线性回归,包括从定义网络到使用自定义的数据进行训练,最后验证我们网络的预测能力。

首先导入PaddlePaddle库和一些工具类库。

In [4]

javascript 复制代码
import paddle
import numpy as np

paddle.__version__
arduino 复制代码
'2.1.0'

我们使用numpy定义一组数据,这组数据的每一条数据有13个,为了做示例,其中除了第一个数外都填充了0。这组数据是符合y = 2 * x + 1,但是程序是不知道的,我们之后使用这组数据进行训练,看看强大的神经网络是否能够训练出一个拟合这个函数的模型。最后定义了一个预测数据,是在训练完成,使用这个数据作为x输入,看是否能够预测于正确值相近结果。

In [5]

lua 复制代码
# 定义训练和测试数据
x_data = np.array([[1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 
                   [2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 
                   [3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 
                   [4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 
                   [5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]).astype('float32')
y_data = np.array([[3.0], [5.0], [7.0], [9.0], [11.0]]).astype('float32')
test_data = np.array([[6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]).astype('float32')

定义一个简单的线性网络,这个网络非常简单,结构是:

css 复制代码
[输入层] --> [隐层] --> [激活函数] --> [输出层]

更具体的就是一个输出大小为100的全连接层、之后接激活函数ReLU和一个输出大小为1的全连接层,就这样构建了一个非常简单的网络。

这里定义输入层的形状为13,这是因为波士顿房价数据集的每条数据有13个属性,我们之后自定义的数据集也是为了符合这一个维度。

In [6]

ini 复制代码
# 定义一个简单的线性网络
net = paddle.nn.Sequential(
    paddle.nn.Linear(13, 100),
    paddle.nn.ReLU(),
    paddle.nn.Linear(100, 1)
)

接着是定义训练使用的优化方法,这里使用的是随机梯度下降优化方法。PaddlePaddle提供了大量的优化函数接口,除了本项目使用的随机梯度下降法(SGD),还有Momentum、Adagrad、Adagrad等等,读者可以更加自己项目的需求使用不同的优化方法。

In [7]

ini 复制代码
# 定义优化方法
optimizer = paddle.optimizer.SGD(learning_rate=0.01, parameters=net.parameters())

我们可以使用数据进行训练了,我们这次训练了10个pass,读者可根据情况设置更多的训练轮数,通常来说训练的次数和模型收敛有一定的关系。

因为本项目是一个线性回归任务,所以我们在训练的时候使用的是平方差损失函数。因为paddle.nn.functional.square_error_cost求的是一个Batch的损失值,所以我们还要对他求一个平均值。PaddlePaddle提供了很多的损失函数的接口,比如交叉熵损失函数paddle.nn.CrossEntropyLoss

在训练过程中,我们可以看到输出的损失值在不断减小,证明我们的模型在不断收敛。

In [8]

scss 复制代码
# 将numpy类型数据转换成tensor之后才能用于模型训练
inputs = paddle.to_tensor(x_data)
labels = paddle.to_tensor(y_data)

# 开始训练100个pass
for pass_id in range(10):
    out = net(inputs)
    loss = paddle.mean(paddle.nn.functional.square_error_cost(out, labels))

    loss.backward()
    optimizer.step()
    optimizer.clear_grad()

    print("Pass:%d, Cost:%0.5f" % (pass_id, loss))
makefile 复制代码
Pass:0, Cost:56.83829
Pass:1, Cost:16.90196
Pass:2, Cost:2.45377
Pass:3, Cost:0.06338
Pass:4, Cost:0.03584
Pass:5, Cost:0.03505
Pass:6, Cost:0.03432
Pass:7, Cost:0.03361
Pass:8, Cost:0.03291
Pass:9, Cost:0.03223

训练完成之后,我们使用上面克隆主程序得到的预测程序了预测我们刚才定义的预测数据。根据我们上面定义数据时,满足规律y = 2 * x + 1,所以当x为6时,y应该时13,最后输出的结果也是应该接近13的。

In [9]

ini 复制代码
# 开始预测
predict_inputs = paddle.to_tensor(test_data)
result = net(predict_inputs)

print("当x为6.0时,y为:%0.5f" % result)
复制代码
当x为6.0时,y为:13.27442

快来上手第一个Demo吧!------用PaddlePaddle做房价预测

Step1:准备数据。

    1. uci-housing数据集介绍

数据集共506行,每行14列。前13列用来描述房屋的各种信息,最后一列为该类房屋价格中位数。

PaddlePaddle提供了读取uci_housing数据集的接口,paddle.text.datasets.UCIHousing

    1. 数据集加载

PaddlePaddle中使用paddle.io.DataLoader来进行数据的加载操作,通过参数batch_size控制批次大小,shuffle控制是否打乱顺序。

In [10]

ini 复制代码
# 导入基本的库
import os
import paddle
import numpy as np


BATCH_SIZE=20

train_dataset = paddle.text.datasets.UCIHousing(mode='train')
valid_dataset = paddle.text.datasets.UCIHousing(mode='test')

#用于训练的数据加载器,每次随机读取批次大小的数据,剩余不满足批大小的数据丢弃
train_loader = paddle.io.DataLoader(train_dataset, batch_size=BATCH_SIZE, shuffle=True, drop_last=True)

#用于测试的数据加载器,每次随机读取批次大小的数据
valid_loader = paddle.io.DataLoader(valid_dataset, batch_size=BATCH_SIZE, shuffle=True)
arduino 复制代码
Cache file /home/aistudio/.cache/paddle/dataset/uci_housing/housing.data not found, downloading http://paddlemodels.bj.bcebos.com/uci_housing/housing.data 
Begin to download
............
Download finished

打印查看uci_housing数据

In [11]

bash 复制代码
#用于打印,查看uci_housing数据
print(train_dataset[0])
ini 复制代码
(array([-0.0405441 ,  0.06636363, -0.32356226, -0.06916996, -0.03435197,
        0.05563625, -0.03475696,  0.02682186, -0.37171334, -0.21419305,
       -0.33569506,  0.10143217, -0.21172912], dtype=float32), array([24.], dtype=float32))

Step2:网络配置

(1)网络搭建:对于线性回归来讲,它就是一个从输入到输出的简单的全连接层。

对于波士顿房价数据集,假设属性和房价之间的关系可以被属性间的线性组合描述。

In [12]

ini 复制代码
# 输入数据形状为[13],输出形状[1]
net = paddle.nn.Linear(13, 1)

(2)定义损失函数

此处使用均方差损失函数。

square_error_cost(input,lable):接受输入预测值和目标值,并返回方差估计,即为(y-y_predict)的平方

(3)定义优化函数

此处使用的是随机梯度下降。

In [13]

ini 复制代码
optimizer = paddle.optimizer.SGD(learning_rate=0.001, parameters=net.parameters())

Step3.模型训练 and Step4.模型评估

(1)定义绘制训练过程的损失值变化趋势的方法draw_train_process

In [14]

ini 复制代码
import matplotlib.pyplot as plt


iter = 0
iters = []
train_costs = []

def draw_train_process(iters, train_costs):
    title="training cost"
    plt.title(title, fontsize=24)
    plt.xlabel("iter", fontsize=14)
    plt.ylabel("cost", fontsize=14)
    plt.plot(iters, train_costs, color='red', label='training cost') 
    plt.grid()
    plt.show()
python 复制代码
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Sized

(2)训练并保存模型

遍历轮次和数据集loader,将批次数据送入net里面进行计算,最终经过loss计算,在进行反向传播和参数优化。

注:enumerate() 函数用于将一个可遍历的数据对象(如列表、元组或字符串)组合为一个索引序列,同时列出数据和数据下标,

In [15]

ini 复制代码
EPOCH_NUM=50

#训练EPOCH_NUM轮
for pass_id in range(EPOCH_NUM):                                  
    # 开始训练并输出最后一个batch的损失值
    train_cost = 0

    #遍历train_reader迭代器
    for batch_id, data in enumerate(train_loader()):
        inputs = paddle.to_tensor(data[0])
        labels = paddle.to_tensor(data[1])
        out = net(inputs)
        train_loss = paddle.mean(paddle.nn.functional.square_error_cost(out, labels))
        train_loss.backward()
        optimizer.step()
        optimizer.clear_grad()

        #每运行40步,输出一次信息,
        #注意batch_id=0时也输出, 即 0, 40, 80, ...
        if batch_id % 40 == 0:
            print("Pass:%d, Cost:%0.5f" % (pass_id, train_loss))    
        
        iter = iter + BATCH_SIZE
        iters.append(iter)
        train_costs.append(train_loss.numpy()[0])
       
    # 开始测试并输出最后一个batch的损失值
    test_loss = 0

    #遍历test_reader迭代器
    for batch_id, data in enumerate(valid_loader()):               
        inputs = paddle.to_tensor(data[0])
        labels = paddle.to_tensor(data[1])
        out = net(inputs)
        test_loss = paddle.mean(paddle.nn.functional.square_error_cost(out, labels))
        
    #打印最后一个batch的损失值
    print('Test:%d, Cost:%0.5f' % (pass_id, test_loss))     
    
#保存模型
paddle.save(net.state_dict(), 'fit_a_line.pdparams')

draw_train_process(iters,train_costs)
makefile 复制代码
Pass:0, Cost:694.04108
Test:0, Cost:211.20151
Pass:1, Cost:718.70618
Test:1, Cost:81.96242
Pass:2, Cost:475.78058
Test:2, Cost:176.78989
Pass:3, Cost:402.72916
Test:3, Cost:251.75000
Pass:4, Cost:502.68036
Test:4, Cost:113.36610
Pass:5, Cost:568.16602
Test:5, Cost:177.52846
Pass:6, Cost:476.13885
Test:6, Cost:99.38324
Pass:7, Cost:263.62946
Test:7, Cost:131.53128
Pass:8, Cost:408.37491
Test:8, Cost:165.41617
Pass:9, Cost:348.94781
Test:9, Cost:125.17019
Pass:10, Cost:235.03036
Test:10, Cost:128.47586
Pass:11, Cost:373.77365
Test:11, Cost:109.12988
Pass:12, Cost:382.86288
Test:12, Cost:52.62062
Pass:13, Cost:228.76428
Test:13, Cost:135.51625
Pass:14, Cost:147.32423
Test:14, Cost:23.88525
Pass:15, Cost:266.08676
Test:15, Cost:51.34695
Pass:16, Cost:187.61273
Test:16, Cost:218.02568
Pass:17, Cost:201.46187
Test:17, Cost:36.58718
Pass:18, Cost:164.64169
Test:18, Cost:136.90654
Pass:19, Cost:109.09910
Test:19, Cost:43.69257
Pass:20, Cost:165.95181
Test:20, Cost:67.69698
Pass:21, Cost:67.52733
Test:21, Cost:100.40565
Pass:22, Cost:148.87378
Test:22, Cost:44.28013
Pass:23, Cost:272.91302
Test:23, Cost:64.55545
Pass:24, Cost:320.36285
Test:24, Cost:8.77742
Pass:25, Cost:181.69868
Test:25, Cost:36.35912
Pass:26, Cost:68.41258
Test:26, Cost:39.68889
Pass:27, Cost:119.07393
Test:27, Cost:21.35777
Pass:28, Cost:61.71670
Test:28, Cost:5.72559
Pass:29, Cost:53.73602
Test:29, Cost:25.21531
Pass:30, Cost:81.89694
Test:30, Cost:40.26062
Pass:31, Cost:51.65599
Test:31, Cost:1.77657
Pass:32, Cost:18.46457
Test:32, Cost:18.31264
Pass:33, Cost:58.57187
Test:33, Cost:15.08143
Pass:34, Cost:102.43970
Test:34, Cost:13.90950
Pass:35, Cost:81.94363
Test:35, Cost:16.54850
Pass:36, Cost:43.64971
Test:36, Cost:30.42578
Pass:37, Cost:59.23506
Test:37, Cost:22.46311
Pass:38, Cost:91.55733
Test:38, Cost:33.10298
Pass:39, Cost:50.88599
Test:39, Cost:5.41668
Pass:40, Cost:17.12974
Test:40, Cost:29.49467
Pass:41, Cost:34.43634
Test:41, Cost:9.65246
Pass:42, Cost:31.48676
Test:42, Cost:1.60214
Pass:43, Cost:91.27415
Test:43, Cost:6.00659
Pass:44, Cost:49.95349
Test:44, Cost:8.52874
Pass:45, Cost:19.81659
Test:45, Cost:100.12550
Pass:46, Cost:62.98671
Test:46, Cost:97.64473
Pass:47, Cost:65.81707
Test:47, Cost:5.76155
Pass:48, Cost:76.49935
Test:48, Cost:125.73111
Pass:49, Cost:20.85202
Test:49, Cost:1.26879
python 复制代码
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/cbook/__init__.py:2349: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  if isinstance(obj, collections.Iterator):
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/cbook/__init__.py:2366: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  return list(data) if isinstance(data, collections.MappingView) else data
arduino 复制代码
<Figure size 432x288 with 1 Axes>

Step5.模型预测

(1)可视化真实值与预测值方法定义

In [16]

ini 复制代码
infer_results = []
groud_truths = []

#绘制真实值和预测值对比图
def draw_infer_result(groud_truths, infer_results):
    title='Boston'
    plt.title(title, fontsize=24)
    x = np.arange(1,20) 
    y = x
    plt.plot(x, y)
    plt.xlabel('ground truth', fontsize=14)
    plt.ylabel('infer result', fontsize=14)
    plt.scatter(groud_truths, infer_results, color='green',label='training cost') 
    plt.grid()
    plt.show()

(2)开始预测

通过paddle.load加载已经训练好的模型,来对从未遇见过的数据进行预测。

In [17]

ini 复制代码
import paddle
import numpy as np
import matplotlib.pyplot as plt


valid_dataset = paddle.text.UCIHousing(mode='test')
infer_loader = paddle.io.DataLoader(valid_dataset, batch_size=200)

infer_net = paddle.nn.Linear(13, 1)
param = paddle.load('fit_a_line.pdparams')
infer_net.set_dict(param)


data = next(infer_loader())
inputs = paddle.to_tensor(data[0])
results = infer_net(inputs)

for idx, item in enumerate(zip(results, data[1])):
    print("Index:%d, Infer Result: %.2f, Ground Truth: %.2f" % (idx, item[0], item[1]))
    infer_results.append(item[0].numpy()[0])
    groud_truths.append(item[1].numpy()[0])
    
draw_infer_result(groud_truths, infer_results)
yaml 复制代码
Index:0, Infer Result: 13.28, Ground Truth: 8.50
Index:1, Infer Result: 13.60, Ground Truth: 5.00
Index:2, Infer Result: 12.96, Ground Truth: 11.90
Index:3, Infer Result: 14.35, Ground Truth: 27.90
Index:4, Infer Result: 13.48, Ground Truth: 17.20
Index:5, Infer Result: 14.10, Ground Truth: 27.50
Index:6, Infer Result: 13.78, Ground Truth: 15.00
Index:7, Infer Result: 13.48, Ground Truth: 17.20
Index:8, Infer Result: 11.57, Ground Truth: 17.90
Index:9, Infer Result: 13.39, Ground Truth: 16.30
Index:10, Infer Result: 11.18, Ground Truth: 7.00
Index:11, Infer Result: 12.51, Ground Truth: 7.20
Index:12, Infer Result: 13.04, Ground Truth: 7.50
Index:13, Infer Result: 12.64, Ground Truth: 10.40
Index:14, Infer Result: 12.86, Ground Truth: 8.80
Index:15, Infer Result: 13.46, Ground Truth: 8.40
Index:16, Infer Result: 14.27, Ground Truth: 16.70
Index:17, Infer Result: 14.11, Ground Truth: 14.20
Index:18, Infer Result: 14.44, Ground Truth: 20.80
Index:19, Infer Result: 13.16, Ground Truth: 13.40
Index:20, Infer Result: 13.69, Ground Truth: 11.70
Index:21, Infer Result: 12.63, Ground Truth: 8.30
Index:22, Infer Result: 14.15, Ground Truth: 10.20
Index:23, Infer Result: 13.77, Ground Truth: 10.90
Index:24, Infer Result: 13.51, Ground Truth: 11.00
Index:25, Infer Result: 13.03, Ground Truth: 9.50
Index:26, Infer Result: 14.01, Ground Truth: 14.50
Index:27, Infer Result: 13.94, Ground Truth: 14.10
Index:28, Infer Result: 14.67, Ground Truth: 16.10
Index:29, Infer Result: 13.76, Ground Truth: 14.30
Index:30, Infer Result: 13.62, Ground Truth: 11.70
Index:31, Infer Result: 13.16, Ground Truth: 13.40
Index:32, Infer Result: 13.25, Ground Truth: 9.60
Index:33, Infer Result: 12.33, Ground Truth: 8.70
Index:34, Infer Result: 12.04, Ground Truth: 8.40
Index:35, Infer Result: 13.59, Ground Truth: 12.80
Index:36, Infer Result: 13.73, Ground Truth: 10.50
Index:37, Infer Result: 14.10, Ground Truth: 17.10
Index:38, Infer Result: 14.22, Ground Truth: 18.40
Index:39, Infer Result: 14.15, Ground Truth: 15.40
Index:40, Infer Result: 13.12, Ground Truth: 10.80
Index:41, Infer Result: 12.83, Ground Truth: 11.80
Index:42, Infer Result: 14.02, Ground Truth: 14.90
Index:43, Infer Result: 14.28, Ground Truth: 12.60
Index:44, Infer Result: 14.20, Ground Truth: 14.10
Index:45, Infer Result: 13.96, Ground Truth: 13.00
Index:46, Infer Result: 13.44, Ground Truth: 13.40
Index:47, Infer Result: 14.33, Ground Truth: 15.20
Index:48, Infer Result: 14.39, Ground Truth: 16.10
Index:49, Infer Result: 14.78, Ground Truth: 17.80
Index:50, Infer Result: 13.33, Ground Truth: 14.90
Index:51, Infer Result: 13.53, Ground Truth: 14.10
Index:52, Infer Result: 13.08, Ground Truth: 12.70
Index:53, Infer Result: 13.31, Ground Truth: 13.50
Index:54, Infer Result: 14.26, Ground Truth: 14.90
Index:55, Infer Result: 14.63, Ground Truth: 20.00
Index:56, Infer Result: 14.28, Ground Truth: 16.40
Index:57, Infer Result: 14.69, Ground Truth: 17.70
Index:58, Infer Result: 14.81, Ground Truth: 19.50
Index:59, Infer Result: 15.05, Ground Truth: 20.20
Index:60, Infer Result: 15.28, Ground Truth: 21.40
Index:61, Infer Result: 15.09, Ground Truth: 19.90
Index:62, Infer Result: 13.48, Ground Truth: 19.00
Index:63, Infer Result: 14.17, Ground Truth: 19.10
Index:64, Infer Result: 14.85, Ground Truth: 19.10
Index:65, Infer Result: 15.31, Ground Truth: 20.10
Index:66, Infer Result: 14.98, Ground Truth: 19.90
Index:67, Infer Result: 15.31, Ground Truth: 19.60
Index:68, Infer Result: 15.38, Ground Truth: 23.20
Index:69, Infer Result: 15.78, Ground Truth: 29.80
Index:70, Infer Result: 14.19, Ground Truth: 13.80
Index:71, Infer Result: 13.91, Ground Truth: 13.30
Index:72, Infer Result: 14.69, Ground Truth: 16.70
Index:73, Infer Result: 13.50, Ground Truth: 12.00
Index:74, Infer Result: 14.51, Ground Truth: 14.60
Index:75, Infer Result: 15.03, Ground Truth: 21.40
Index:76, Infer Result: 15.88, Ground Truth: 23.00
Index:77, Infer Result: 16.16, Ground Truth: 23.70
Index:78, Infer Result: 16.33, Ground Truth: 25.00
Index:79, Infer Result: 16.05, Ground Truth: 21.80
Index:80, Infer Result: 15.63, Ground Truth: 20.60
Index:81, Infer Result: 15.93, Ground Truth: 21.20
Index:82, Infer Result: 15.10, Ground Truth: 19.10
Index:83, Infer Result: 15.66, Ground Truth: 20.60
Index:84, Infer Result: 16.09, Ground Truth: 15.20
Index:85, Infer Result: 15.40, Ground Truth: 7.00
Index:86, Infer Result: 14.76, Ground Truth: 8.10
Index:87, Infer Result: 16.22, Ground Truth: 13.60
Index:88, Infer Result: 16.82, Ground Truth: 20.10
Index:89, Infer Result: 20.30, Ground Truth: 21.80
Index:90, Infer Result: 20.46, Ground Truth: 24.50
Index:91, Infer Result: 20.25, Ground Truth: 23.10
Index:92, Infer Result: 19.19, Ground Truth: 19.70
Index:93, Infer Result: 19.93, Ground Truth: 18.30
Index:94, Infer Result: 20.20, Ground Truth: 21.20
Index:95, Infer Result: 19.71, Ground Truth: 17.50
Index:96, Infer Result: 19.88, Ground Truth: 16.80
Index:97, Infer Result: 21.37, Ground Truth: 22.40
Index:98, Infer Result: 21.10, Ground Truth: 20.60
Index:99, Infer Result: 21.52, Ground Truth: 23.90
Index:100, Infer Result: 21.39, Ground Truth: 22.00
Index:101, Infer Result: 21.08, Ground Truth: 11.90
arduino 复制代码
<Figure size 432x288 with 1 Axes>

代码解释

到这里你已经学会了PaddlePaddle的基本命令和第一个小例子!恭喜你已经入门啦~ 如果想学习更多入门内容欢迎查看AI Studio 上的更多内容,有精选项目,也有优质课程,加油哦!

NLP12日打卡营即将开始,你准备好了吗!

相关推荐
程序员爱钓鱼1 小时前
Go语言实战案例-创建模型并自动迁移
后端·google·go
javachen__1 小时前
SpringBoot整合P6Spy实现全链路SQL监控
spring boot·后端·sql
uzong7 小时前
技术故障复盘模版
后端
GetcharZp7 小时前
基于 Dify + 通义千问的多模态大模型 搭建发票识别 Agent
后端·llm·agent
桦说编程7 小时前
Java 中如何创建不可变类型
java·后端·函数式编程
IT毕设实战小研7 小时前
基于Spring Boot 4s店车辆管理系统 租车管理系统 停车位管理系统 智慧车辆管理系统
java·开发语言·spring boot·后端·spring·毕业设计·课程设计
wyiyiyi8 小时前
【Web后端】Django、flask及其场景——以构建系统原型为例
前端·数据库·后端·python·django·flask
阿华的代码王国9 小时前
【Android】RecyclerView复用CheckBox的异常状态
android·xml·java·前端·后端
Jimmy9 小时前
AI 代理是什么,其有助于我们实现更智能编程
前端·后端·ai编程
AntBlack9 小时前
不当韭菜V1.1 :增强能力 ,辅助构建自己的交易规则
后端·python·pyqt