mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Segmentation fault when using 'simple_bind'

Open sodabeta7 opened this issue 10 years ago • 8 comments

Hi, I've got a 'Segmentation fault' when I try to use a pre-trained model to do simple_bind operation. The model is converted from vgg16 Caffe model by the tool in mxnet. And the code works if I comment out the last line. This is the code:

import numpy as np
import mxnet as mx


X=mx.io.ImageRecordIter(
  path_imgrec ='data/'+"val_rec.bin",
  mean_r      =123.68,
  mean_g      =116.779,
  mean_b      =103.939,
  rand_crop   =False,
  rand_mirror =False,
  data_shape  =(3,224,224),
  batch_size  =32,
  num_parts   =1,
  part_index  =0)

prefix='model/vgg16'
devs=mx.gpu()
vgg_model=mx.model.FeedForward.load(prefix,1,ctx=devs)
vgg_exec=vgg_model.symbol.simple_bind(vgg_model.ctx[0],grad_req='null',**dict(X.provide_data))

This is what I got from gdb

gdb

sodabeta7 avatar Dec 04 '15 10:12 sodabeta7

ping @winstywang

sodabeta7 avatar Dec 04 '15 10:12 sodabeta7

If you want to use FeedForward model you should use it's fit API instead of binding by yourself.

piiswrong avatar Dec 04 '15 20:12 piiswrong

Thank you for your reply. Since I just want to do predicting instead of training, the fit API is not a choice here. And the source code in predict function in mxnet also use simple_bind like what I do above. And I've found that if I replace devs=mx.gpu() with devs=mx.cpu(), it works without segmentation fault.

sodabeta7 avatar Dec 07 '15 12:12 sodabeta7

@piiswrong To make it more clear, I think the code is the same as FeedForward._init_predictor since I just take the symbol out from the model and do simple_bind.

sodabeta7 avatar Dec 07 '15 13:12 sodabeta7

Can you run any example with GPU? a quick work around is to fit with end_epoch=0 so that FeedFoward model can bind for you without training

piiswrong avatar Dec 09 '15 02:12 piiswrong

model = mx.model.FeedForward.load('path/to/model', 5, ctx=mx.gpu(0))
data = your_data_iter
depth = model.predict(data)

This code works fine for me.

piiswrong avatar Dec 09 '15 03:12 piiswrong

@piiswrong He only needs the symbol stored in the checkpoint. If he initializes the symbol from scratch, it works fine.

winstywang avatar Dec 09 '15 03:12 winstywang

https://github.com/dmlc/mxnet/issues/865

piiswrong avatar Dec 09 '15 08:12 piiswrong