hi everyone

can anybody help me ??

I used this code before, it predicted the photos with a good approximation. But now it encounters an error. (Since I updated)

Can anyone tell me the correct coding?

I think the problem is in the last part of the coding

test <- lapply(mytest,readImage)

setwd("C:/Users/90553/Desktop/paste0")

train[[1]]

plot(test[[4]])

par(mfrow=c(7,3))

foreach(i=1:21) %do% {plot(train[[i]])}

par(mfrow=c(1,1))

foreach(i = 1:21) %do% {train[[i]] <-resize(train[[i]],150,150)}

foreach(i = 1:9) %do% {test[[i]] <-resize(train[[i]],150,150)}

str(test)

trainall <- combine(train)

testall <- combine(test)

display(tile(trainall,7))

str(trainall)

trainall <- aperm(trainall,c(4,1,2,3))

testall <- aperm(testall,c(4,1,2,3))

trainlabels <- rep(0:2, each=7)

testlabels <- rep(0:2 , each=3)

trainy <- to_categorical(trainlabels)

testy <- to_categorical(testlabels)

model <- keras_model_sequential()

model %>%

layer_conv_2d(filters = 256,

kernel_size=c(3,3),

activation = "relu",

input_shape = c(150,150,3))%>%

layer_max_pooling_2d(pool_size =c(3,3), strides = 2)%>%

layer_conv_2d(filters = 128,

kernel_size=c(5,5),

activation = "relu")%>%

layer_max_pooling_2d(pool_size = c(2,2), strides = 2)%>%

layer_conv_2d(filters = 32,

kernel_size=c(3,3),

activation = "relu")%>%

layer_max_pooling_2d(pool_size = c(2,2), strides = 2)%>%

layer_flatten()%>%

layer_dense(units = 256)%>% layer_activation_leaky_relu(alpha = 0.1)%>%

layer_dropout(rate = 0.4)%>%

layer_dense(units = 3, activation = "softmax")

summary(model)

model %>% compile(loss = "categorical_crossentropy",

optimizer = "rmsprop",

metrics = "accuracy")

model %>% compile(loss = "categorical_crossentropy",

optimizer = "rmsprop",

metrics = "accuracy")

history <- model %>%

fit(trainall,trainy, epoch=50,batch_size=32, validation_split=0.2)

save_model_hdf5(model, "model.cnn.h5")

model <- load_model_hdf5("model.cnn.h5")

train_evaluate <- evaluate(model, trainall, trainy)

test_evaluate <- evaluate(model, testall, testy)

model %>% predict(testall) %>% k_argmax()

pred <- testy

model %>% predict(testall) %>% k_argmax()

pred <- predict(testall)

pred[pred==0] <- "cat"

pred[pred==1] <- "dog"

pred[pred==2] <- "lion"

par(mfrow=c(3,3))

foreach(i=1:9) %do%{display(test[[i]], method = "raster");

text(x=20, y=20,label= pred[i],

adj = c(0,1),col = "black", cex = 4)}

par(mfrow=c(1,1))