Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Need help: numpy array to mxnet ndarray is too slow. #7899

Closed
KeyKy opened this issue Sep 14, 2017 · 5 comments
Closed

Need help: numpy array to mxnet ndarray is too slow. #7899

KeyKy opened this issue Sep 14, 2017 · 5 comments

Comments

@KeyKy
Copy link
Contributor

KeyKy commented Sep 14, 2017

numpy array to mxnet ndarray is too slow.

start = time.time()
data_ = [mx.nd.array(img_data)]
label_ = [mx.nd.array(label_data)]
end = time.time()
print 't3: {}'.format(end-start)

t3: 0.293313980103. sometimes i get 1.5s. Need help, thanks! It slows down my training!

@madjam
Copy link
Contributor

madjam commented Sep 15, 2017

How big is img_data and label_data?
FYI: this involves allocating memory and copying contents of numpy array into the allocated memory.
How is this step slowing down your training? how often are you doing this copy?

@KeyKy
Copy link
Contributor Author

KeyKy commented Sep 19, 2017

@madjam image_data is (128, 3, 224, 224) label_data is (128,)
it needs to load batch of data before doing net training. Forward and backward is much faster than loading data. So i need to reduce the loading data cost.

@KeyKy KeyKy closed this as completed Oct 13, 2017
@Joke09
Copy link

Joke09 commented Dec 5, 2018

For inference, I have the same problem. The client send jpg to server, then the server use cv2 to do resize. When put the image data into the mx.nd.array, it's very slow. And the Utilization of GPU is low too. How to solve it? Thank you!

@summer-via
Copy link

I have the same problem, why is the nd.array() function so slow?

@leezu
Copy link
Contributor

leezu commented Apr 16, 2020

You can use the mx.nd.from_numpy(ndarray, zero_copy=True) if you don't mind that the numpy array is invalid afterwards.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants