lanking520 commented on issue #14756: Mismatch between shape Java API
URL: 
https://github.com/apache/incubator-mxnet/issues/14756#issuecomment-486769617
 
 
   Minimum reproducible Java code:
   ```
   import org.apache.mxnet.infer.javaapi.Predictor;
   import org.apache.mxnet.javaapi.*;
   
   import java.util.ArrayList;
   import java.util.Arrays;
   import java.util.List;
   
   public class YoloInference {
       public static void main(String[] args) {
           // Prepare the predictor
           List<DataDesc> inputDesc = new ArrayList<>();
           List<Context> contexts = new ArrayList<>();
           DataDesc dataDesc = new DataDesc("data", new Shape(new int[]{1, 3, 
512, 512}), DType.Float32(), "NCHW");
           Context context = Context.cpu();
           inputDesc.add(dataDesc);
           contexts.add(context);
           Predictor predictor = new Predictor("yolo/yolo3_darknet53", 
inputDesc, contexts, 0);
           // Prepare the data
           NDArray nd = NDArray.ones(Context.cpu(), new int[]{1, 3, 512, 512});
           // Do inference
           System.out.println(nd);
           predictor.predictWithNDArray(Arrays.asList(nd));
       }
   }
   ```
   
   Where as Python did not have this problem:
   ```
   import mxnet as mx
   from mxnet import nd
   
   sym, arg_params, aux_params = 
mx.model.load_checkpoint(prefix='yolo3_darknet53', epoch=0)
   
   mod = mx.mod.Module(symbol=sym,
                       data_names=['data'],
                       context=mx.cpu(),
                       label_names=None)
   mod.bind(for_training=False,
            data_shapes=[('data', (1, 3, 512, 512))],
            label_shapes=mod._label_shapes)
   
   mod.set_params(arg_params, aux_params, allow_missing=True)
   
   sample_input = nd.ones((1, 3, 512, 512))
   
   data_iter = mx.io.NDArrayIter(sample_input, None, 1)
   result = mod.predict(data_iter)
   for item in result:
       print(item.shape)
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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

Reply via email to