我正在研究Kaggle语义分段任务,
在我的代码的测试部分,
library(shiny)
library(ggplot2)
library(dplyr)
library(tidyverse)
## Only run examples in interactive R sessions
if (interactive()) {
ui <- fluidPage(
# App title ----
titlePanel("Uploading Files"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Select a file ----
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
# Horizontal line ----
tags$hr(),
# Input: Checkbox if file has header ----
checkboxInput("header", "Header", TRUE),
# Input: Select separator ----
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
# Input: Select quotes ----
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"'),
# Horizontal line ----
tags$hr(),
# Input: Select number of rows to display ----
radioButtons("disp", "Display",
choices = c(Head = "head",
All = "all"),
selected = "head"),
# Include a Slider for Strata
sliderInput("strata",
"strata:",
min = 1,
max = 20,
value = c(1,20),
step=1)
),
##########################
# Main panel for displaying outputs ----
mainPanel(
# Output: Data file ----
tableOutput("contents")
)
)
)
###
server <- function(input, output, session) {
mytable <- reactive({
req(input$file1)
df <- read.csv(input$file1$datapath,
header = input$header,
sep = input$sep,
quote = input$quote, stringsAsFactors = FALSE)
print(df)
df<-data.frame(df)
df<- df %>%
filter(df$strata>=input$strata[1] & df$strata<=input$strata[2])
print(df)
if(input$disp == "head") {
return(head(df))
}
else {
return(df)
}
})
output$contents <- renderTable({
# Now do use (), since we are calling a value from a reactive.
mytable()
})
}
# Run the app ----
shinyApp(ui, server)
}
当我做preds部分时,数组只是填充,我希望它是一个最大位置的数组我不知道出了什么问题。
model = model.eval()
predictions =[]
for data in testdataloader:
data = t.autograd.Variable(data, volatile=True).cuda()
output = model.forward(data)
_,preds = t.max(output, 1, keepdim = True)
部分效果很好,我附上了output
对出现问题的任何消息都会非常有帮助。
感谢
答案 0 :(得分:0)
假设您的数据格式为MiniBatch x Dim
,您现在正在查看哪个小批量具有最高价值。如果您使用单个样本(MB = 1
)对其进行测试,那么您将始终获得0
作为答案。因此,您可能想尝试:
_,preds = t.max(output, 0, keepdim = False)