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

Results differ in first run from next runs #17106

@igor-byel

Description

@igor-byel

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())

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions