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

Results differ in first run from next runs #17106

Open
igor-byel opened this issue Dec 18, 2019 · 0 comments
Open

Results differ in first run from next runs #17106

igor-byel opened this issue Dec 18, 2019 · 0 comments
Labels

Comments

@igor-byel
Copy link

igor-byel commented Dec 18, 2019

Description

Results differ in first-run from next runs when using MXNET_ENGINE_TYPE=NaiveEngine environment variable

Steps to reproduce

#1.set environment variable
import os
os.environ["MXNET_ENGINE_TYPE"] = "NaiveEngine"
##this import commented in global  if uncomment all works good 
##import moved to line 14,23,24 to emulate reference to class in separated file
#import mxnet as mx    
#from mxnet import ndarray as nd

#2.init
import numpy as np
import cv2

class NetInterface:
  def __init__(self, prefix, epoch):
    import mxnet as mx

    sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch)
    image_size = (640, 640)
    self.model = mx.mod.Module(symbol=sym, context=mx.cpu(), label_names = None)
    self.model.bind(data_shapes=[('data', (1, 3, image_size[0], image_size[1]))], for_training=False)
    self.model.set_params(arg_params, aux_params)

  def run(self, img):
      import mxnet as mx
      from mxnet import ndarray as nd    
      im_tensor = np.transpose(img, (2, 0, 1))[np.newaxis, ...].astype(np.float32)
      for i in range(3):
          im_tensor[:, i, :, :] = im_tensor[:, 2 - i, :, :]
      data = nd.array(im_tensor.copy())
      net_in = mx.io.DataBatch(data=(data,), provide_data=[('data', data.shape)])
      self.model.forward(net_in, is_train=False)
      net_out = self.model.get_outputs()
      return net_out
#models are here https://drive.google.com/drive/folders/1OTXuAUdkLVaf78iz63D1uqGLZi4LbPeL
prefix="mnet.25"
epoch=0
net = NetInterface(prefix, epoch,)

img = cv2.imread(
    'some image with faces ')



#3. run
outputs=[]
for j in range(3):

  numpy_out=[]
  net_out=net.run(img)
  for j in range(len(net_out)):
      numpy_out.append(net_out[j].asnumpy())
  outputs.append(numpy_out)


for i in range(2):
    for j in range(i+1,3):
      for k in range(len(outputs[0])):
         print( i, "--",j, " diff  " ,np.abs(outputs[i][k]-outputs[j][k]).max())
@igor-byel igor-byel added the Bug label Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant