12
$\begingroup$

ONNX is a open format to represent deep learning models.

So I want to import neural networks from other frameworks via ONNX.

import workflow

And the Mathematica 11.3 supports python now.

I think I can use ONNX-MXNet to export the mxnet.json and mxnet.params then just Import these.

But I have no idea about how to install packages on Python-ExternalSessions.


Example

Here is an onnx-format file of Super Resolution Model.

How can I import this using Mathematica and Python-ExternalSessions?

$\endgroup$
3
  • 1
    $\begingroup$ According to this live CEOing video, it looks like it's in the works. youtube.com/watch?v=l_KzSb9GGbE $\endgroup$ Commented Apr 30, 2018 at 14:19
  • $\begingroup$ According to this article, it will be possible in Mathematica 12. $\endgroup$ Commented Aug 17, 2018 at 1:48
  • $\begingroup$ ONNX is a supported format since v12.1 $\endgroup$ Commented Nov 23 at 21:19

1 Answer 1

7
$\begingroup$

This is incomplete answer because Mathematica doesn't support the latest version of mxnet.

Step 1

Install onnx-mxnet. Open Command Prompt and enter:

pip install onnx-mxnet 

enter image description here

Step 2

Download model and image. Run this code in Mathematica:

enter image description here

import mxnet as mx import onnx_mxnet import numpy as np sym, params = onnx_mxnet.import_model('C:/Users/Alexey/Documents/super_resolution.onnx') from PIL import Image img = Image.open('C:/Users/Alexey/Documents/super_res_input.jpg').resize((224, 224)) img_ycbcr = img.convert("YCbCr") img_y, img_cb, img_cr = img_ycbcr.split() test_image = np.array(img_y)[np.newaxis, np.newaxis, :, :] mod = mx.mod.Module(symbol=sym, data_names=['input_0'], context=mx.cpu(), label_names=None) mod.bind(for_training=False, data_shapes=[('input_0',test_image.shape)], label_shapes=None) mod.set_params(arg_params=params, aux_params=params, allow_missing=True, allow_extra=True) mod.save_checkpoint("super_resolution",1) net = Import["super_resolution-symbol.json", "MXNet"] 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.