この光沢のあるアプリは、次のものから構築されています。here 基本的にR光沢のテンソルフローのPythonを使用しています。私の主な質問は、Rで実行するPyコードを取得している。Tensorflow classify_image
編集:私はいくつかの変更を加えることによって実行することができました。すべてが実行されます。しかし、単語クラウドはありません。また、光沢を帯びた出力を得ることもできません。イメージをアップロードすると、出力はRstudioのコンソールに表示されます。
library(wordcloud)
shinyServer(function(input, output) {
PYTHONPATH <- "C:/Program Files/Anaconda3" #should look like /Users/yourname/anaconda/bin if you use anaconda python distribution in OS X
CLASSIFYIMAGEPATH <- "C:/Program Files/Anaconda3/Lib/site-packages/tensorflow/models/image/imagenet" #should look like ~/anaconda/lib/python2.7/site-packages/tensorflow/models/image/imagenet
outputtext <- reactive({
###This is to compose image recognition template###
inFile <- input$file1 #This creates input button that enables image upload
template <- paste0("python"," ", "classify_image.py") #Template to run image recognition using Python
if (is.null(inFile))
{system(paste0(template," --image_file /tmp/imagenet/cropped_panda.jpg"))} else { #Initially the app classifies cropped_panda.jpg, if you download the model data to a different directory, you should change /tmp/imagenet to the location you use.
system(paste0(template," --image_file ",inFile$datapath)) #Uploaded image will be used for classification
}
})
output$answer <- renderPrint({outputtext()})
output$plot <- renderPlot({
###This is to create wordcloud based on image recognition results###
df <- data.frame(gsub(" *\\(.*?\\) *", "", outputtext()),gsub("[^0-9.]", "", outputtext())) #Make a dataframe using detected objects and scores
names(df) <- c("Object","Score") #Set column names
df$Object <- as.character(df$Object) #Convert df$Object to character
df$Score <- as.numeric(as.character(df$Score)) #Convert df$Score to numeric
s <- strsplit(as.character(df$Object), ',') #Split rows by comma to separate rows
df <- data.frame(Object=unlist(s), Score=rep(df$Score, sapply(s, FUN=length))) #Allocate scores to split words
# By separating long categories into shorter terms, we can avoid "could not be fit on page. It will not be plotted" warning as much as possible
wordcloud(df$Object, df$Score, scale=c(4,2),
colors=brewer.pal(6, "RdBu"),random.order=F) #Make wordcloud
})
output$outputImage <- renderImage({
###This is to plot uploaded image###
if (is.null(input$file1)){
outfile <- "/tmp/imagenet/cropped_panda.jpg"
contentType <- "image/jpg"
#Panda image is the default
}else{
outfile <- input$file1$datapath
contentType <- input$file1$type
#Uploaded file otherwise
}
list(src = outfile,
contentType=contentType,
width=300)
}, deleteFile = TRUE)
})
Rstudioのコンソール上の出力の例:
pug, pug-dog (score = 0.89841) bull mastiff (score = 0.01825) Brabancon griffon (score = 0.01114) French bulldog (score = 0.00161) Pekinese, Pekingese, Peke (score = 0.00091) W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_def_util.cc:332] Op BatchNormWithGlobalNormalization is deprecated. It will cease to work in GraphDef version 9. Use tf.nn.batch_normalization().
は、誰もが何が起こっているか知っていますか?
- 私はさまざまな方法を試してみましたが、私は印刷出力(使用renderPrint、rendertext ...等)、ここでOK
Windows上にいますか? –
はい私は悲しいことです:/ – Germ