paddlepaddle使用(一)

paddlepaddle是百度提出来的深度学习的框架,个人感觉其实和tensorflow差不多(语法上面),因为本人也是初学者,也不是很懂tensorflow,所以,这些都是个人观点。

百度的paddlepaddle提出貌似有一段时间了,我是最近才知道的,好奇去看了看,而且最近在看tensorflow,所以想看看paddlepaddle是不是友好一点,说实话,tensorflow还是比较难懂的(对于个人来说)。感觉paddlepaddle比tensorflow好的地方在于,paddlepaddle有百度的工程师给出对应视频和代码进行讲解,对于入门深度学习比较好。

以下就是paddlepaddle的第一讲,利用波士顿房价讲解线性回归。

模型训练:

#-*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import paddle.v2 as paddle

# Initialize PaddlePaddle.
paddle.init(use_gpu=False, trainer_count=1)

# Configure the neural network.
x = paddle.layer.data(name=‘x‘, type=paddle.data_type.dense_vector(13))
y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear())

# Infer using provided test data.
probs = paddle.infer(
    output_layer=y_predict,
    parameters=paddle.dataset.uci_housing.model(),
    input=[item for item in paddle.dataset.uci_housing.test()()])

for i in xrange(len(probs)):
    print ‘Predicted price: ${:,.2f}‘.format(probs[i][0] * 1000)

运行结果:

Pass 0, Batch 0, Cost 886.077026
Pass 0, Batch 100, Cost 236.768433
Pass 0, Batch 200, Cost 555.669922
Test 0, Cost 56.372781
Pass 1, Batch 0, Cost 558.157104
Pass 1, Batch 100, Cost 17.486526
Pass 1, Batch 200, Cost 49.110359
Test 1, Cost 22.666769
Pass 2, Batch 0, Cost 2.017142
Pass 2, Batch 100, Cost 5.376208
Pass 2, Batch 200, Cost 1.576212
Test 2, Cost 18.296844
Pass 3, Batch 0, Cost 103.864586
Pass 3, Batch 100, Cost 84.158134
Pass 3, Batch 200, Cost 5.564497
Test 3, Cost 17.668033
Pass 4, Batch 0, Cost 2.316584
Pass 4, Batch 100, Cost 9.555552
Pass 4, Batch 200, Cost 74.418373
Test 4, Cost 17.311696
Pass 5, Batch 0, Cost 9.540855
Pass 5, Batch 100, Cost 22.676167
Pass 5, Batch 200, Cost 123.998085
Test 5, Cost 16.799527
Pass 6, Batch 0, Cost 56.558044
Pass 6, Batch 100, Cost 33.035114
Pass 6, Batch 200, Cost 58.189980
Test 6, Cost 16.333503
Pass 7, Batch 0, Cost 7.590010
Pass 7, Batch 100, Cost 34.771137
Pass 7, Batch 200, Cost 44.883244
Test 7, Cost 16.017060
Pass 8, Batch 0, Cost 42.311310
Pass 8, Batch 100, Cost 24.567163
Pass 8, Batch 200, Cost 33.340485
Test 8, Cost 15.520346
Pass 9, Batch 0, Cost 178.452744
Pass 9, Batch 100, Cost 10.791793
Pass 9, Batch 200, Cost 0.137641
Test 9, Cost 15.214742
Pass 10, Batch 0, Cost 10.072014
Pass 10, Batch 100, Cost 11.594021
Pass 10, Batch 200, Cost 24.404564
Test 10, Cost 14.916112
Pass 11, Batch 0, Cost 5.649694
Pass 11, Batch 100, Cost 31.902603
Pass 11, Batch 200, Cost 11.218608
Test 11, Cost 14.600422
Pass 12, Batch 0, Cost 87.761772
Pass 12, Batch 100, Cost 53.684475
Pass 12, Batch 200, Cost 37.861378
Test 12, Cost 14.326864
Pass 13, Batch 0, Cost 5.141076
Pass 13, Batch 100, Cost 0.324465
Pass 13, Batch 200, Cost 2.333709
Test 13, Cost 14.124264
Pass 14, Batch 0, Cost 9.482045
Pass 14, Batch 100, Cost 22.704296
Pass 14, Batch 200, Cost 12.826228
Test 14, Cost 13.945640
Pass 15, Batch 0, Cost 41.819580
Pass 15, Batch 100, Cost 10.353182
Pass 15, Batch 200, Cost 13.374403
Test 15, Cost 13.767083
Pass 16, Batch 0, Cost 83.044785
Pass 16, Batch 100, Cost 27.363625
Pass 16, Batch 200, Cost 5.347357
Test 16, Cost 13.665516
Pass 17, Batch 0, Cost 0.994224
Pass 17, Batch 100, Cost 0.298174
Pass 17, Batch 200, Cost 140.061615
Test 17, Cost 13.568394
Pass 18, Batch 0, Cost 11.832894
Pass 18, Batch 100, Cost 8.340067
Pass 18, Batch 200, Cost 30.967430
Test 18, Cost 13.465723
Pass 19, Batch 0, Cost 15.379287
Pass 19, Batch 100, Cost 123.313614
Pass 19, Batch 200, Cost 36.328705
Test 19, Cost 13.377999
Pass 20, Batch 0, Cost 12.842525
Pass 20, Batch 100, Cost 54.218903
Pass 20, Batch 200, Cost 18.377592
Test 20, Cost 13.266518
Pass 21, Batch 0, Cost 49.386784
Pass 21, Batch 100, Cost 215.253906
Pass 21, Batch 200, Cost 0.260682
Test 21, Cost 13.237288
Pass 22, Batch 0, Cost 469.974213
Pass 22, Batch 100, Cost 8.073731
Pass 22, Batch 200, Cost 0.810365
Test 22, Cost 13.192008
Pass 23, Batch 0, Cost 145.341141
Pass 23, Batch 100, Cost 15.787022
Pass 23, Batch 200, Cost 4.965213
Test 23, Cost 13.133022
Pass 24, Batch 0, Cost 10.377566
Pass 24, Batch 100, Cost 3.863908
Pass 24, Batch 200, Cost 15.857657
Test 24, Cost 13.113067
Pass 25, Batch 0, Cost 6.239013
Pass 25, Batch 100, Cost 15.914387
Pass 25, Batch 200, Cost 48.752701
Test 25, Cost 13.137239
Pass 26, Batch 0, Cost 57.843086
Pass 26, Batch 100, Cost 0.732344
Pass 26, Batch 200, Cost 48.501846
Test 26, Cost 13.141359
Pass 27, Batch 0, Cost 443.271545
Pass 27, Batch 100, Cost 227.696655
Pass 27, Batch 200, Cost 1.482114
Test 27, Cost 13.094058
Pass 28, Batch 0, Cost 11.784382
Pass 28, Batch 100, Cost 1.334578
Pass 28, Batch 200, Cost 16.487831
Test 28, Cost 13.122105
Pass 29, Batch 0, Cost 10.043719
Pass 29, Batch 100, Cost 26.890572
Pass 29, Batch 200, Cost 11.034937
Test 29, Cost 13.203439
label=8.5, predict=11.7476
label=5.0, predict=13.6822
label=11.9, predict=10.7325
label=27.9, predict=18.0696
label=17.2, predict=13.0193

房价预测:

#-*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import paddle.v2 as paddle

# Initialize PaddlePaddle.
paddle.init(use_gpu=False, trainer_count=1)

# Configure the neural network.
x = paddle.layer.data(name=‘x‘, type=paddle.data_type.dense_vector(13))
y_predict = paddle.layer.fc(input=x, size=1, act=paddle.activation.Linear())

# Infer using provided test data.
probs = paddle.infer(
    output_layer=y_predict,
    parameters=paddle.dataset.uci_housing.model(),
    input=[item for item in paddle.dataset.uci_housing.test()()])

for i in xrange(len(probs)):
    print ‘Predicted price: ${:,.2f}‘.format(probs[i][0] * 1000)

运行结果

Predicted price: $12,316.63
Predicted price: $13,830.34
Predicted price: $11,499.34
Predicted price: $17,395.05
Predicted price: $13,317.67
Predicted price: $16,834.08
Predicted price: $16,632.04
Predicted price: $15,384.20
Predicted price: $7,697.38
Predicted price: $13,657.83
Predicted price: $6,329.62
Predicted price: $12,153.18
Predicted price: $13,890.60
Predicted price: $11,367.41
Predicted price: $13,269.13
Predicted price: $14,979.35
Predicted price: $17,539.03
Predicted price: $16,686.41
Predicted price: $16,810.74
Predicted price: $13,620.53
Predicted price: $14,720.09
Predicted price: $12,533.42
Predicted price: $15,835.49
Predicted price: $16,064.76
Predicted price: $14,566.97
Predicted price: $13,783.11
Predicted price: $16,211.73
Predicted price: $16,362.79
Predicted price: $18,183.92
Predicted price: $16,298.03
Predicted price: $16,084.58
Predicted price: $14,406.07
Predicted price: $15,309.62
Predicted price: $12,104.60
Predicted price: $9,865.44
Predicted price: $14,116.36
Predicted price: $14,552.37
Predicted price: $16,381.32
Predicted price: $16,992.90
Predicted price: $16,722.93
Predicted price: $13,468.48
Predicted price: $13,622.97
Predicted price: $16,512.31
Predicted price: $17,004.60
Predicted price: $16,492.97
Predicted price: $16,179.70
Predicted price: $15,989.17
Predicted price: $17,289.17
Predicted price: $16,975.07
Predicted price: $18,950.22
Predicted price: $15,513.54
Predicted price: $15,652.08
Predicted price: $14,162.51
Predicted price: $14,665.31
Predicted price: $16,724.47
Predicted price: $17,369.51
Predicted price: $17,330.55
Predicted price: $17,923.71
Predicted price: $18,018.71
Predicted price: $19,392.96
Predicted price: $18,379.00
Predicted price: $17,187.61
Predicted price: $14,920.71
Predicted price: $15,435.08
Predicted price: $16,458.07
Predicted price: $17,390.93
Predicted price: $17,520.05
Predicted price: $18,763.72
Predicted price: $18,698.70
Predicted price: $20,425.67
Predicted price: $15,431.77
Predicted price: $14,803.56
Predicted price: $17,336.69
Predicted price: $13,052.34
Predicted price: $16,874.23
Predicted price: $18,547.62
Predicted price: $19,574.30
Predicted price: $21,303.89
Predicted price: $22,053.60
Predicted price: $18,862.40
Predicted price: $17,969.15
Predicted price: $19,496.96
Predicted price: $17,676.56
Predicted price: $18,699.87
Predicted price: $14,520.48
Predicted price: $12,410.05
Predicted price: $9,987.12
Predicted price: $15,381.11
Predicted price: $16,906.17
Predicted price: $21,538.57
Predicted price: $21,566.74
Predicted price: $19,905.33
Predicted price: $17,938.98
Predicted price: $20,776.08
Predicted price: $21,715.28
Predicted price: $20,169.60
Predicted price: $21,148.05
Predicted price: $22,589.09
Predicted price: $21,913.31
Predicted price: $24,388.41
Predicted price: $23,748.72
Predicted price: $22,013.94

来源:paddlepaddle官网、以上代码对应的视频讲解地址

原文地址:https://www.cnblogs.com/ybf-yyj/p/8111498.html

时间: 2024-10-09 01:12:08

paddlepaddle使用(一)的相关文章

Install PaddlePaddle (Parallel Distributed Deep Learning)

Step 1: Install docker on your linux system (My linux version is fedora) https://docs.docker.com/engine/installation/linux/fedora/ Other linux systems You can refer to the official guide https://docs.docker.com/engine/installation/ for further inform

【深度学习系列】PaddlePaddle之数据预处理

上篇文章讲了卷积神经网络的基本知识,本来这篇文章准备继续深入讲CNN的相关知识和手写CNN,但是有很多同学跟我发邮件或私信问我关于PaddlePaddle如何读取数据.做数据预处理相关的内容.网上看的很多教程都是几个常见的例子,数据集不需要自己准备,所以不需要关心,但是实际做项目的时候做数据预处理感觉一头雾水,所以我就写一篇文章汇总一下,讲讲如何用PaddlePaddle做数据预处理. PaddlePaddle的基本数据格式 根据官网的资料,总结出PaddlePaddle支持多种不同的数据格式,

【深度学习系列】用PaddlePaddle和Tensorflow实现AlexNet

上周我们用PaddlePaddle和Tensorflow实现了图像分类,分别用自己手写的一个简单的CNN网络simple_cnn和LeNet-5的CNN网络识别cifar-10数据集.在上周的实验表现中,经过200次迭代后的LeNet-5的准确率为60%左右,这个结果差强人意,毕竟是二十年前写的网络结构,结果简单,层数也很少,这一节中我们讲讲在2012年的Image比赛中大放异彩的AlexNet,并用AlexNet对cifar-10数据进行分类,对比上周的LeNet-5的效果. 什么是AlexN

【深度学习系列】用PaddlePaddle和Tensorflow实现经典CNN网络Vgg

上周我们讲了经典CNN网络AlexNet对图像分类的效果,2014年,在AlexNet出来的两年后,牛津大学提出了Vgg网络,并在ILSVRC 2014中的classification项目的比赛中取得了第2名的成绩(第一名是GoogLeNet,也是同年提出的).在论文<Very Deep Convolutional Networks for Large-Scale Image Recognition>中,作者提出通过缩小卷积核大小来构建更深的网络. Vgg网络结构 VGGnet是Oxford的

【深度学习系列】一起来参加百度 PaddlePaddle AI 大赛吧!

写这个系列写了两个月了,对paddlepaddle的使用越来越熟悉,不过一直没找到合适的应用场景.最近百度搞了个AI大赛,据说有四个赛题,现在是第一个----综艺节目精彩片段预测 ,大家可以去检测一下最近的学习成果啊!还有丰厚的奖金10W元软妹币哦! 这是啥比赛? 看比赛的要求,是希望参赛选手使用PaddlePaddle深度学习框架.利用BROAD数据集.利用K-Lab,着手解决行业中的真实问题,从而让AI真正应用于行业.真正服务于行业.本次大赛,我们将目光放在电视综艺行业,希望选手们利用BRO

【深度学习系列】关于PaddlePaddle的一些避“坑”技巧

最近除了工作以外,业余在参加Paddle的AI比赛,在用Paddle训练的过程中遇到了一些问题,并找到了解决方法,跟大家分享一下: PaddlePaddle的Anaconda的兼容问题 之前我是在服务器上安装的PaddlePaddle的gpu版本,我想把BROAD数据拷贝到服务器上面,结果发现我们服务器的22端口没开,不能用scp传上去,非常郁闷,只能在本地训练.本机mac的显卡是A卡,所以只能装cpu版本的,安装完以后,我发现运行一下程序的时候报错了: 1 import paddle.v2 a

全开源深度学习平台PaddlePaddle入手之路(二)----利用Docker在Windows10专业版环境下配置PaddlePaddle

利用Docker在Windows10专业版环境下配置PaddlePaddle 对于PaddlePaddle的安装,查询官网信息,PaddlePaddle提供pip安装和Docker安装运行的使用方式.我们已经了解到Docker在避免环境配置难题上的的巨大优势,加上本人用的是Windows10操作系统,目前官方对于win10版本给出独特的支持,因而选择了在Docker中安装PaddlePaddle. (1)安装docker 在安装Docker前,切记在Windows中打开Hyper-V管理器中(截

AI系统化风潮渐显,PaddlePaddle如何应对开发者争夺战

最近很多海外企业之中在发生一种很有趣的改变,那就是AI正在脱离其他部门附属品的角色,成为一个独立的部门或事业部. 先是CEO纳德拉对微软大动干戈地进行了重组,将原Windows部门重组成"设备与体验"和"云计算与人工智能平台".很快谷歌也宣布将原来的人工智能及搜索部门一分为二,将人工智能部分独立出来,归由原来谷歌大脑的负责人Jeff Dean领导.不久苹果又挖角了谷歌前人工智能及搜索部门主管John Giannandrea,任命其领导机器学习和人工智能战略并直接向T

基于PaddlePaddle框架利用RNN(循环神经网络)生成古诗句

基于PaddlePaddle框架利用RNN(循环神经网络)生成古诗句 在本项目中,将使用PaddlePaddle实现循环神经网络模型(即RNN模型,以下循环神经网络都称作RNN),并实现基于RNN语言模型进行诗句的生成. 本项目利用全唐诗数据集对RNN语言模型进行训练,能够实现根据输入的前缀诗句,自动生成后续诗句. 本实验所用全唐诗数据集下载地址:https://pan.baidu.com/s/1OgIdxjO2jh5KC8XzG-j8ZQ 1.背景知识 RNN是一个序列模型,基本思路是:在时刻