Skip to content

Commit d2c857f

Browse files
author
Ilia Karmanov
authored
Merge pull request ilkarman#82 from ilkarman/vapaunic/kerasr
Vapaunic/kerasr
2 parents 2349e13 + cbe6477 commit d2c857f

File tree

4 files changed

+91
-67
lines changed

4 files changed

+91
-67
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The notebooks are executed on an Azure [Deep Learning Virtual Machine](https://a
4040
| [PyTorch](notebooks/PyTorch_CNN.ipynb) | 169 | 51 |
4141
| [Julia - Knet](notebooks/Knet_CNN.ipynb) | 159 | ?? |
4242
| [R - MXNet](notebooks/.ipynb) | ??? | ?? |
43-
| [R - Keras (TF)](notebooks/KerasR_TF_CNN.ipynb) | 211 | 75 |
43+
| [R - Keras(TF)](notebooks/KerasR_TF_CNN.ipynb) | 205 | 72 |
4444

4545

4646
*Note: It is recommended to use higher level APIs where possible; see these notebooks for examples with [Tensorflow](notebooks/Tensorflow_CNN_highAPI.ipynb), [MXNet](notebooks/MXNet_CNN_highAPI.ipynb) and [CNTK](notebooks/CNTK_CNN_highAPI.ipynb). They are not linked in the table to keep the common-structure-for-all approach*
@@ -94,7 +94,7 @@ Input for this model is 112,120 PNGs of chest X-rays resized to (264, 264). **No
9494
| [PyTorch](notebooks/PyTorch_Inference.ipynb) | 7.7 | 1.9 |
9595
| [Julia - Knet](notebooks/Knet_Inference.ipynb) | 6.3 | ??? |
9696
| [R - MXNet](notebooks/.ipynb) | ??? | ??? |
97-
| [R - Keras (TF)](notebooks/KerasR_TF_Inference.ipynb)| 16 | 7.5 |
97+
| [R - Keras(TF)](notebooks/KerasR_TF_Inference.ipynb)| 17 | 7.4 |
9898

9999

100100
A pre-trained ResNet50 model is loaded and chopped just after the avg_pooling at the end (7, 7), which outputs a 2048D dimensional vector. This can be plugged into a softmax layer or another classifier such as a boosted tree to perform transfer learning. Allowing for a warm start; this forward-only pass to the avg_pool layer is timed. *Note: batch-size remains constant, however filling the RAM on a GPU would produce further performance boosts (greater for GPUs with more RAM).*
@@ -111,7 +111,7 @@ A pre-trained ResNet50 model is loaded and chopped just after the avg_pooling at
111111
| [Tensorflow](notebooks/Tensorflow_RNN.ipynb) | 30 | 22 | Yes |
112112
| [Julia - Knet](notebooks/Knet_RNN.ipynb) | 29 | ?? | Yes |
113113
| [R - MXNet](notebooks/.ipynb) | ?? | ?? | ??? |
114-
| [R - Keras (TF)](notebooks/KerasR_TF_RNN.ipynb) | 238 | 209 | No |
114+
| [R - Keras(TF)](notebooks/KerasR_TF_RNN.ipynb) | 35 | 25 | Yes |
115115

116116

117117
Input for this model is the standard [IMDB movie review dataset](http://ai.stanford.edu/~amaas/data/sentiment/) containing 25k training reviews and 25k test reviews, uniformly split across 2 classes (positive/negative). Processing follows [Keras](https://github.com/fchollet/keras/blob/master/keras/datasets/imdb.py) approach where start-character is set as 1, out-of-vocab (vocab size of 30k is used) represented as 2 and thus word-index starts from 3. Zero-padded / truncated to fixed axis of 150 words per review.

notebooks/KerasR_TF_CNN.ipynb

+26-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"# SETUP\n",
1919
"#\n",
2020
"# Install keras R\n",
21-
"# install.packages('keras')\n",
21+
"# install.packages('keras', repos = \"https://cloud.r-project.org\")\n",
2222
"# \n",
2323
"# Update reticulate from cran (it defaults to mran which has an outdated version)\n",
2424
"# install.packages(\"reticulate\", repos = \"https://cloud.r-project.org\")"
@@ -64,6 +64,17 @@
6464
{
6565
"cell_type": "code",
6666
"execution_count": 4,
67+
"metadata": {
68+
"collapsed": true
69+
},
70+
"outputs": [],
71+
"source": [
72+
"# reticulate::py_config()"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": 5,
6778
"metadata": {
6879
"scrolled": true
6980
},
@@ -74,8 +85,8 @@
7485
"text": [
7586
"OS: Linux \n",
7687
"R version 3.4.1 (2017-06-30) \n",
77-
"Keras: 2.0.6 \n",
78-
"Tensorflow: 1.3.1 \n",
88+
"Keras: 2.1.5 \n",
89+
"Tensorflow: 1.5 \n",
7990
"Keras using tensorflow \n",
8091
"Keras channel ordering is channels_first \n",
8192
"GPU: Tesla P100-PCIE-16GB \n",
@@ -85,7 +96,6 @@
8596
}
8697
],
8798
"source": [
88-
"# py_config()\n",
8999
"cat(\"OS:\", Sys.info()[\"sysname\"], \"\\n\")\n",
90100
"cat(R.version$version.string, \"\\n\")\n",
91101
"cat(\"Keras:\", paste0(packageVersion(\"keras\")), \"\\n\")\n",
@@ -99,7 +109,7 @@
99109
},
100110
{
101111
"cell_type": "code",
102-
"execution_count": 5,
112+
"execution_count": 6,
103113
"metadata": {
104114
"collapsed": true
105115
},
@@ -138,7 +148,7 @@
138148
},
139149
{
140150
"cell_type": "code",
141-
"execution_count": 6,
151+
"execution_count": 7,
142152
"metadata": {
143153
"collapsed": true
144154
},
@@ -156,7 +166,7 @@
156166
},
157167
{
158168
"cell_type": "code",
159-
"execution_count": 7,
169+
"execution_count": 8,
160170
"metadata": {},
161171
"outputs": [
162172
{
@@ -181,7 +191,7 @@
181191
},
182192
{
183193
"cell_type": "code",
184-
"execution_count": 8,
194+
"execution_count": 9,
185195
"metadata": {},
186196
"outputs": [
187197
{
@@ -204,7 +214,7 @@
204214
},
205215
{
206216
"cell_type": "code",
207-
"execution_count": 9,
217+
"execution_count": 10,
208218
"metadata": {
209219
"collapsed": true
210220
},
@@ -216,7 +226,7 @@
216226
},
217227
{
218228
"cell_type": "code",
219-
"execution_count": 10,
229+
"execution_count": 11,
220230
"metadata": {
221231
"collapsed": true
222232
},
@@ -228,7 +238,7 @@
228238
},
229239
{
230240
"cell_type": "code",
231-
"execution_count": 11,
241+
"execution_count": 12,
232242
"metadata": {
233243
"scrolled": true
234244
},
@@ -277,14 +287,14 @@
277287
},
278288
{
279289
"cell_type": "code",
280-
"execution_count": 12,
290+
"execution_count": 13,
281291
"metadata": {},
282292
"outputs": [
283293
{
284294
"data": {
285295
"text/plain": [
286296
" user system elapsed \n",
287-
" 69.731 14.883 75.247 "
297+
" 69.565 14.586 71.634 "
288298
]
289299
},
290300
"metadata": {},
@@ -303,7 +313,7 @@
303313
},
304314
{
305315
"cell_type": "code",
306-
"execution_count": 13,
316+
"execution_count": 14,
307317
"metadata": {
308318
"collapsed": true
309319
},
@@ -316,14 +326,14 @@
316326
},
317327
{
318328
"cell_type": "code",
319-
"execution_count": 14,
329+
"execution_count": 15,
320330
"metadata": {},
321331
"outputs": [
322332
{
323333
"name": "stdout",
324334
"output_type": "stream",
325335
"text": [
326-
"[1] \"Accuracy: 0.7743\"\n"
336+
"[1] \"Accuracy: 0.7685\"\n"
327337
]
328338
}
329339
],

notebooks/KerasR_TF_Inference.ipynb

+25-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"# SETUP\n",
1212
"#\n",
1313
"# Install keras R\n",
14-
"# install.packages('keras')\n",
14+
"# install.packages('keras', repos = \"https://cloud.r-project.org\")\n",
1515
"# \n",
1616
"# Update reticulate from cran (it defaults to mran which has an outdated version)\n",
1717
"# install.packages(\"reticulate\", repos = \"https://cloud.r-project.org\")"
@@ -44,6 +44,17 @@
4444
{
4545
"cell_type": "code",
4646
"execution_count": 3,
47+
"metadata": {
48+
"collapsed": true
49+
},
50+
"outputs": [],
51+
"source": [
52+
"# reticulate::py_config()"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 4,
4758
"metadata": {},
4859
"outputs": [
4960
{
@@ -52,8 +63,8 @@
5263
"text": [
5364
"OS: Linux \n",
5465
"R version 3.4.1 (2017-06-30) \n",
55-
"Keras: 2.0.6 \n",
56-
"Tensorflow: 1.3.1 \n",
66+
"Keras: 2.1.5 \n",
67+
"Tensorflow: 1.5 \n",
5768
"Keras using tensorflow \n",
5869
"Keras channel ordering is channels_last \n",
5970
"GPU: Tesla P100-PCIE-16GB \n",
@@ -63,7 +74,6 @@
6374
}
6475
],
6576
"source": [
66-
"# py_config()\n",
6777
"cat(\"OS:\", Sys.info()[\"sysname\"], \"\\n\")\n",
6878
"cat(R.version$version.string, \"\\n\")\n",
6979
"cat(\"Keras:\", paste0(packageVersion(\"keras\")), \"\\n\")\n",
@@ -77,7 +87,7 @@
7787
},
7888
{
7989
"cell_type": "code",
80-
"execution_count": 4,
90+
"execution_count": 5,
8191
"metadata": {
8292
"collapsed": true
8393
},
@@ -89,7 +99,7 @@
8999
},
90100
{
91101
"cell_type": "code",
92-
"execution_count": 5,
102+
"execution_count": 6,
93103
"metadata": {},
94104
"outputs": [
95105
{
@@ -106,7 +116,7 @@
106116
},
107117
{
108118
"cell_type": "code",
109-
"execution_count": 6,
119+
"execution_count": 7,
110120
"metadata": {
111121
"collapsed": true
112122
},
@@ -118,7 +128,7 @@
118128
},
119129
{
120130
"cell_type": "code",
121-
"execution_count": 7,
131+
"execution_count": 8,
122132
"metadata": {},
123133
"outputs": [
124134
{
@@ -130,7 +140,9 @@
130140
"================================================================================\n",
131141
"input_1 (InputLayer) (None, 224, 224, 0 \n",
132142
"________________________________________________________________________________\n",
133-
"conv1 (Conv2D) (None, 112, 112, 9472 input_1[0][0] \n",
143+
"conv1_pad (ZeroPadding2D) (None, 230, 230, 0 input_1[0][0] \n",
144+
"________________________________________________________________________________\n",
145+
"conv1 (Conv2D) (None, 112, 112, 9472 conv1_pad[0][0] \n",
134146
"________________________________________________________________________________\n",
135147
"bn_conv1 (BatchNormalizat (None, 112, 112, 256 conv1[0][0] \n",
136148
"________________________________________________________________________________\n",
@@ -505,14 +517,14 @@
505517
},
506518
{
507519
"cell_type": "code",
508-
"execution_count": 8,
520+
"execution_count": 9,
509521
"metadata": {},
510522
"outputs": [
511523
{
512524
"data": {
513525
"text/plain": [
514526
" user system elapsed \n",
515-
" 6.510 1.284 7.489 "
527+
" 6.161 1.612 7.432 "
516528
]
517529
},
518530
"metadata": {},
@@ -529,14 +541,14 @@
529541
},
530542
{
531543
"cell_type": "code",
532-
"execution_count": 9,
544+
"execution_count": 10,
533545
"metadata": {},
534546
"outputs": [
535547
{
536548
"name": "stdout",
537549
"output_type": "stream",
538550
"text": [
539-
"[1] \"Images per second 170.917345439979\"\n"
551+
"[1] \"Images per second 172.228202368138\"\n"
540552
]
541553
}
542554
],

0 commit comments

Comments
 (0)