作者celestialgod (天)
看板R_Language
标题Re: [问题] R 记忆体用量
时间Sat Mar 25 01:56:13 2017
※ 引述《f496328mm (123)》之铭言:
: 文章分类提示:
: - 问题: 当你想要问问题时,请使用这个类别。
: 建议先利用 google 爬文,如输入
: 「想查询的关键字 site:webptt.com/cn.aspx?n=/*/R_Language/」。
: [问题类型]:
: 程式谘询(我想用R 做某件事情,但是我不知道要怎麽用R 写出来)
: [软体熟悉度]:
: 入门(写过其他程式,只是对语法不熟悉)
: [问题叙述]:
: http://imgur.com/4UN3EJk
: 如图
: 我跑的物件总共也才不到6gb
: 可是看系统监控 却已经有17.6gb在背景了
: 到底是为什麽阿?? 而且我也执行过gc()了
: 我原本打算转换所有的data , 目前因为ram的关系
: 只能转1/4部份 有点麻烦 有什麽办法可以解决?
: 另外
: 如果我改到 python 去做转换 会比较省ram吗?
: 谢谢
: ps: 我是把图片转换成 pixel
: 这是function
: https://gist.github.com/f496328mm/a342cb39e8ae3b84f01be29a46bb81da
: 这是main
: https://gist.github.com/f496328mm/44116adf79356f01e761cfe72627d213
有些地方没看懂你要干嘛,不过稍微改一下应该就好
我的话应该这样写就差不多转完:
library(jpeg)
library(pipeR)
library(data.table)
trainJpgFiles <- list.files("train", "\\.jpg", full.names = TRUE)
testJpgFiles <- list.files("test", "\\.jpg", full.names = TRUE)
outputSize <- c(224L, 224L, 3)
inputSize <- dim(readJPEG(trainJpgFiles[1]))
idxDT <- mapply(function(i, j) sort(sample.int(i, j)),
inputSize[1L:2L], outputSize[1L:2L], SIMPLIFY = FALSE) %>>%
(CJ(x = .[[1]], y = .[[2]], z = 1L:3L)) %>>%
`[`(j = idx := x + (y-1L) * inputSize[1L] +
(z-1L) * prod(inputSize[1L:2L])) %>>%
setorder(z, y, x)
readJpgFunc <- function(jpgList, i){
tmp <- lapply(jpgList, function(jpg) readJPEG(jpg)[idxDT$idx]) %>>%
do.call(what = cbind) %>>% data.table %>>% `[`(j = names(idxDT) := idxDT)
fwrite(tmp, file = sprintf("fold_jpg_%s.csv", i))
return(NULL)
}
batchSize <- 5000L
trainJpgFiles %>>%
split(rep(1L:ceiling(length(.) / batchSize), length = length(.))) %>>%
(mapply(readJpgFunc, ., seq_along(.)))
testJpgFiles %>>%
split(rep(1L:ceiling(length(.) / batchSize), length = length(.))) %>>%
(mapply(readJpgFunc, ., seq_along(.)))
--
R资料整理套件系列文:
magrittr #1LhSWhpH (R_Language) https://goo.gl/72l1m9
data.table #1LhW7Tvj (R_Language) https://goo.gl/PZa6Ue
dplyr(上.下) #1LhpJCfB,#1Lhw8b-s (R_Language) https://goo.gl/I5xX9b
tidyr #1Liqls1R (R_Language) https://goo.gl/i7yzAz
pipeR #1NXESRm5 (R_Language) https://goo.gl/zRUISx
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 118.170.36.92
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1490378177.A.200.html
※ 编辑: celestialgod (118.170.36.92), 03/25/2017 01:58:50
1F:推 f496328mm: thank you 晚点研究看看 03/25 02:16