Incubator-mxnet: UserWarning: input name is not found in symbol.list_arguments()

Created on 11 Apr 2017  路  4Comments  路  Source: apache/incubator-mxnet

I ran NN on raspberrypi. Please ignored OOM prolem(std::bad_alloc), I wanna fix userWarning. Thanks a lot!

Error Messages

(py-perfblas) yuanshuai@raspberrypi:~/code/mxnet_inference/vgg-16-official-mxnet $ python run_inference.py                                                                                                                                                                                                             
[16:42:22] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.8.0. Attempting to upgrade...
[16:42:22] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
/home/yuanshuai/pyEnv/py-perfblas/local/lib/python2.7/site-packages/mxnet-0.9.5-py2.7.egg/mxnet/module/base_module.py:52: UserWarning: You created Module with Module(..., label_names=['softmax_label']) but input with name 'softmax_label' is not found in symbol.list_arguments(). Did you mean one of:
        data
        prob_label
  warnings.warn(msg)
/home/yuanshuai/pyEnv/py-perfblas/local/lib/python2.7/site-packages/mxnet-0.9.5-py2.7.egg/mxnet/module/base_module.py:64: UserWarning: Data provided by label_shapes don't match names specified by label_names ([] vs. ['softmax_label'])
  warnings.warn(msg)
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted

Code

import os, sys 
import urllib
import mxnet as mx
import time

# Added by yuanshuai
sys.path.append('/mnt/sdcard/lizhihao/install/opencv-3.1.0/lib/python2.7/dist-packages')

with open('synset.txt', 'r') as f:
    synsets = [l.rstrip() for l in f]

# Edited by yuanshuai
sym, arg_params, aux_params = mx.model.load_checkpoint('caffenet-upgrade', 1)
#arg_params['prob_label'] = mx.nd.array([0])
#mx.model.bind(data_shapes=[('data', (1, 3, 224, 224))], label_shapes=[('prob_label', (1,))] )

mod = mx.mod.Module(symbol=sym, context=mx.cpu(0))
input_shape = (224, 224)
predict_times = 1 
mod.bind(for_training=False, data_shapes=[('data', (1, 3, input_shape[0], input_shape[1]))])
mod.set_params(arg_params, aux_params)

import cv2 
import numpy as np
from collections import namedtuple
Batch = namedtuple('Batch', ['data'])

def get_image(url, show=True):
    get_image_start = time.time()
    filename = url.split("/")[-1]
    img = cv2.imread(filename)
    if img is None:
        print('failed to download ' + url)
    print "get image take {0}".format((time.time()-get_image_start)/100)
    return filename

def predict(filename, mod, synsets, input_shape, predict_times=1):
    predict_start = time.time()
    img = cv2.cvtColor(cv2.imread(filename), cv2.COLOR_BGR2RGB)
    if img is None:
        return None
    img = cv2.resize(img, (224, 224))
    img = np.swapaxes(img, 0, 2)
    img = np.swapaxes(img, 1, 2)
    img = img[np.newaxis, :]

    start = time.time()
    for i in range(predict_times):
         mod.forward(Batch([mx.nd.array(img)]))
         #print 'take time {0}'.format(time.time()-start)
         prob = mod.get_outputs()[0].asnumpy()
         prob = np.squeeze(prob)
         a = np.argsort(prob)[::-1]
    print "each image take {0}".format((time.time()-start)/predict_times)
    #for i in a[0:5]:
    #    print('probability=%f, class=%s' % (prob[i], synsets[i]))

url = './Cat-hd-wallpapers.jpg'
predict(url, mod, synsets, input_shape, predict_times = predict_times)

Most helpful comment

i'm having the same issue loading vgg16 model and doing a prediction. Where do you suggest I provide the dummy 'softmax_label'? In the model json file? I'm totally new so not familiar with that format.

All 4 comments

By Default MxNet network looks for an input with the name 'softmax_label' as the target variable for training. When you built your network by loading the check-point, it was expecting an input 'softmax_label' which you did not provide that hence the warning.
Take a look here:
https://github.com/dmlc/mxnet/blob/master/python/mxnet/module/module.py#L31

A probable remedy could be to just supply a dummy variable with the name 'softmax_label'

i'm having the same issue loading vgg16 model and doing a prediction. Where do you suggest I provide the dummy 'softmax_label'? In the model json file? I'm totally new so not familiar with that format.

This issue is closed due to lack of activity in the last 90 days. Feel free to ping me to reopen if this is still an active issue. Thanks!

same issue here

bascially i think issues can not be closed if they've not been solved.

Was this page helpful?
0 / 5 - 0 ratings