-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
96 lines (64 loc) · 1.78 KB
/
app.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
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
library(shiny)
library(shinythemes)
library(keras)
ui <- fluidPage(
theme = shinytheme("yeti"),
titlePanel("Hotdog? Not Hotdog?", windowTitle = "Hotdog"),
br(),
tags$p("Sometimes you just can't tell if your hot dog is the real deal.
It happens to the best of us.
You sit down to enjoy your delicious hot dog but suspect it's really a
hot dog in disguise."),
tags$p("Let those worries rest because now you can be certain of your hot dogs'
authenticity."),
tags$p("Try it now! Just upload an image and find out if it's the real McCoy!"),
sidebarLayout(
sidebarPanel(
fileInput(
"imageinput",
"Choose an image to upload",
accept = c('image/png', 'image/jpeg')
),
actionButton(
"gobutton",
"Go!"
)
),
mainPanel(
htmlOutput("textresult")
)
)
)
server <- function(input, output){
model <- load_model_hdf5("2019-04-26-vgg16-fine-tune.h5")
make_pred <- eventReactive(
input$gobutton,
{
req(input$imageinput)
img <- image_load(input$imageinput$datapath, target_size = c(150, 150))
img_array <- image_to_array(img)
img_array <- array_reshape(img_array, c(1, 150, 150, 3))
img_array <- img_array / 255
# 0 is hot dog, 1 is not hot dog
pred <- predict_classes(model, img_array)
pred[1, 1]
}
)
output$textresult <- renderText({
pred_numeric <- make_pred()
if (pred_numeric){
paste0(
"<h1 style=\"font-size:60px;\"><span style=\"color:red\">",
"Not Hotdog!",
"</span></h1>"
)
} else {
paste0(
"<h1 style=\"font-size:60px;\"><span style=\"color:green\">",
"Hotdog!",
"</span></h1>"
)
}
})
}
shiny::shinyApp(ui = ui, server = server)