Search code examples
pythonmxnet

when I practise the Mxnet turorial mnist, an error"ImportError: No module named mnist_demo" occurs


The tutorial is on http://mxnet.io/tutorials/python/mnist.html. At this step: "

from IPython.display import HTML
import cv2
import numpy as np
from mnist_demo import html, script
def classify(img):
    img = img[len('data:image/png;base64,'):].decode('base64')
    img = cv2.imdecode(np.fromstring(img, np.uint8), -1)
    img = cv2.resize(img[:,:,3], (28,28))
    img = img.astype(np.float32).reshape((1,1,28,28))/255.0
    return model.predict(img)[0].argmax()

'''
To see the model in action, run the demo notebook at
https://github.com/dmlc/mxnet-notebooks/blob/master/python/tutorials/mnist.ipynb.
'''
HTML(html + script)

"

ImportError Traceback (most recent call last) in () 2 import cv2 3 import numpy as np ----> 4 from mnist_demo import html, script 5 def classify(img): 6 img = img[len('data:image/png;base64,'):].decode('base64')

ImportError: No module named mnist_demo

I do not know what is the reason and I cannot find the answer on Google. Does anyone has any idea?


Solution

  • That was because the tutorial was not written in a single file. You should put the mnist_demo.py file together with your the tutorial notebook. The file could be found at mxnet-notebooks on the github site. :P