You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/10/26 06:28:14 UTC
[GitHub] edmBernard commented on issue #8427: Ask : Speed difference between Mxnet API and Amalgamation API
edmBernard commented on issue #8427: Ask : Speed difference between Mxnet API and Amalgamation API
URL: https://github.com/apache/incubator-mxnet/issues/8427#issuecomment-339564711
@reminisce Your are right I failed on output type. After correction I got the same result.
The main difference is the regular API result is in mx.ndarray format and the Amalgamation is in numpy.ndarray.
Here the line_profiler result :
```python
Line # Hits Time Per Hit % Time Line Contents
==============================================================
20 @profile
21 def main():
22
23 # Load image
24 # img = cv2.imread("data/test2.png")
25 1 3647 3647.0 0.0 img = cv2.imread("data/test1.png")
26 1 507 507.0 0.0 resized_img = transform_image(img)
27
28 # Module API
29 1 8566 8566.0 0.1 model = mx.mod.Module.load('model/test', 101, context=mx.cpu(0), data_names=['data'])
30 1 20229 20229.0 0.2 model.bind(data_shapes=[('data', (1, 3, 200, 200))])
31
32 1 3 3.0 0.0 tic = time.time()
33 11 18 1.6 0.0 for i in range(10):
34 10 23533 2353.3 0.2 image = mx.io.DataBatch(data=(mx.nd.array(resized_img), ), label=(mx.nd.array(['1']),))
35 10 1590 159.0 0.0 model.forward(image)
36 10 353 35.3 0.0 prob = model.get_outputs(0)[0][0][0]
37 10 333 33.3 0.0 print(type(prob)) # <class 'mxnet.ndarray.ndarray.NDArray'>
38 10 12375057 1237505.7 92.7 prob.wait_to_read()
39 10 106503 10650.3 0.8 top1 = mx.nd.argmax(prob, axis=0)[0].asnumpy()[0]
40 10 592 59.2 0.0 print('Prediction :', top1)
41 1 17 17.0 0.0 print("Prediction time : %.6fs" % (time.time() - tic))
42
43
44 # Amalgamation
45 1 2 2.0 0.0 tic = time.time()
46 1 2 2.0 0.0 sys.path.append('/home/dev/lib/mxnet/amalgamation/python/')
47 1 7590 7590.0 0.1 from mxnet_predict import Predictor, load_ndarray_file
48 1 95 95.0 0.0 model = Predictor(open('model/test-symbol.json', "r").read(),
49 1 2576 2576.0 0.0 open('model/test-0101.params', "rb").read(),
50 1 14095 14095.0 0.1 {'data': (1, 3, 200, 200)})
51 11 25 2.3 0.0 for i in range(10):
52 10 3643 364.3 0.0 model.forward(data=resized_img)
53 10 782952 78295.2 5.9 prob = model.get_output(0)[0]
54 10 696 69.6 0.0 print(type(prob)) # <class 'numpy.ndarray'>
55 10 126 12.6 0.0 top1 = np.argmax(prob)
56 10 1159 115.9 0.0 print('Prediction :', top1)
57 1 13 13.0 0.0 print("Prediction time : %.6fs" % (time.time() - tic))
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services