-
Notifications
You must be signed in to change notification settings - Fork 14
/
README.Rmd
156 lines (117 loc) · 4.14 KB
/
README.Rmd
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
---
title: "R Interface to AutoKeras"
output: github_document
---
[![Travis Build Status](https://travis-ci.org/r-tensorflow/autokeras.svg?branch=master)](https://travis-ci.org/r-tensorflow/autokeras)
[![Coverage status](https://img.shields.io/codecov/c/github/jcrodriguez1989/autokeras/master.svg)](https://codecov.io/github/jcrodriguez1989/autokeras?branch=master)
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[AutoKeras](https://autokeras.com/) is an open source software library for
automated machine learning (AutoML). It is developed by
[DATA Lab](https://people.engr.tamu.edu/xiahu/index.html) at Texas A&M
University and community contributors. The ultimate goal of AutoML is to
provide easily accessible deep learning tools to domain experts with limited
data science or machine learning background. AutoKeras provides functions
to automatically search for architecture and hyperparameters of deep
learning models.
Check out the [AutoKeras blogpost at the **RStudio TensorFlow for R blog**](https://blogs.rstudio.com/tensorflow/posts/2019-04-16-autokeras/).
## Dependencies
* [AutoKeras](https://autokeras.com/) requires Python >= 3.5 .
## Installation
Install the current released version of `{autokeras}` from [CRAN](https://cran.r-project.org/package=autokeras):
```{r eval = FALSE}
install.packages("autokeras")
```
Or install the development version from GitHub:
```{r eval = FALSE}
if (!require("remotes")) {
install.packages("remotes")
}
remotes::install_github("r-tensorflow/autokeras")
```
Then, use the `install_autokeras()` function to install TensorFlow:
```{r eval = FALSE}
library("autokeras")
install_autokeras()
```
## Docker
`autokeras` R package has a configured Docker image.
Steps to run it:
From a bash console:
```{bash eval = FALSE}
docker pull jcrodriguez1989/r-autokeras:1.0.0
docker run -it jcrodriguez1989/r-autokeras:1.0.0 /bin/bash
```
To run the docker image, and share the current folder (in home machine) to the `/data` path (in the docker machine), then do:
```{bash eval = FALSE}
docker run -it -v ${PWD}:/data jcrodriguez1989/r-autokeras:1.0.0 /bin/bash
ls /data # once when the docker image is running
```
## Examples
### CIFAR-10 dataset
```{r eval = FALSE}
library("keras")
# Get CIFAR-10 dataset, but not preprocessing needed
cifar10 <- dataset_cifar10()
c(x_train, y_train) %<-% cifar10$train
c(x_test, y_test) %<-% cifar10$test
```
```{r eval = FALSE}
library("autokeras")
# Create an image classifier, and train 10 different models
clf <- model_image_classifier(max_trials = 10) %>%
fit(x_train, y_train)
```
```{r eval = FALSE}
# And use it to evaluate, predict
clf %>% evaluate(x_test, y_test)
```
```{r eval = FALSE}
clf %>% predict(x_test[1:10, , , ])
```
```{r eval = FALSE}
# Get the best trained Keras model, to work with the keras R library
(keras_model <- export_model(clf))
```
### IMDb dataset
```{r eval = FALSE}
library("keras")
# Get IMDb dataset
imdb <- dataset_imdb(num_words = 1000)
c(x_train, y_train) %<-% imdb$train
c(x_test, y_test) %<-% imdb$test
# AutoKeras procceses each text data point as a character vector,
# i.e., x_train[[1]] "<START> this film was just brilliant casting..",
# so we need to transform the dataset.
word_index <- dataset_imdb_word_index()
word_index <- c(
"<PAD>", "<START>", "<UNK>", "<UNUSED>",
names(word_index)[order(unlist(word_index))]
)
x_train <- lapply(x_train, function(x) {
paste(word_index[x + 1], collapse = " ")
})
x_test <- lapply(x_test, function(x) {
paste(word_index[x + 1], collapse = " ")
})
x_train <- matrix(unlist(x_train), ncol = 1)
x_test <- matrix(unlist(x_test), ncol = 1)
y_train <- array(unlist(y_train))
y_test <- array(unlist(y_test))
```
```{r eval = FALSE}
library("autokeras")
# Create a text classifier, and train 10 different models
clf <- model_text_classifier(max_trials = 10) %>%
fit(x_train, y_train)
```
```{r eval = FALSE}
# And use it to evaluate, predict
clf %>% evaluate(x_test, y_test)
```
```{r eval = FALSE}
clf %>% predict(x_test[1:10])
```
```{r eval = FALSE}
# Get the best trained Keras model, to work with the keras R library
export_model(clf)
```