MonicaGu commented on issue #17684: The output of the ReLU layer in MXNET is 
different from that in tensorflow and cntk
URL: 
https://github.com/apache/incubator-mxnet/issues/17684#issuecomment-603144553
 
 
   I could reproduce the difference with your code. However, when I use the 
output of "conv1_bn" layer as the input of ReLU, the output results of both 
mxnet and TensorFlow backend are the same. Here is my code:
   ```
   import pickle
   import tensorflow as tf
   import mxnet as mx
   import numpy as np
   
   imagename = 'imagenet-0.png'
   with open("output/{}_{}.pkl".format("mxnet",imagename[:-4]), "rb+") as f:
        backend_output_dict = pickle.load(f)
   count = 0
   for each in backend_output_dict:
        count += 1
        if count == 3: # the 3rd layer is conv1_bn
                input_mxnet = each
                break
   
   with open("output/{}_{}.pkl".format("tensorflow",imagename[:-4]), "rb+") as 
f:
        backend_output_dict = pickle.load(f)
   count = 0
   for each in backend_output_dict:
        count += 1
        if count == 3: # the 3rd layer is conv1_bn
                input_tf = each
                break
   
   def delta(x, y):
        x = np.reshape(x, [np.shape(x)[0], -1])
        y = np.reshape(y, [np.shape(y)[0], -1])
        return np.mean(np.abs(x - y), axis=1)
   
   mxoutput = mx.nd.relu(mx.nd.array(input_tf))
   tfoutput = tf.nn.relu(input_tf)
   print(delta(mxoutput.asnumpy(), tfoutput))
   
   mxoutput2 = mx.nd.relu(mx.nd.array(input_mxnet))
   tfoutput2 = tf.nn.relu(input_mxnet)
   print(delta(mxoutput2.asnumpy(), tfoutput2))
   print(delta(tfoutput, mxoutput2.asnumpy()))
   ```
   The output of the code is:
   ```
   [0.]
   [0.]
   [3.0203162e-06]
   ```
   This result is quite different from the result of your code. Therefore, I 
suppose there might be a problem in Keras.

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