WindowsとRとMXNetでSRGAN(GPUなし)

2018年8月1日動作確認

環境

Windows10 Pro 64bit
R-3.5.1

はじめに

「Super-Resolution-Zoo」として各種学習済みモデルが公開されている。
github.com
今回はその中の「Super-Resolution-Zoo/SRGAN/SRGAN@leftthomas」内の「SRGAN_2x」を使わせて頂く。

MXNetのインストール

  • 公式サイト通りに行う
cran <- getOption("repos")
cran["dmlc"] <- "https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/R/CRAN/"
options(repos = cran)
install.packages("mxnet")

サンプル画像を用意する

今回は下記画像を使用(sample.jpg)
f:id:touch-sp:20180801114518j:plain

実行ファイルを作成

  • 「SRGAN.R」の名前で保存
#ライブラリの読み込み
library(mxnet)
library(jpeg)

args <- commandArgs(TRUE)
input_file_name <- args[1]

#学習済みモデルの読み込み
srgan <- mx.model.load("SRGAN_2x",0)

#サンプル画像の読み込み
img <- readJPEG(input_file_name)

#実行
height <- dim(img)[1]
width <- dim(img)[2]
test <- array(0,c(height,width,3,1))
test[,,,1] <- img
out <- predict(srgan,test,ctx=mx.cpu())

#結果の出力
writeJPEG(out[,,,1],"out.jpg",quality=1)

コマンドプロンプトから実行

Rscript SRGAN.R sample.jpg

結果

f:id:touch-sp:20180801115359j:plain

2018年10月15日追記

Pythonで使用する場合を追加
touch-sp.hatenablog.com