2021年1月1日記事を更新しました
はじめに
こちらを利用させて頂いた
github.com
今回はGPUあり/なしの二つの環境で動作確認しています。
環境
インストールが必要なのは「mxnet」と「pillow」のみです。
- GPUあり
Windows10 Pro NVIDIA GeForce GTX1080 CUDA 10.1 Python 3.7.9
pip install mxnet-cu101==1.7.0 -f https://dist.mxnet.io/python/cu101 pip install pillow
certifi==2020.12.5 chardet==3.0.4 graphviz==0.8.4 idna==2.6 mxnet-cu101==1.7.0 numpy==1.16.6 Pillow==8.0.1 requests==2.18.4 urllib3==1.2
- GPUなし
Windows10 Pro Python 3.8.7
pip install mxnet pip install pillow
certifi==2020.12.5 chardet==3.0.4 graphviz==0.8.4 idna==2.6 mxnet==1.7.0.post1 numpy==1.16.6 Pillow==8.0.1 requests==2.18.4 urllib3==1.22
実行スクリプト
import mxnet as mx from mxnet import image, gluon ctx = mx.gpu() if mx.context.num_gpus() >0 else mx.cpu() gluon.utils.download('https://s3.amazonaws.com/onnx-mxnet/examples/super_res_input.jpg') img = image.imread('super_res_input.jpg').astype('float32')/255 img = mx.nd.transpose(img, (2,0,1)) gluon.utils.download('https://raw.githubusercontent.com/WolframRhodium/Super-Resolution-Zoo/master/ARAN/aran_c0_s1_x4-symbol.json') gluon.utils.download('https://raw.githubusercontent.com/WolframRhodium/Super-Resolution-Zoo/master/ARAN/aran_c0_s1_x4-0000.params') net = gluon.SymbolBlock.imports("aran_c0_s1_x4-symbol.json",['data'], "aran_c0_s1_x4-0000.params") net.collect_params().reset_ctx(ctx) output = net(img.expand_dims(0).as_in_context(ctx)) output = mx.nd.squeeze(output) output = (mx.nd.transpose(output, (1,2,0))*255).astype('uint8') from PIL import Image img = Image.fromarray(output.asnumpy()) img.save('ARAN_4x.jpg')
警告
以下の警告が出るが結果には影響しない
UserWarning: Cannot decide type for the following arguments. Consider providing them as input: data: None input_sym_arg_type = in_param.infer_type()[0]