Hello,
I am trying to predict an image loading the image with the function mxnet.image.imdecode.
I used mx.nd function ( reshape, expand_dims ...) but I have an error when I try to predict. I do not understand where the problem come from. ( the reshaping seems to work I can print it)
little_batch = mx.image.imdecode(open(path_image,'rb').read(),flag=1, to_rgb=1) print(little_batch.shape) little_batch = mx.image.imresize(little_batch, 224,224) little_batch = mx.nd.expand_dims(little_batch, axis=0) little_batch = mx.nd.reshape(little_batch,(1, 3, 224, 224)) print(little_batch.shape) print(little_batch.asnumpy()[0,2,::,::]) batch = mx.io.DataBatch(data=(little_batch,), label = (mx.nd.array(['1']),)) model.forward(batch , is_train=False)
The error's message :
[12:08:52] src/nnvm/legacy_json_util.cc:190: Loading symbol saved by previous version v0.9.4. Attempting to upgrade...
[12:08:52] src/nnvm/legacy_json_util.cc:198: Symbol successfully upgraded!
[12:09:10] src/operator/././cudnn_algoreg-inl.h:57: Running performance tests to find the best convolution algorithm, this can take a while... (setting env variable MXNET_CUDNN_AUTOTUNE_DEFAULT to 0 to disable)
[12:09:12] /root/mxnet/dmlc-core/include/dmlc/logging.h:300: [12:09:12] src/ndarray/ndarray_function.cu:18: Check failed: to->type_flag_ == from.type_flag_ (0 vs. 3) Source and target must have the same data type when copying across devices.Stack trace returned 9 entries:
[bt] (0) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4dmlc15LogMessageFatalD1Ev+0x39) [0x7f20ddc296c9]
[bt] (1) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet7ndarray4CopyIN7mshadow3cpuENS2_3gpuEEEvRKNS_5TBlobEPS5_NS_7ContextES9_NS_10RunContextE+0xd3) [0x7f20df1ca8d3]
[bt] (2) /root/mxnet/python/mxnet/../../lib/libmxnet.so(+0xeb9bad) [0x7f20de5b4bad]
[bt] (3) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZNSt17_Function_handlerIFvN5mxnet10RunContextENS0_6engine18CallbackOnCompleteEEZNS0_6Engine8PushSyncESt8functionIFvS1_EENS0_7ContextERKSt6vectorIPNS2_3VarESaISC_EESG_NS0_10FnPropertyEiPKcEUlS1_S3_E_E9_M_invokeERKSt9_Any_dataS1_S3_+0x23) [0x7f20ddc994a3]
[bt] (4) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet6engine14ThreadedEngine15ExecuteOprBlockENS_10RunContextEPNS0_8OprBlockE+0x98) [0x7f20de4e31f8]
[bt] (5) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZNSt17_Function_handlerIFvvEZZN5mxnet6engine23ThreadedEnginePerDevice13PushToExecuteEPNS2_8OprBlockEbENKUlvE0_clEvEUlvE_E9_M_invokeERKSt9_Any_data+0x60) [0x7f20de4e7520]
[bt] (6) /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x90c30) [0x7f20ca85fc30]
[bt] (7) /lib/x86_64-linux-gnu/libpthread.so.0(+0x8184) [0x7f20fe34b184]
[bt] (8) /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f20fe07837d][12:09:12] /root/mxnet/dmlc-core/include/dmlc/logging.h:300: [12:09:12] src/engine/./threaded_engine.h:329: [12:09:12] src/ndarray/ndarray_function.cu:18: Check failed: to->type_flag_ == from.type_flag_ (0 vs. 3) Source and target must have the same data type when copying across devices.
Stack trace returned 9 entries:
[bt] (0) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4dmlc15LogMessageFatalD1Ev+0x39) [0x7f20ddc296c9]
[bt] (1) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet7ndarray4CopyIN7mshadow3cpuENS2_3gpuEEEvRKNS_5TBlobEPS5_NS_7ContextES9_NS_10RunContextE+0xd3) [0x7f20df1ca8d3]
[bt] (2) /root/mxnet/python/mxnet/../../lib/libmxnet.so(+0xeb9bad) [0x7f20de5b4bad]
[bt] (3) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZNSt17_Function_handlerIFvN5mxnet10RunContextENS0_6engine18CallbackOnCompleteEEZNS0_6Engine8PushSyncESt8functionIFvS1_EENS0_7ContextERKSt6vectorIPNS2_3VarESaISC_EESG_NS0_10FnPropertyEiPKcEUlS1_S3_E_E9_M_invokeERKSt9_Any_dataS1_S3_+0x23) [0x7f20ddc994a3]
[bt] (4) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet6engine14ThreadedEngine15ExecuteOprBlockENS_10RunContextEPNS0_8OprBlockE+0x98) [0x7f20de4e31f8]
[bt] (5) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZNSt17_Function_handlerIFvvEZZN5mxnet6engine23ThreadedEnginePerDevice13PushToExecuteEPNS2_8OprBlockEbENKUlvE0_clEvEUlvE_E9_M_invokeERKSt9_Any_data+0x60) [0x7f20de4e7520]
[bt] (6) /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x90c30) [0x7f20ca85fc30]
[bt] (7) /lib/x86_64-linux-gnu/libpthread.so.0(+0x8184) [0x7f20fe34b184]
[bt] (8) /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f20fe07837d]An fatal error occurred in asynchronous engine operation. If you do not know what caused this error, you can try set environment variable MXNET_ENGINE_TYPE to NaiveEngine and run with debugger (i.e. gdb). This will force all operations to be synchronous and backtrace will give you the series of calls that lead to this error. Remember to set MXNET_ENGINE_TYPE back to empty after debugging.
Stack trace returned 6 entries:
[bt] (0) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4dmlc15LogMessageFatalD1Ev+0x39) [0x7f20ddc296c9]
[bt] (1) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet6engine14ThreadedEngine15ExecuteOprBlockENS_10RunContextEPNS0_8OprBlockE+0x4ac) [0x7f20de4e360c]
[bt] (2) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZNSt17_Function_handlerIFvvEZZN5mxnet6engine23ThreadedEnginePerDevice13PushToExecuteEPNS2_8OprBlockEbENKUlvE0_clEvEUlvE_E9_M_invokeERKSt9_Any_data+0x60) [0x7f20de4e7520]
[bt] (3) /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x90c30) [0x7f20ca85fc30]
[bt] (4) /lib/x86_64-linux-gnu/libpthread.so.0(+0x8184) [0x7f20fe34b184]
[bt] (5) /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f20fe07837d]terminate called after throwing an instance of 'dmlc::Error'
what(): [12:09:12] src/engine/./threaded_engine.h:329: [12:09:12] src/ndarray/ndarray_function.cu:18: Check failed: to->type_flag_ == from.type_flag_ (0 vs. 3) Source and target must have the same data type when copying across devices.Stack trace returned 9 entries:
[bt] (0) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4dmlc15LogMessageFatalD1Ev+0x39) [0x7f20ddc296c9]
[bt] (1) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet7ndarray4CopyIN7mshadow3cpuENS2_3gpuEEEvRKNS_5TBlobEPS5_NS_7ContextES9_NS_10RunContextE+0xd3) [0x7f20df1ca8d3]
[bt] (2) /root/mxnet/python/mxnet/../../lib/libmxnet.so(+0xeb9bad) [0x7f20de5b4bad]
[bt] (3) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZNSt17_Function_handlerIFvN5mxnet10RunContextENS0_6engine18CallbackOnCompleteEEZNS0_6Engine8PushSyncESt8functionIFvS1_EENS0_7ContextERKSt6vectorIPNS2_3VarESaISC_EESG_NS0_10FnPropertyEiPKcEUlS1_S3_E_E9_M_invokeERKSt9_Any_dataS1_S3_+0x23) [0x7f20ddc994a3]
[bt] (4) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet6engine14ThreadedEngine15ExecuteOprBlockENS_10RunContextEPNS0_8OprBlockE+0x98) [0x7f20de4e31f8]
[bt] (5) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZNSt17_Function_handlerIFvvEZZN5mxnet6engine23ThreadedEnginePerDevice13PushToExecuteEPNS2_8OprBlockEbENKUlvE0_clEvEUlvE_E9_M_invokeERKSt9_Any_data+0x60) [0x7f20de4e7520]
[bt] (6) /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x90c30) [0x7f20ca85fc30]
[bt] (7) /lib/x86_64-linux-gnu/libpthread.so.0(+0x8184) [0x7f20fe34b184]
[bt] (8) /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f20fe07837d]An fatal error occurred in asynchronous engine operation. If you do not know what caused this error, you can try set environment variable MXNET_ENGINE_TYPE to NaiveEngine and run with debugger (i.e. gdb). This will force all operations to be synchronous and backtrace will give you the series of calls that lead to this error. Remember to set MXNET_ENGINE_TYPE back to empty after debugging.
Stack trace returned 6 entries:
[bt] (0) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN4dmlc15LogMessageFatalD1Ev+0x39) [0x7f20ddc296c9]
[bt] (1) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZN5mxnet6engine14ThreadedEngine15ExecuteOprBlockENS_10RunContextEPNS0_8OprBlockE+0x4ac) [0x7f20de4e360c]
[bt] (2) /root/mxnet/python/mxnet/../../lib/libmxnet.so(_ZNSt17_Function_handlerIFvvEZZN5mxnet6engine23ThreadedEnginePerDevice13PushToExecuteEPNS2_8OprBlockEbENKUlvE0_clEvEUlvE_E9_M_invokeERKSt9_Any_data+0x60) [0x7f20de4e7520]
[bt] (3) /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x90c30) [0x7f20ca85fc30]
[bt] (4) /lib/x86_64-linux-gnu/libpthread.so.0(+0x8184) [0x7f20fe34b184]
[bt] (5) /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f20fe07837d]
How can I solve the problem ?
data readed in uint8, you need to cast it to float first
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!
@szha It still is an issue.
MXNetError Traceback (most recent call last)
<ipython-input-5-86d0ff6dc892> in <module>()
----> 1 predict('https://github.com/dmlc/web-data/blob/master/mxnet/doc/tutorials/python/predict_image/cat.jpg?raw=true')
<ipython-input-4-a9db1e4f665d> in predict(url)
25 # compute the predict probabilities
26 mod.forward(Batch([img]))
---> 27 prob = mod.get_outputs()[0].asnumpy()
28 # print the top-5
29 prob = np.squeeze(prob)
/usr/local/lib/python3.5/dist-packages/mxnet/ndarray/ndarray.py in asnumpy(self)
1874 self.handle,
1875 data.ctypes.data_as(ctypes.c_void_p),
-> 1876 ctypes.c_size_t(data.size)))
1877 return data
1878
/usr/local/lib/python3.5/dist-packages/mxnet/base.py in check_call(ret)
147 """
148 if ret != 0:
--> 149 raise MXNetError(py_str(_LIB.MXGetLastError()))
150
151
MXNetError: [12:46:50] src/ndarray/ndarray_function.cu:43: Check failed: to->type_flag_ == from.type_flag_ (0 vs. 3) Source and target must have the same data type when copying across devices.
Stack trace returned 10 entries:
[bt] (0) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x30cbe2) [0x7fcd90174be2]
[bt] (1) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x30d1b8) [0x7fcd901751b8]
[bt] (2) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x4655d4f) [0x7fcd944bdd4f]
[bt] (3) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x2afcebb) [0x7fcd92964ebb]
[bt] (4) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x2b10728) [0x7fcd92978728]
[bt] (5) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x2b1084b) [0x7fcd9297884b]
[bt] (6) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x294ada4) [0x7fcd927b2da4]
[bt] (7) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x295100b) [0x7fcd927b900b]
[bt] (8) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x295122e) [0x7fcd927b922e]
[bt] (9) /usr/local/lib/python3.5/dist-packages/mxnet/libmxnet.so(+0x294b46b) [0x7fcd927b346b]
I met this problem, too. Any suggestion? thanks
The image must be changed to float32 type for gpu context. (as @piiswrong commented.)
In @Shiro-LK ’s code, add a line as little_batch = little_batch.astype('float32') after reshaping.
Most helpful comment
@szha It still is an issue.