-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeep-learning-with-jupyter-on-aws.html
313 lines (269 loc) · 21.5 KB
/
deep-learning-with-jupyter-on-aws.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Cathy Yeh" />
<meta property="og:type" content="article" />
<meta name="twitter:card" content="summary">
<meta name="keywords" content="AWS, bash, cloud, deep learning, Jupyter, Tools, " />
<meta property="og:title" content="Start deep learning with Jupyter notebooks in the cloud "/>
<meta property="og:url" content="./deep-learning-with-jupyter-on-aws" />
<meta property="og:description" content="Want a quick and easy way to play around with deep learning libraries? Puny GPU got you down? Thanks to Amazon Web Services (AWS) — specifically, AWS Elastic Compute Cloud (EC2) — no data scientist need be left behind. Jupyter/IPython notebooks are indispensable tools for learning and tinkering. This post shows …" />
<meta property="og:site_name" content="EFAVDB" />
<meta property="og:article:author" content="Cathy Yeh" />
<meta property="og:article:published_time" content="2016-03-10T20:41:00-08:00" />
<meta name="twitter:title" content="Start deep learning with Jupyter notebooks in the cloud ">
<meta name="twitter:description" content="Want a quick and easy way to play around with deep learning libraries? Puny GPU got you down? Thanks to Amazon Web Services (AWS) — specifically, AWS Elastic Compute Cloud (EC2) — no data scientist need be left behind. Jupyter/IPython notebooks are indispensable tools for learning and tinkering. This post shows …">
<title>Start deep learning with Jupyter notebooks in the cloud · EFAVDB
</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Fira+Sans:300,400,700" rel="stylesheet" type='text/css' />
<link href="https://fonts.googleapis.com/css?family=Cardo:400,700" rel="stylesheet" type='text/css' />
<link rel="stylesheet" type="text/css" href="./theme/css/elegant.prod.css" media="screen">
<link rel="stylesheet" type="text/css" href="./theme/css/custom.css" media="screen">
<link rel="apple-touch-icon" sizes="180x180" href="./images/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="./images/favicon-16x16.png">
<link rel="manifest" href="./images/site.webmanifest">
<link rel="mask-icon" href="./images/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
</head>
<body>
<div id="content">
<div class="navbar navbar-static-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="./"><span class=site-name>EFAVDB</span></a>
<div class="nav-collapse collapse">
<ul class="nav pull-right top-menu">
<li >
<a href=
.
>Home</a>
</li>
<li ><a href="./pages/authors.html">Authors</a></li>
<li ><a href="./categories.html">Categories</a></li>
<li ><a href="./tags.html">Tags</a></li>
<li ><a href="./archives.html">Archives</a></li>
<li><form class="navbar-search" action="./search.html" onsubmit="return validateForm(this.elements['q'].value);"> <input type="text" class="search-query" placeholder="Search" name="q" id="tipue_search_input"></form></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span1"></div>
<div class="span10">
<article itemscope>
<div class="row-fluid">
<header class="page-header span8 offset2">
<h1>
<a href="./deep-learning-with-jupyter-on-aws">
Start deep learning with Jupyter notebooks in the cloud
</a>
</h1>
</header>
<div class="span2"></div>
</div>
<div class="row-fluid">
<div class="span8 offset2 article-content">
<p>Want a quick and easy way to play around with deep learning libraries? Puny <span class="caps">GPU</span> got you down? Thanks to Amazon Web Services (<span class="caps">AWS</span>) — specifically, <span class="caps">AWS</span> Elastic Compute Cloud (<span class="caps">EC2</span>) — no data scientist need be left behind.</p>
<p>Jupyter/IPython notebooks are indispensable tools for learning and tinkering. This post shows how to set up a public Jupyter notebook server in <span class="caps">EC2</span> and then access it remotely through your web browser, just as you would if you were using a notebook launched from your own laptop.</p>
<p>For a beginner, having to both set up deep learning libraries and navigate the <span class="caps">AWS</span> menagerie feels like getting thrown into the deep end when you just want to stick a toe in. You can skip the hassle of setting up deep learning frameworks from scratch by choosing an Amazon Machine Image (<span class="caps">AMI</span>) that comes pre-installed with the libraries and their dependencies. (Concerned about costs? — see the note<a href="#note1">*</a> at the bottom of this post.)</p>
<p>For example, the Stanford class, <a href="http://cs231n.stanford.edu/">CS231n: Convolutional Neural Networksfor Visual Recognition</a>, has provided a public <span class="caps">AMI</span> with these specs:</p>
<ul>
<li>cs231n_caffe_torch7_keras_lasagne_v2</li>
<li><span class="caps">AMI</span> <span class="caps">ID</span>: ami-125b2c72 in the us-west-1 region</li>
<li>Use a g2.2xlarge instance.</li>
<li>Caffe, Torch7, Theano, Keras and Lasagne are pre-installed. Python bindings of caffe are available. It has <span class="caps">CUDA</span> 7.5 and CuDNN v3.</li>
</ul>
<p>If you’re new to <span class="caps">AWS</span>, CS231n provides a nice step-by-step <a href="http://cs231n.github.io/aws-tutorial/"><span class="caps">AWS</span> tutorial</a> with lots of screenshots. We’re just going to tweak their procedure to enable access to Jupyter/IPython notebooks.</p>
<p>After you’re done, you’ll be able to work through tutorials in notebook format like those provided by caffe in their examples folder, e.g. <a href="http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/00-classification.ipynb">00-classification.ipynb</a>.</p>
<p>We’ve written a little bash script <code>jupyter_userdata.sh</code> to execute Jupyter’s <a href="http://jupyter-notebook.readthedocs.org/en/latest/public_server.html">instructions</a> for setting up a public notebook server, so you don’t have to manually configure the notebook server every time you want to spin up a new <span class="caps">AMI</span> instance.</p>
<p>For the script to work, Jupyter itself should already be installed — which it is in the CS231n <span class="caps">AMI</span>.</p>
<p>You just have to edit the password in the script. To generate a hashed password, use IPython:</p>
<div class="highlight"><pre><span></span><code><span class="n">In</span> <span class="p">[</span><span class="mi">1</span><span class="p">]:</span> <span class="kn">from</span> <span class="nn">notebook.auth</span> <span class="kn">import</span> <span class="n">passwd</span>
<span class="n">In</span> <span class="p">[</span><span class="mi">2</span><span class="p">]:</span> <span class="n">passwd</span><span class="p">()</span>
<span class="n">Enter</span> <span class="n">password</span><span class="p">:</span>
<span class="n">Verify</span> <span class="n">password</span><span class="p">:</span>
<span class="n">Out</span><span class="p">[</span><span class="mi">2</span><span class="p">]:</span> <span class="s1">'sha1:bcd259ccf...<your hashed password here>'</span>
</code></pre></div>
<p>Replace the right hand side of line 24 in the script with the hashed password you just generated.</p>
<hr>
<p>Then, follow these steps to launch an <span class="caps">EC2</span> instance.</p>
<p><strong>1.</strong> First, follow the CS231n <a href="http://cs231n.github.io/aws-tutorial/"><span class="caps">AWS</span> tutorial</a> up until the step <em>“Choose the instance type <code>g2.2xlarge</code>, and click on “Review and Launch”</em>.</p>
<p>Don’t click on “Review and Launch” yet!</p>
<p><strong>2.</strong> Here’s where we add a couple extra steps to the tutorial.<a href="#note2">**</a></p>
<p>We’re going to supply the shell script as <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html">user-data</a>, a way to pass in scripts to automate configurations to your <span class="caps">AMI</span>. Instead of clicking on “Review and Launch”, click on the gray button in the lower right “Next: Configure Instance Details”.</p>
<p>In the next page, click on the arrowhead next to “Advanced Details” to expand its options. Click on the radio button next to “As text”, then copy and paste the text from <code>jupyter_userdata.sh</code> (modified with your password) into the field.</p>
<p>Warning: if you click on “As file” instead and browse to wherever you saved <code>jupyter_userdata.sh</code>, the file must first be <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html">base64-encoded</a>.</p>
<p><a href="./wp-content/uploads/2016/03/Step3_Configure-Instance-Details.png"><img alt="" src="./wp-content/uploads/2016/03/Step3_Configure-Instance-Details.png"></a></p>
<p><strong>3.</strong> Next, (skipping steps 4. and 5.) click on the link to “6. Configure Security Group” near the top of the page. By default, <span class="caps">SSH</span> is enabled, but we need to enable access to the notebook server, whose port we’ve set as 8888 in the bash script.</p>
<p>Click on the grey button “Add Rule”, then for the new rule, choose Type: Custom <span class="caps">TCP</span> Rule; Protocol: <span class="caps">TCP</span>; Port Range: 8888; Source: Anywhere.</p>
<p><a href="./wp-content/uploads/2016/03/Step6_Configure-Security-Group.png"><img alt="" src="./wp-content/uploads/2016/03/Step6_Configure-Security-Group.png"></a></p>
<p><strong>4.</strong> Now, pick up where you left off in the CS231n tutorial (“<em>… click on “Review and Launch</em>“.), which takes you to “Step 7. Review Instance Launch”. Complete the tutorial.</p>
<hr>
<p>Check that the Jupyter notebook server was set up correctly:</p>
<ol>
<li>ssh into your instance (see CS231n instructions).</li>
<li>Navigate to <code>~/caffe/examples</code>.</li>
<li>Start the notebook server using the <code>jupyter notebook</code> command.</li>
<li>
<p>In your web browser, access the notebook server with https://PUBLIC_IP:8888, where PUBLIC_IP is the public <span class="caps">IP</span> of your instance, displayed from the instance description on your <span class="caps">AWS</span> dashboard. Your browser will warn that your self-signed certificate is insecure or unrecognized.</p>
<p><a href="./wp-content/uploads/2016/03/scary-browser-warning.png"><img alt="" src="./wp-content/uploads/2016/03/scary-browser-warning.png"></a></p>
<p>That’s ok — click past the warnings, and you should get a sign-in page. Type in your password.</p>
</li>
<li>
<p>Next, you should see the files and directories in <code>/home/ubuntu/caffe/examples</code></p>
</li>
<li>Open one of the example notebooks, e.g. <code>00-classification.ipynb</code>, and try running some cells to make sure everything is working.</li>
</ol>
<p>Voila! We hope this guide removes some obstacles to getting started. Happy learning!</p>
<hr>
<ul>
<li>The cost of running a <span class="caps">GPU</span> instance is high compared to many other instance types, but still very reasonable if you’re just tinkering for a few hours on a pre-trained model, not training a whole neural network from scratch.</li>
</ul>
<p>Check out the <a href="https://aws.amazon.com/ec2/pricing/">pricing</a> for an <span class="caps">EC2</span> instance in the section “On-Demand Instance Prices” and selecting the region of your <span class="caps">AMI</span>. At the time of writing, the cost of an on-demand <code>g2.2xlarge</code> instance in the <span class="caps">US</span> West (Northern California) region was $0.7/hour, whereas the price of a <a href="https://aws.amazon.com/ec2/spot/pricing/">spot</a> instance (a cheaper alternative which will automatically terminate when the spot pricing exceeds your bid) was $0.3/hour.</p>
<p><strong> If you followed the CS231n tutorial exactly and forgot to supply user data, you can still use this script. First modify the security configuration of your instance according to step </strong>3**. Then use the <code>scp</code> command to copy the script from your local computer to your instance, <code>ssh</code> into your instance, then execute the script: <code>source jupyter_userdata.sh</code>. If you need help with using <code>scp</code>, see “To use <span class="caps">SCP</span> to transfer a file” in this <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html">guide</a>.</p>
<p id="post-share-links">
Like this post? Share on:
<a href="https://twitter.com/intent/tweet?text=Start%20deep%20learning%20with%20Jupyter%20notebooks%20in%20the%C2%A0cloud&url=/deep-learning-with-jupyter-on-aws&hashtags=aws,bash,cloud,deep-learning,jupyter" target="_blank" rel="nofollow noopener noreferrer" title="Share on Twitter">Twitter</a>
|
<a href="https://www.facebook.com/sharer/sharer.php?u=/deep-learning-with-jupyter-on-aws" target="_blank" rel="nofollow noopener noreferrer" title="Share on Facebook">Facebook</a>
|
<a href="mailto:?subject=Start%20deep%20learning%20with%20Jupyter%20notebooks%20in%20the%C2%A0cloud&body=/deep-learning-with-jupyter-on-aws" target="_blank" rel="nofollow noopener noreferrer" title="Share via Email">Email</a>
</p>
<hr />
<div class="author_blurb">
<a href="" target="_blank" rel="nofollow noopener noreferrer">
<img src=/images/cy_efavdb_headshot.jpg alt="Cathy Yeh Avatar" title="Cathy Yeh">
<span class="author_name">Cathy Yeh</span>
</a>
Cathy Yeh got a PhD at UC Santa Barbara studying soft-matter/polymer physics. After stints in a translational modeling group at Pfizer in San Diego, Driver (a no longer extant startup trying to match cancer patients to clinical trials) in San Francisco, and Square, she is currently participating in the OpenAI Scholars program.
</div>
<hr/>
<aside>
<nav>
<ul class="articles-timeline">
<li class="previous-article">« <a href="./dotfiles" title="Previous: Dotfiles for peace of mind">Dotfiles for peace of mind</a></li>
<li class="next-article"><a href="./caffe-virtualbox" title="Next: Try Caffe pre-installed on a VirtualBox image">Try Caffe pre-installed on a VirtualBox image</a> »</li>
</ul>
</nav>
</aside>
</div>
<section id="article-sidebar" class="span2">
<h4>Published</h4>
<time itemprop="dateCreated" datetime="2016-03-10T20:41:00-08:00">Mar 10, 2016</time>
<h4>Category</h4>
<a class="category-link" href="./categories.html#tools-ref">Tools</a>
<h4>Tags</h4>
<ul class="list-of-tags tags-in-article">
<li><a href="./tags.html#aws-ref">AWS
<span>1</span>
</a></li>
<li><a href="./tags.html#bash-ref">bash
<span>2</span>
</a></li>
<li><a href="./tags.html#cloud-ref">cloud
<span>3</span>
</a></li>
<li><a href="./tags.html#deep-learning-ref">deep learning
<span>3</span>
</a></li>
<li><a href="./tags.html#jupyter-ref">Jupyter
<span>2</span>
</a></li>
</ul>
<h4>Contact</h4>
<div id="sidebar-social-link">
<a href="https://twitter.com/efavdb" title="" target="_blank" rel="nofollow noopener noreferrer">
<svg xmlns="http://www.w3.org/2000/svg" aria-label="Twitter" role="img" viewBox="0 0 512 512"><rect width="512" height="512" rx="15%" fill="#1da1f3"/><path fill="#fff" d="M437 152a72 72 0 0 1-40 12 72 72 0 0 0 32-40 72 72 0 0 1-45 17 72 72 0 0 0-122 65 200 200 0 0 1-145-74 72 72 0 0 0 22 94 72 72 0 0 1-32-7 72 72 0 0 0 56 69 72 72 0 0 1-32 1 72 72 0 0 0 67 50 200 200 0 0 1-105 29 200 200 0 0 0 309-179 200 200 0 0 0 35-37"/></svg>
</a>
<a href="https://github.com/efavdb" title="" target="_blank" rel="nofollow noopener noreferrer">
<svg xmlns="http://www.w3.org/2000/svg" aria-label="GitHub" role="img" viewBox="0 0 512 512"><rect width="512" height="512" rx="15%" fill="#1B1817"/><path fill="#fff" d="M335 499c14 0 12 17 12 17H165s-2-17 12-17c13 0 16-6 16-12l-1-50c-71 16-86-28-86-28-12-30-28-37-28-37-24-16 1-16 1-16 26 2 40 26 40 26 22 39 59 28 74 22 2-17 9-28 16-35-57-6-116-28-116-126 0-28 10-51 26-69-3-6-11-32 3-67 0 0 21-7 70 26 42-12 86-12 128 0 49-33 70-26 70-26 14 35 6 61 3 67 16 18 26 41 26 69 0 98-60 120-117 126 10 8 18 24 18 48l-1 70c0 6 3 12 16 12z"/></svg>
</a>
<a href="https://www.youtube.com/channel/UClfvjoSiu0VvWOh5OpnuusA" title="" target="_blank" rel="nofollow noopener noreferrer">
<svg xmlns="http://www.w3.org/2000/svg" aria-label="YouTube" role="img" viewBox="0 0 512 512" fill="#ed1d24"><rect width="512" height="512" rx="15%"/><path d="m427 169c-4-15-17-27-32-31-34-9-239-10-278 0-15 4-28 16-32 31-9 38-10 135 0 174 4 15 17 27 32 31 36 10 241 10 278 0 15-4 28-16 32-31 9-36 9-137 0-174" fill="#fff"/><path d="m220 203v106l93-53"/></svg>
</a>
</div>
</section>
</div>
</article>
<button onclick="topFunction()" id="myBtn" title="Go to top">▲</button>
</div>
<div class="span1"></div>
</div>
</div>
</div>
<footer>
<div>
<span class="site-name"><a href= .>EFAVDB</span> - Everybody's Favorite Data Blog</a>
</div>
<!-- <div id="fpowered"> -->
<!-- Powered by: <a href="http://getpelican.com/" title="Pelican Home Page" target="_blank" rel="nofollow noopener noreferrer">Pelican</a> -->
<!-- Theme: <a href="https://elegant.oncrashreboot.com/" title="Theme Elegant Home Page" target="_blank" rel="nofollow noopener noreferrer">Elegant</a> -->
<!-- -->
<!-- </div> -->
</footer> <script src="//code.jquery.com/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script>
function validateForm(query)
{
return (query.length > 0);
}
</script>
<script>
//** Scroll to top button **
//Get the button:
mybutton = document.getElementById("myBtn");
// When the user scrolls down 30px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 30 || document.documentElement.scrollTop > 30) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
</script>
<script>
(function () {
if (window.location.hash.match(/^#comment-\d+$/)) {
$('#comment_thread').collapse('show');
}
})();
window.onhashchange=function(){
if (window.location.hash.match(/^#comment-\d+$/))
window.location.reload(true);
}
$('#comment_thread').on('shown', function () {
var link = document.getElementById('comment-accordion-toggle');
var old_innerHTML = link.innerHTML;
$(link).fadeOut(200, function() {
$(this).text('Click here to hide comments').fadeIn(200);
});
$('#comment_thread').on('hidden', function () {
$(link).fadeOut(200, function() {
$(this).text(old_innerHTML).fadeIn(200);
});
})
})
</script>
</body>
<!-- Theme: Elegant built for Pelican
License : MIT -->
</html>