nnlayer_conv: Construct a convolution layer.

Description Usage Arguments See Also Examples

View source: R/nnlayer_conv.R

Description

Construct a convolution layer.

Usage

1
2
nnlayer_conv(layer, kernelshape, inputshape, name, inputname, stride, lowerpad,
  sharing, mapcount = 1, activation = c("rlinear"), ...)

Arguments

layer

A layer object, e.g. using nnlayer_input, or NULL

kernelshape

Numeric vector describing the number of inputs in each dimension, e.g. c(3, 15, 15)

inputshape

Numeric vector describing the number of inputs in each dimension, e.g. c(3, 15, 15). If layer is specified, this can be NULL.

name

Name of the layer

inputname

Name of the preceding layer. If layer is specified, this can be NULL.

stride

Numeric vector describing the number of inputs in each dimension, e.g. c(3, 15, 15).

lowerpad

Numeric vector describing the number of inputs in each dimension, e.g. c(3, 15, 15).

sharing

Logical vector.

mapcount

Number of maps to create.

activation

Activation function, e.g. rlinear

...

Other arguments passed from nnlayer_pool and nnlayer_norm

See Also

Other layer.definition.functions: nnlayer_full, nnlayer_input, nnlayer_norm, nnlayer_output, nnlayer_pool

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
 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
# Use the layer functions to generate individual layer specifications

nnlayer_input(c(13, 13))
nnlayer_input(c(3, 7, 7), name = "pixels")

# Convolution layers automatically compute the output size and padding

nnlayer_conv(NULL, c(2, 2), 
           inputshape = c(13, 13), 
           name = "conv1", 
           inputname = "pixels"
)

nnlayer_conv(NULL, 
           c(2, 2), 
           inputshape = c(13, 13), 
           name = "conv1", 
           inputname = "pixels", 
           stride = c(2, 2)
)

nnlayer_conv(NULL, 
           c(1, 2, 2), 
           inputshape = c(3, 13, 13), 
           name = "conv1", 
           inputname = "pixels", 
           stride = c(1, 2, 2)
)

nnlayer_pool(NULL, 
           c(1, 2, 2), 
           inputshape = c(3, 13, 13), 
           name = "conv1", 
           inputname = "pixels", 
           stride = c(1, 2, 2)
)



# Specify the number of nodes in a fully connected layer

nnlayer_full(NULL, nodes = 100, name = "h3", inputname = "conv")

# Output layer

nnlayer_output(NULL, 6, name = "class", inputname = "h3")


# using magrittr pipes to connect layers ----------------------------------

require(magrittr)

nnlayer_input(c(3, 50, 50), name = "pixels") %>% 
  nnlayer_conv(
    kernelshape = c(1, 5, 5),
    name = "conv1", 
    stride = c(1, 2, 3)
  )

nnlayer_input(c(3, 50, 50), name = "pixels") %>% 
  nnlayer_conv(
    kernelshape = c(1, 5, 5),
    name = "conv1", 
    stride = c(1, 2, 3)
  ) %>% 
  nnlayer_pool(
    kernelshape = c(1, 5, 5),
    name = "conv1", 
    stride = c(1, 2, 3)
  )

nnlayer_norm(NULL, inputshape = c(3, 11, 5), kernelshape = c(1,5,5), name = "rnorm1", inputname = "conv")

nnlayer_input(c(3, 50, 50), name = "pixels") %>% 
  nnlayer_conv(
    kernelshape = c(1, 5, 5),
    name = "conv1", 
    stride = c(1, 2, 3)
  ) %>% 
  nnlayer_norm(
    kernelshape = c(1, 5, 5),
    name = "norm1", 
    stride = c(1, 2, 3),
    alpha = 0.0001,
    beta = 0.75
  )


nnlayer_input(c(3, 50, 50), name = "pixels") %>% 
  nnlayer_conv(
    kernelshape = c(3, 5, 5), 
    name = "conv1", 
    stride = c(1, 2, 2),
    mapcount = 48
  ) %>% 
  nnlayer_conv(
    kernelshape = c(1, 4, 4), 
    stride = c(1, 2, 2),
    name = "conv2"
  ) %>% 
  nnlayer_full(nodes = 100, name = "hid1") %>% 
  nnlayer_full(nodes = 30, name = "hid2") %>% 
  nnlayer_output(nodes = 6, name = "class")

andrie/mxNeuralNetExtra documentation built on June 3, 2017, 7:02 p.m.