FaceMaskDetection icon indicating copy to clipboard operation
FaceMaskDetection copied to clipboard

How to run mxnet python on GPU?

Open MyraBaba opened this issue 4 years ago • 8 comments

Hi ,

How to run mxnet python on GPU ?

The code running on the cpu

MyraBaba avatar Apr 04 '20 22:04 MyraBaba

Hi, here is the toturials. https://beta.mxnet.io/guide/crash-course/6-use_gpus.html Just set the context to GPU instead of CPU.

AIZOOTech avatar Apr 06 '20 05:04 AIZOOTech

I put gpu(0) on :

def load_mxnet_model(weight_path): ssd = SSD() ssd.load_parameters(weight_path , cox = gpu(0)) return ssd İt gives :

RuntimeError: Parameter 'conv2d_0weight' was not initialized on context cpu(0). It was only initiali| zed on [gpu(0)]. |

ERROR.

Where should I put the CTX = GPU(0) . Not so familiar to the gluon

PS: are you planning to port c++ ? We would love to use it in our hospital entrance

On 6 Apr 2020, at 08:27, AIZOOTech [email protected] wrote:

Hi, here is the toturials. https://beta.mxnet.io/guide/crash-course/6-use_gpus.html https://beta.mxnet.io/guide/crash-course/6-use_gpus.html Just set the context to GPU instead of CPU.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AIZOOTech/FaceMaskDetection/issues/26#issuecomment-609572629, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEFRZHYSJO7UTAKBB63ONIDRLFR4FANCNFSM4L7LAYZQ.

MyraBaba avatar Apr 06 '20 11:04 MyraBaba

Found..

extra need to add default ctx to gpu

Best

MyraBaba avatar Apr 06 '20 12:04 MyraBaba

@MyraBaba how did you solve RuntimeError: Parameter 'conv2d_0bias' was not initialized on context cpu(0). It was only initialized on [gpu(0)]. error

tomriddle54 avatar May 05 '20 14:05 tomriddle54

need to set defult ctx in mxnet. It was my other GPU laptop. When I on it let you know.

MyraBaba avatar May 05 '20 17:05 MyraBaba

@MyraBaba any update sorry to bother you. How did you add extra default ctx to gpu.

tomriddle54 avatar May 08 '20 11:05 tomriddle54

@MyraBaba i have the same issue , please need your help

ZIKO94ZIKO avatar May 18 '20 04:05 ZIKO94ZIKO

Guys, I figured! Two changes need to be applied: In 'mxnet_loader.py', edit the function 'load_mxnet_model' to be like this: def load_mxnet_model(weight_path, ctx=mx.gpu(0)): ssd = SSD() ssd.load_parameters(weight_path, ctx=ctx) ssd.collect_params().reset_ctx(ctx) return ssd

And in the same .py file, edit another function 'mxnet_inference' to be like: def mxnet_inference(model, img_arr, ctx=mx.gpu(0)): y_scores, y_bboxes = model.forward(nd.array(img_arr).as_in_context(ctx)) return y_bboxes.asnumpy(), y_scores.asnumpy()

This should solve your problem.

Zenvi avatar Jun 22 '20 01:06 Zenvi