jikechao opened a new issue, #15084:
URL: https://github.com/apache/tvm/issues/15084

   For the UpSampling2D operator in keras. If we set the value of attr 
`interpolation` to **bilinear** or **bicubic**, TVM will give different 
predicted results with Keras. 
   
   
   ### Expected behavior
   
   TVM and Keras have the same inference results.
   
   ### Actual behavior
   
   TVM gave different inference results with Keras.
   
![image](https://github.com/apache/tvm/assets/29506758/0d09e7b6-eb97-4dba-9adc-cd4094617845)
   
   
   ### Environment
   
   TVM: latest
   Keras: 2.12.0
   
   ### Steps to reproduce
   
   ```
   import tvm
   import tvm.relay as relay
   import numpy as np
   from tensorflow import keras
   from tensorflow.keras import layers, models
   input_shape = (1, 1, 2, 3)
   input_data = np.random.random(size=input_shape)
   x = layers.Input(shape=input_shape[1:], dtype='float32')
   
   kwargs={'size':[2, 
2],'data_format':"channels_last",'interpolation':"bilinear"} # bilinear, 
bicubic lead to the wrong result 
   
   layer = keras.layers.UpSampling2D(**kwargs)
   layer.set_weights(layer.get_weights())
   
   y = layer(x)
   model = models.Model(x, y)
   model.summary()
   res_keras = model(input_data)
   print(res_keras.shape)
   shape_dict = {'input_1': input_shape}
   mod, params = relay.frontend.from_keras(model, shape_dict,layout='NHWC')
   with tvm.transform.PassContext(opt_level=3):
       model = relay.build_module.create_executor("graph", mod, tvm.cpu(0), 
'llvm', params).evaluate()
   
   test_x_tvm = input_data
   res_tvm = model(tvm.nd.array(test_x_tvm.astype('float32'))).numpy()
   
   np.testing.assert_allclose(res_keras, res_tvm, atol=1e-3, rtol=1e-3)
   ```
   
   ### Triage
   
   Please refer to the list of label tags 
[here](https://github.com/apache/tvm/wiki/Issue-Triage-Labels) to find the 
relevant tags and add them below in a bullet format (example below).
   
   * needs-triage
   * frontend:keras
   * topi
   
   
   ### Analysis
   1. if we use interpolation="nearest", the inference results are the same 
between keras and tvm.
   2. the bug seems in the file 
[topi/image/resize](https://github.com/apache/tvm/blob/main/python/tvm/topi/image/resize.py)
   
   I tried to locate/fix this bug but failed. Wish someone could help me review 
and fix this bug. Thanks!
   
   


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to