-
Notifications
You must be signed in to change notification settings - Fork 76
/
classify_deeplearning.R
62 lines (51 loc) · 1.39 KB
/
classify_deeplearning.R
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
library(sits)
# load the sitsdata library
if (!requireNamespace("sitsdata", quietly = TRUE)) {
stop("Please install package sitsdata\n",
"Please call devtools::install_github('e-sensing/sitsdata')",
call. = FALSE
)
}
# load the sitsdata library
library(sitsdata)
# load a time series samples for the Mato Grosso region
data("samples_matogrosso_mod13q1")
samples_ndvi_evi <- sits_select(
data = samples_matogrosso_mod13q1,
bands = c("NDVI", "EVI")
)
# train a deep learning model using multi-layer perceptrons
dl_model <- sits_train(
samples = samples_ndvi_evi,
ml_method = sits_tempcnn()
)
# create a data cube to be classified
# Cube MOD13Q1 images from the Sinop region in Mato Grosso (Brazil)
data_dir <- system.file("extdata/sinop", package = "sitsdata")
sinop <- sits_cube(
source = "BDC",
collection = "MOD13Q1-6",
data_dir = data_dir
)
# classify the raster image
sinop_probs <- sits_classify(
data = sinop,
ml_model = dl_model,
memsize = 12,
multicores = 2,
output_dir = tempdir()
)
# smoothen with bayesian filter
sinop_bayes <- sits_smooth(
cube = sinop_probs,
output_dir = tempdir()
)
# label the classified image
sinop_label <- sits_label_classification(
cube = sinop_bayes,
output_dir = tempdir()
)
# plot the smoothed image
plot(sinop_bayes)
# plot the classified image
plot(sinop_label)