model_image_classifier: AutoKeras Image Classifier Model

Description Usage Arguments Details Value Examples

View source: R/model_image_classifier.R

Description

AutoKeras image classification class.
It is used for image classification. It searches convolutional neural network architectures for the best configuration for the image dataset. To 'fit', 'evaluate' or 'predict', format inputs as:

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
model_image_classifier(
  num_classes = NULL,
  multi_label = FALSE,
  loss = NULL,
  metrics = list("accuracy"),
  name = "image_classifier",
  max_trials = 100,
  directory = tempdir(),
  objective = "val_loss",
  overwrite = TRUE,
  seed = runif(1, 0, 1e+07)
)

Arguments

num_classes

: numeric. Defaults to 'NULL'. If 'NULL', it will infer from the data.

multi_label

: logical. Defaults to 'FALSE'.

loss

: A Keras loss function. Defaults to use 'binary_crossentropy' or 'categorical_crossentropy' based on the number of classes.

metrics

: A list of Keras metrics. Defaults to use 'accuracy'.

name

: character. The name of the AutoModel. Defaults to "image_classifier".

max_trials

: numeric. The maximum number of different Keras Models to try. The search may finish before reaching the 'max_trials'. Defaults to '100'.

directory

: character. The path to a directory for storing the search outputs. Defaults to 'tempdir()', which would create a folder with the name of the AutoModel in the current directory.

objective

: character. Name of model metric to minimize or maximize, e.g. "val_accuracy". Defaults to "val_loss".

overwrite

: logical. Defaults to 'TRUE'. If 'FALSE', reloads an existing project of the same name if one is found. Otherwise, overwrites the project.

seed

: numeric. Random seed. Defaults to 'runif(1, 0, 10e6)'.

Details

Important: The object returned by this function behaves like an R6 object, i.e., within function calls with this object as parameter, it is most likely that the object will be modified. Therefore it is not necessary to assign the result of the functions to the same object.

Value

A non-trained image classifier AutokerasModel.

Examples

 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
## Not run: 
library("keras")

# use the MNIST dataset as an example
mnist <- dataset_mnist()
c(x_train, y_train) %<-% mnist$train
c(x_test, y_test) %<-% mnist$test

library("autokeras")

# Initialize the image classifier
clf <- model_image_classifier(max_trials = 10) %>% # It tries 10 different models
  fit(x_train, y_train) # Feed the image classifier with training data

# If you want to use own valitadion data do:
clf <- model_image_classifier(max_trials = 10) %>%
  fit(
    x_train,
    y_train,
    validation_data = list(x_test, y_test)
  )

# Predict with the best model
(predicted_y <- clf %>% predict(x_test))

# Evaluate the best model with testing data
clf %>% evaluate(x_test, y_test)

# Get the best trained Keras model, to work with the keras R library
export_model(clf)

## End(Not run)

autokeras documentation built on Jan. 17, 2021, 9:06 a.m.