jikechao opened a new pull request, #15337:
URL: https://github.com/apache/tvm/pull/15337

   This PR fixes a corner bug in the softmax converter in the Keras frontend.
   If the input dimension of softmax is 1, TVM will crash unexpectedly.
   
   ### Model structure:
   
![image](https://github.com/apache/tvm/assets/29506758/d277cbbe-e862-4277-944f-c3a132209ff5)
   
   
   ### StackTrace
   ```
   Traceback (most recent call last):
     File "test.py", line 25, in <module>
       mod, params = relay.frontend.from_keras(model, shape_dict)
     File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/keras.py", 
line 1565, in from_keras
       _convert_layer(keras_layer, etab)
     File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/keras.py", 
line 1519, in _convert_layer
       layout,
     File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/keras.py", 
line 1394, in keras_op_to_relay
       outs = _convert_map[op_name](inexpr, keras_layer, etab, data_layout)
     File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/keras.py", 
line 134, in _convert_advanced_activation
       dims = len(input_shape)
   TypeError: object of type 'NoneType' has no len()
   ```
   
   
   ### 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 = (11,)
   input_data = np.random.random(size=input_shape)
   dtype = 'float32'
   
   x = layers.Input(shape=input_shape[1:], dtype=dtype)
   
   layer = keras.layers.Softmax()
   layer.set_weights(layer.get_weights())
   
   y = layer(x)
   model = models.Model(x, y)
   res_keras = model.predict(input_data)
   print(model.summary())
   
   res_keras2 = model(input_data)
   
   shape_dict = {'input_1': input_shape}
   mod, params = relay.frontend.from_keras(model, shape_dict)
   print(mod)
   ```
   
   
   cc @echuraev @Hzfengsy @leandron 


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