未加星标

Tutorial: Deep Learning with R on Azure with Keras and CNTK

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二04 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

by Le Zhang (Data Scientist, Microsoft) and Graham Williams (Director of Data Science, Microsoft)

Microsoft's Cognitive Toolkit (better known as CNTK) is a commercial-grade and open-source framework for deep learning tasks. At present CNTK does not have a native R interface but can be accessed through Keras , a high-level API which wraps various deep learning backends including CNTK, TensorFlow, and Theano, for the convenience of modularizing deep neural network construction. The latest version of CNTK (2.1) supports Keras. The RStudio team has developed an R interface for Keras making it possible to run different deep learning backends, including CNTK, from within an R session.

This tutorial illustrates how to simply and quickly spin up a Ubuntu-based Azure Data Science Virtual Machine (DSVM) and to configure a Keras and CNTK environment. An Azure DSVM is a curated virtual machine image coming with an extensive collection of pre-installed open source data science tools. The Keras R package can be readily setup up on the DSVM so as to experience the fun of deep learning.

The deployment of a DSVM is also largely simplified through a few R commands from a local R session (running on your own laptop), thanks to the AzureSMR and AzureDSVM packages for R. With an Azure subscription (visit Microsoft for a free trial subscription) and an initial setup of the Azure Active Directory App for authority to access and manage Azure resources, data scientists can use R to manage and operate selected Azure resources, including to easily interact with and use Azure DSVMs for data analytical jobs.A deploy-compute-destroy cycle is now trivial to orchestrate within R.

The following code snippets create an Azure resource group (a logical collection of related resources) and a Ubuntu DSVMof a specified size within the new resource group:

library(AzureSMR)
library(AzureDSVM)
# Authentication.
asc <- createAzureContext(tenantID = "<tenant_id>", clientID = "<client_id>", authKey = "<authentication_key>")
azureAuthenticate(asc)
# Create a resource group.
azureCreateResourceGroup(asc, location = "southeastasia", resourceGroup = "dsvmrg")
# Deploy a DSVM with specifications.
deployDSVM(asc,
resource.group = "dsvmrg",
size = "Standard_D4_v2",
location = "southeastasia",
hostname = "mydsvm",
username = "myname",
authen = "Password",
password = "MyDSVM_123",
mode = "Sync")

Once this DSVM is deployed it willcost approximately $0.25 per hour ( pricing based on size and location). The DSVM can be powered down as required to reduce costs.

Note that the N-series VMs on Azure now include GPU devices. If a DSVM instance is deployed or resized to the N-series, Keras and CNTK will automatically activate GPU-based capabilities to accelerate model training.

Installation and configuration of Keras can be manually performed after a successful deployment of the DSVM. This post-deployment installation process can be accelerated via Azure Virtual Machine Extensions , which is also functionally available in AzureDSVM:

fileurl <- paste0("https://github.com/yueguoguo/Azure-R-Interface", "/blob/master/demos/demo-5/script.sh")
addExtensionDSVM(asc, location = "southeastasia", resource.group = "dsvmrg", hostname = "mydsvm", os = "Ubuntu", fileurl = fileurl, command = "sudo sh script.sh")

The fileurl and command arguments point to the URL of a script file to download to the DSVM and the command to execute that script on the DSVM, respectively. A sample script for installing and configuring Keras and its R interface in Ubuntu linux DSVM can be found here .

Once the R script has been successfully run the remote DSVM can be accessed via RStudio server or through a remote desktop (e.g., X2Go). Try the following within R on the DSVM to see whether the Keras R interface is installed and CNTK is configured as its backend:

library(keras)
backend()

The output in the console should be "Using CNTK backend" indicating a successful set-up. The Keras R interface provides a set of examples to get started. More information can be found here . Note it is also feasible to switch the backend from CNTK to others such as Tensorflow or Theano, by following the instructions here .

A case study for Solar power forecasting (reproducing CNTK tutorial 106 B ) is available here . It illustrates training a time series forecasting model by using Long Short-Term Memory (LSTM) for predicting solar power generation. The LSTM layer basically captures patterns and long-term dependencies in the historical time series data of solar power readings, to predict the maximum value of total power generation on a specific day. The following chart compares the prediction with the true data.


Tutorial: Deep Learning with R on Azure with Keras and CNTK

The tutorial's model is a simplified version for ease of repeatability but it can be further improved if epoch size is increased and network topology is more sophisticated.

Have fun with Keras + CNTK in R!

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

主题: UbuntuLinux2G
分页:12
转载请注明
本文标题:Tutorial: Deep Learning with R on Azure with Keras and CNTK
本站链接:http://www.codesec.net/view/561421.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(22)