Error with Loading Saved Keras Model in Shiny App

shiny
keras

#1

.. Greeting Everyone,

I am newbie to ML...i have been learning to built model based on Keras in R and integrating with Shiny app. My test project that i am trying to built is to classify images of forms that receive for processing in my organization. CNN model I have built works fine when loading model in R Script for Prediction. However when try to load the model in Shiny app, i am getting an error

Error: argument "filepath" is missing, with no default

Below is the code of shiny app that i am trying built. Please help with understanding what i am doing incorrectly.

Note: I have tried to call model from within server function / outside of the as well. Both produce the same error.

library(shiny)
library(keras)
library(EBImage)
library(reticulate)
#pmodel <- load_model_weights_hdf5("E:\Sriram\shiny\image_classifier.h5")

ui <- fluidPage("Hello World",
fileInput(inputId = "imgfile",label = "Upload Your Image file",accept = c(".jpg",".jpeg")),
imageOutput("Page"),
"Printing Results",
textOutput("result")
)

server <- function(input,output)
{

output$Page <- renderImage({
src <- input$imgfile
src <- src$datapath
list(src = src,
height = "300",
alt = "This is alternate text")
})

output$result <-renderText({
pmodel <- load_model_weights_hdf5("E:\Sriram\shiny\image_classifier.h5")
img<-readImage(input$imgfile)
rimg <- img
rimg<-resize(rimg,100,100)
x <- array_reshape(rimg,c(1,100,100,3))
prob <- pmodel %>%
predict_proba(x)
pred <- pmodel%>%
predict_classes(x)
c<-c('HCFA','UB','Dental','Superbill-HCFA','Superbill-UB','Medicare', 'COB', 'Attach','Blank','EOB','MEOB')
paste("Image uploaded is -> %s Page with accuary of %s %%",c[pred])
})

}

shinyApp(ui = ui, server = server)`library(shiny)

#2

To save and load a full model you use save_model_hdf5()/load_model_hdf5() rather than the weights variation as you have done here.


#3

thanks.It is working now.


#4

Hi there! If your question's been answered, would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: