Re: [問題] R 記憶體用量

看板R_Language作者 (天)時間8年前 (2017/03/25 01:56), 8年前編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《f496328mm (123)》之銘言: : 文章分類提示: : - 問題: 當你想要問問題時,請使用這個類別。 : 建議先利用 google 爬文,如輸入 : 「想查詢的關鍵字 site:www.ptt.cc/*/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://www.ptt.cc/bbs/R_Language/M.1490378177.A.200.html ※ 編輯: celestialgod (118.170.36.92), 03/25/2017 01:58:50

03/25 02:16, , 1F
thank you 晚點研究看看
03/25 02:16, 1F
文章代碼(AID): #1OrLt180 (R_Language)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1OrLt180 (R_Language)