wyc-ruiker commented on a change in pull request #4822: [Frontend][TFLite] Add 
MIRROR_PAD operator
URL: https://github.com/apache/incubator-tvm/pull/4822#discussion_r375337905
 
 

 ##########
 File path: python/tvm/relay/frontend/tflite.py
 ##########
 @@ -1422,10 +1423,48 @@ def convert_pad(self, op):
         # convert list of lists to tuple of tuples
         paddings = tuple(tuple(l) for l in pad_list)
 
-        # Use default pad_value 0 because TFLite does not support 
constant_values parameter
+        # Use default pad_value 0 because TFLite PAD does not support 
constant_values parameter
         out = _op.nn.pad(in_expr, paddings)
         return out
 
+    def convert_mirror_pad(self, op):
+        """Convert TFLite MIRROR_PAD"""
+        try:
+            from tflite.Operator import Operator
+            from tflite.BuiltinOptions import BuiltinOptions
+            from tflite.MirrorPadOptions import MirrorPadOptions
+        except ImportError:
+            raise ImportError("The tflite package must be installed")
+
+        # the quantized form MirrorPad is not yet implemented in TFLite.
+        if self.is_quantized(op):
+            raise tvm.error.OpNotImplemented(
 
 Review comment:
   I have tried to support it. But when I write a test case like this:
   ```python
   in_data = [array_ops.placeholder(shape=data[0].shape, dtype='float32', 
name='in')]
   inq_data = [tf.quantization.fake_quant_with_min_max_args(in_data[0], 
min=-100, max=100, name="inq")]
   out = array_ops.pad(inq_data[0], ops.convert_to_tensor(data[1], 
dtype=data[1].dtype), mode=mode)
   out = tf.quantization.fake_quant_with_min_max_args(out, min=-100, max=100, 
name="out")
   compare_tflite_with_tvm([data[0]], ['inq:0'], inq_data, [out], 
quantized=True)
   ```
   I find this case check failed in TFlite:
   ```
   2020-02-05 23:44:37.789418: F ./tensorflow/lite/toco/toco_tooling.h:38] 
Check failed: s.ok() Unimplemented: this graph contains an operator of type 
MirrorPad for which the quantized form is not yet implemented. Sorry, and 
patches welcome (that's a relatively fun patch to write, mostly providing the 
actual quantized arithmetic code for this op).
   Fatal Python error: Aborted
   Current thread 0x00007fee879dd700 (most recent call first):
     File 
"/home/wangyc/.local/lib/python3.7/site-packages/tensorflow/lite/toco/python/toco_from_protos.py",
 line 33 in execute
     File "/home/wangyc/.local/lib/python3.7/site-packages/absl/app.py", line 
250 in _run_main
     File "/home/wangyc/.local/lib/python3.7/site-packages/absl/app.py", line 
299 in run
     File 
"/home/wangyc/.local/lib/python3.7/site-packages/tensorflow/python/platform/app.py",
 line 40 in run
     File 
"/home/wangyc/.local/lib/python3.7/site-packages/tensorflow/lite/toco/python/toco_from_protos.py",
 line 59 in main
     File "/home/wangyc/.local/bin/toco_from_protos", line 8 in <module>
   Aborted (core dumped)
   ```

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