-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcreateResNetWithSpatialTransformerNetworkModel3D.Rd
More file actions
102 lines (80 loc) · 3.16 KB
/
createResNetWithSpatialTransformerNetworkModel3D.Rd
File metadata and controls
102 lines (80 loc) · 3.16 KB
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in
% R/createResNetWithSpatialTransformerNetworkModel.R
\name{createResNetWithSpatialTransformerNetworkModel3D}
\alias{createResNetWithSpatialTransformerNetworkModel3D}
\title{3-D implementation of the ResNet deep learning architecture with a
preceding spatial transformer network layer.}
\usage{
createResNetWithSpatialTransformerNetworkModel3D(
inputImageSize,
numberOfOutputs = 1000,
layers = 1:4,
residualBlockSchedule = c(3, 4, 6, 3),
lowestResolution = 64,
cardinality = 1,
resampledSize = c(64, 64, 64),
numberOfSpatialTransformerUnits = 50,
mode = c("classification", "regression")
)
}
\arguments{
\item{inputImageSize}{Used for specifying the input tensor shape. The
shape (or dimension) of that tensor is the image dimensions followed by
the number of channels (e.g., red, green, and blue). The batch size
(i.e., number of training images) is not specified a priori.}
\item{numberOfOutputs}{Number of segmentation labels.}
\item{layers}{a vector determining the number of 'filters' defined at
for each layer.}
\item{residualBlockSchedule}{vector defining the how many residual blocks
repeats.}
\item{lowestResolution}{number of filters at the initial layer.}
\item{cardinality}{perform ResNet (cardinality = 1) or ResNeXt
(cardinality != 1 but powers of 2---try '32' )}
\item{resampledSize}{output image size of the spatial transformer network.}
\item{numberOfSpatialTransformerUnits}{number of units in the dense layer.}
\item{mode}{'classification' or 'regression'. Default = 'classification'.}
}
\value{
an ResNet keras model
}
\description{
Creates a keras model of the ResNet deep learning architecture for image
classification with a spatial transformer network (STN) layer. The paper
is available here:
}
\details{
\if{html}{\out{<div class="sourceCode">}}\preformatted{ https://arxiv.org/abs/1512.03385
}\if{html}{\out{</div>}}
}
\examples{
\dontrun{
library( ANTsRNet )
library( keras )
mnistData <- dataset_mnist()
numberOfLabels <- 10
# Extract a small subset for something that can run quickly
X_trainSmall <- mnistData$train$x[1:10,,]
X_trainSmall <- array( data = X_trainSmall, dim = c( dim( X_trainSmall ), 1 ) )
Y_trainSmall <- to_categorical( mnistData$train$y[1:10], numberOfLabels )
X_testSmall <- mnistData$test$x[1:10,,]
X_testSmall <- array( data = X_testSmall, dim = c( dim( X_testSmall ), 1 ) )
Y_testSmall <- to_categorical( mnistData$test$y[1:10], numberOfLabels )
# We add a dimension of 1 to specify the channel size
inputImageSize <- c( dim( X_trainSmall )[2:3], 1 )
model <- createResNetWithSpatialTransformerNetworkModel2D(
inputImageSize = inputImageSize,
numberOfOutputs = numberOfLabels )
model \%>\% compile( loss = 'categorical_crossentropy',
optimizer = optimizer_adam( lr = 0.0001 ),
metrics = c( 'categorical_crossentropy', 'accuracy' ) )
track <- model \%>\% fit( X_trainSmall, Y_trainSmall, verbose = 1,
epochs = 1, batch_size = 2, shuffle = TRUE, validation_split = 0.5 )
# Now test the model
testingMetrics <- model \%>\% evaluate( X_testSmall, Y_testSmall )
predictedData <- model \%>\% predict( X_testSmall, verbose = 1 )
}
}
\author{
Tustison NJ
}