Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 正在将CIFAR-10数据集导入到R_Python_R_Image Processing - Fatal编程技术网

Python 正在将CIFAR-10数据集导入到R

Python 正在将CIFAR-10数据集导入到R,python,r,image-processing,Python,R,Image Processing,我正在尝试下载CIFAR-10图像数据集; 在R中,但我似乎无法提取文件。我已经尝试了所有三种格式。bin、.mat和python。有人能帮我提出一些建议,如何提取它们吗 非常感谢,威尔和其他任何事情一样,我认为最简单的方法通常是依靠别人的努力。在这种情况下,这意味着寻找其他人谁已经转换它。一个快速的谷歌搜索(其中包含一个R数据文件的图像)呈现了一个伟大的候选人的方法 或者,如果您想直接使用CIFAR-10数据,我刚刚创建了一个脚本,用于从Alex链接到的二进制文件中读取数据: #读取二进制文件

我正在尝试下载CIFAR-10图像数据集; 在R中,但我似乎无法提取文件。我已经尝试了所有三种格式。bin、.mat和python。有人能帮我提出一些建议,如何提取它们吗


非常感谢,威尔

和其他任何事情一样,我认为最简单的方法通常是依靠别人的努力。在这种情况下,这意味着寻找其他人谁已经转换它。一个快速的谷歌搜索(其中包含一个R数据文件的图像)呈现了一个伟大的候选人的方法

或者,如果您想直接使用CIFAR-10数据,我刚刚创建了一个脚本,用于从Alex链接到的二进制文件中读取数据:

#读取二进制文件并转换为整数向量
#[必要,因为直接读取为整数()
#将第一位读取为带符号的]
#
#文件格式为10000条记录,模式如下:
#[标签x1][红色x1024][绿色x1024][蓝色x1024]
#未拆分为行,因此需要注意“大小”和“n”
#
#(见http://www.cs.toronto.edu/~kriz/cifar.html)

标签它似乎没有显示R支持的任何数据格式。您是否尝试过使用python接口(如Rpy2)通过R读取python数据格式?我尝试过python接口,但我以前从未使用过该语言,因此我没有在这方面取得很大进展。我尝试使用为python提供的示例代码,但无法实现。
# Read binary file and convert to integer vectors
# [Necessary because reading directly as integer() 
# reads first bit as signed otherwise]
#
# File format is 10000 records following the pattern:
# [label x 1][red x 1024][green x 1024][blue x 1024]
# NOT broken into rows, so need to be careful with "size" and "n"
#
# (See http://www.cs.toronto.edu/~kriz/cifar.html)
labels <- read.table("cifar-10-batches-bin/batches.meta.txt")
images.rgb <- list()
images.lab <- list()
num.images = 10000 # Set to 10000 to retrieve all images per file to memory

# Cycle through all 5 binary files
for (f in 1:5) {
  to.read <- file(paste("cifar-10-batches-bin/data_batch_", f, ".bin", sep=""), "rb")
  for(i in 1:num.images) {
    l <- readBin(to.read, integer(), size=1, n=1, endian="big")
    r <- as.integer(readBin(to.read, raw(), size=1, n=1024, endian="big"))
    g <- as.integer(readBin(to.read, raw(), size=1, n=1024, endian="big"))
    b <- as.integer(readBin(to.read, raw(), size=1, n=1024, endian="big"))
    index <- num.images * (f-1) + i
    images.rgb[[index]] = data.frame(r, g, b)
    images.lab[[index]] = l+1
  }
  close(to.read)
  remove(l,r,g,b,f,i,index, to.read)
}

# function to run sanity check on photos & labels import
drawImage <- function(index) {
  # Testing the parsing: Convert each color layer into a matrix,
  # combine into an rgb object, and display as a plot
  img <- images.rgb[[index]]
  img.r.mat <- matrix(img$r, ncol=32, byrow = TRUE)
  img.g.mat <- matrix(img$g, ncol=32, byrow = TRUE)
  img.b.mat <- matrix(img$b, ncol=32, byrow = TRUE)
  img.col.mat <- rgb(img.r.mat, img.g.mat, img.b.mat, maxColorValue = 255)
  dim(img.col.mat) <- dim(img.r.mat)

  # Plot and output label
  library(grid)
  grid.raster(img.col.mat, interpolate=FALSE)

  # clean up
  remove(img, img.r.mat, img.g.mat, img.b.mat, img.col.mat)

  labels[[1]][images.lab[[index]]]
}

drawImage(sample(1:(num.images*5), size=1))