Joke09 commented on issue #13545: 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! URL: https://github.com/apache/incubator-mxnet/issues/13545#issuecomment-445417415 > Hi @Joke09 instead of trying to use cv2 to read, you should use this: > https://mxnet.incubator.apache.org/api/python/image/image.html#mxnet.image.imread > Which convert an image into NDArray directly Hi @lanking520 , the client use cv2 to read and send the image data to the server. I can't control it. I don't really want to write the image data to disk. Another question: the shape of `data` in `mx.io.DataBatch` must be [8,3,896,1024]. The `im_infos.shape` is (8, 3). They are both used for proposal in image detection. But image.imread and image.imdecode just get only one NDArray and the shape is [3,896,1024]. How to get NDArray with the shape is [8,3,896,1024]. I have try this: ``` im_arrays = im_arrays.swapaxes(2, 3).swapaxes(1, 2) #data = [mx.nd.array(im_arrays), mx.nd.array(im_infos)] img_encodes = [] for im_array in im_arrays: img_encodes.append(cv2.imencode('.bmp', im_array)[1]) batch_images = [mx.img.imdecode(img_encode) for img_encode in img_encodes] # note: I don't know how to convert this list of NDArray to an NDArray of batch image data. data_batch = mx.io.DataBatch(data=data, label=None, provide_data=data_shapes, provide_label=None) self.module.forward(data_batch) ``` I also try this: ``` im = cv2.imread("0.jpg") start = time.time() img_encode = cv2.imencode('.bmp', im)[1] image = mx.img.imdecode(img_encode) print(time.time() - start) start = time.time() image = mx.nd.array(im) print(time.time() - start) ``` the fisrt print time is almost half of the second. Maybe the `mx.nd.array` is too slow.
---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
