楼主: oliyiyi
1345 4

Deep Learning in R [推广有奖]

版主

泰斗

0%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
271951 个
通用积分
31269.3519
学术水平
1435 点
热心指数
1554 点
信用等级
1345 点
经验
383775 点
帖子
9598
精华
66
在线时间
5468 小时
注册时间
2007-5-21
最后登录
2024-4-18

初级学术勋章 初级热心勋章 初级信用勋章 中级信用勋章 中级学术勋章 中级热心勋章 高级热心勋章 高级学术勋章 高级信用勋章 特级热心勋章 特级学术勋章 特级信用勋章

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

Deep learning has a wide range of applications, from speech recognition, computer vision, to self-driving cars and mastering the game of Go. While the concept is intuitive, the implementation is often heuristic and tedious. We will take a stab at simplifying the process, and make the technology more accessible.

Example

We illustrate our approach with the venerable CIFAR-10 dataset. The following code snippet will download the data from its known location to a folder “data/cifar” inside the current working directory. It also creates a data source object for later use.

> library(rpud)
> ds <- rpudlCreateDataSource(
+      data.format="cifar10",
+      data.dir="data/cifar"
+ )

The training process requires us to pre-compute the mean value of the training data. The following will save the result to a file “cifar10-data.mean” inside the data source’s directory.

> rpudlFindTrainingDataMean(ds, filename="cifar10-data.mean")

We then create a model object using a script named cifar10_quick_train.prototxt. The script is written in Google Protocol Buffers format. There is a local copy of the script in the rpudl folder of the rpud installation directory, which is what we will use below. The script is based on the cifar10 example of the Caffe framework. If interested, you can also find the message type definition “rpudl_model.proto” in the same local folder.

> rpudl.path <- file.path(path.package(package="rpud"), "rpudl")
> model <- rpudl(
+       file.path(rpudl.path, "cifar10_quick_train.prototxt"),
+       data.source=ds
+ )

Now we are ready to train the model. The training process takes about 280 seconds on a GTX 660Ti. The result is a new model object with updated parameters. Here, we overwrite the previous model object for simplicity. Should we save the result in a separate model object, we can have a history of the trained models. It reaches about 72% accuracy after 4,000 iterations.

> system.time(model <- rpudlTrain(
+       model, batch=100, iter=4000))
    ....
training @iter 3800, cost 0.535023, accuracy 74%
training @iter 3900, cost 0.689107, accuracy 73%
training @iter 4000, cost 0.655459, accuracy 78%
training ends with average cost of 0.951724, and accuracy 71.78%
  user  system elapsed
210.04   70.17  279.78

We then resume the training with a smaller learning rate. It takes about 72 seconds for another 1,000 iterations, and improves the accuracy to 75%.

> system.time(model <- rpudlTrain(
+       model, batch=100, iter=1000, learning.rate=0.0001)
+       )
    ....
training @iter 4800, cost 0.416993, accuracy 72%
training @iter 4900, cost 0.43716, accuracy 79%
training @iter 5000, cost 0.456889, accuracy 77%
training ends with average cost of 0.874285, and accuracy 75.43%
user  system elapsed
53.97   18.06   71.92

For demonstration purpose, we extract 12 samples from the testing data, and run prediction against the trained model.

> num <- 12
> obj <- rpudlGetTestingDataSamples(ds, c(1, num))
> res <- predict(model, obj$x)
> sum((obj$y) == res)
[1] 12

The model object keeps a history of model cost, which we can print out with the qplotmethod from the ggplot2 library.

> library(ggplot2)
> costs <- model$cost.log
> qplot(1:length(costs), costs, geom="smooth")

We can also have a picture of the weight parameters of a convolutional layer using a rpudlPlotLayerWeights method.

> weights <- rpudlGetLayerWeights(model, "conv1")
> rpudlPlotLayerWeights(weights)


Notes
  • Currently, the rpudl methods are accessible even without an active rpudpluslicense.
  • There are more examples to try out in the rpudl folder of the rpudinstallation directory.
  • The supported data formats are CIFAR, MNIST and LMDB. To train with your own data, you have to export your data to an LMDB database according to the following message type:message Datum {
        required bytes data = 1;
        required uint32 label = 2;
    }

  • The current object model consists of a simple processing pipeline. It does not support Long Short-Term Memory (LSTM) or Network-In-Network (NIN) models. We will address these limitations in upcoming releases.

References

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Learning earning Learn deep Earn technology following download computer learning

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html
沙发
benji427 在职认证  发表于 2016-11-18 10:23:35 |只看作者 |坛友微信交流群
thank you for sharing
已有 1 人评分论坛币 收起 理由
oliyiyi + 10 精彩帖子

总评分: 论坛币 + 10   查看全部评分

使用道具

藤椅
h2h2 发表于 2016-11-18 12:20:36 |只看作者 |坛友微信交流群
谢谢分享
已有 1 人评分经验 收起 理由
oliyiyi + 10 精彩帖子

总评分: 经验 + 10   查看全部评分

使用道具

板凳
minixi 发表于 2016-11-19 12:54:45 |只看作者 |坛友微信交流群
谢谢分享
已有 1 人评分经验 收起 理由
oliyiyi + 10 精彩帖子

总评分: 经验 + 10   查看全部评分

使用道具

报纸
leon_9930754 发表于 2016-11-19 19:02:42 |只看作者 |坛友微信交流群
谢谢分享
已有 1 人评分经验 收起 理由
oliyiyi + 10 精彩帖子

总评分: 经验 + 10   查看全部评分

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-20 00:18