Я пытаюсь создать модель глубокого обучения для классификации изображения на основе 5 переменных (R, G, B, NIR, NDVI). Учебные образцы находятся в точечном шейп-файле со всеми 6 переменными, включая столбец класса. Я использую библиотеку Keras в R для создания модели.
library(keras)
install_keras()
library(tensorflow)
install_tensorflow(gpu=T)
library(magrittr)
library("tidyverse")
library(reticulate)
#Training samples
trainingSamples <- readOGR("Q:/2.0.Projects/Fiber/Satellite/Field Validation/Cerato training samples/Training samples/AllSamples.shp")
data.df <- as.data.frame(trainingSamples)
train.df <- data.df[c(3:7,12)] #3-7 variables are R,G,B,NIR and NDVI and 12th variable is corresponding class.
#converting class variable into numeric (Classes are in characters)
train.df$Class <- as.numeric(train.df$Class)
нормализация данных
for (i in 1:5) {
train.df[,i] <- (train.df[,i]-min(train.df[,i]))/(max(train.df[,i])-min(train.df[,i]))
}
Разделение данных - определение размера выборки
ind <- sample(2, nrow(train.df), replace=TRUE, prob=c(0.80, 0.20))
training <- train.df[ind==1, 1:5]
test <- train.df[ind==2, 1:5]
# Split the class attribute
traintarget <- train.df[ind==1, 6]
testtarget <- train.df[ind==2, 6]
одна горячая кодировка
trainlabels <- to_categorical(traintarget)
testlabels <- to_categorical(testtarget)
создание модели
model <- keras_model_sequential()
model %>%
layer_dense(units=5, activation = 'relu', input_shape = c(5)) %>%
layer_dense(units=1, activation = 'softmax')
summary(model)
#Compiling the model to configure the learning process
model %>%
compile(loss = 'categorical_crossentropy',
optimizer = 'adam',
metrics = 'accuracy')
#Fit model
mymodel <- model %>%
fit(training,
trainlabels,
epoch=100,
batch_size=32,
validation_split=0.2)
Ошибка
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘fit’ for signature ‘"keras.engine.sequential.Sequential", "matrix"’
Я попытался преобразовать фрейм данных в матрицу, а затем применить dimnames как NULL, все еще получая ту же ошибку , Любая помощь будет оценена.