[AutoTVM] could not broadcast input array from shape (1057) into shape (871)

I’m trying to import a TFLite mobilenet v1 model (https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_1.0_224.tgz) and tune it on an Android phone. I got the following error:

(python3.7) user1@user11:~/Desktop/tvm/tutorials/autotvm$ python tune_relay_arm.py 
Extract tasks...
Tuning...
[Task  1/20]  Current/Best:    7.06/  12.67 GFLOPS | Progress: (12/1500) | 16.01 s[17:12:01] /usr/local/home/user1/Desktop/tvm/src/tir/transforms/vectorize_loop.cc:356: Detect vectorize inside vectorized loop, ignoring...
[Task  1/20]  Current/Best:    1.35/  12.67 GFLOPS | Progress: (60/1500) | 61.32 sTraceback (most recent call last):
  File "tune_relay_arm.py", line 391, in <module>
    tune_and_evaluate(tuning_option)
  File "tune_relay_arm.py", line 346, in tune_and_evaluate
    tune_tasks(tasks, **tuning_opt)
  File "tune_relay_arm.py", line 322, in tune_tasks
    autotvm.callback.log_to_file(tmp_log_file),
  File "/usr/local/home/user1/miniconda3/envs/python3.7/lib/python3.7/site-packages/tvm-0.8.dev120+g0c7aae345-py3.7-linux-x86_64.egg/tvm/autotvm/tuner/xgboost_tuner.py", line 103, in tune
    super(XGBTuner, self).tune(*args, **kwargs)
  File "/usr/local/home/user1/miniconda3/envs/python3.7/lib/python3.7/site-packages/tvm-0.8.dev120+g0c7aae345-py3.7-linux-x86_64.egg/tvm/autotvm/tuner/tuner.py", line 169, in tune
    self.update(inputs, results)
  File "/usr/local/home/user1/miniconda3/envs/python3.7/lib/python3.7/site-packages/tvm-0.8.dev120+g0c7aae345-py3.7-linux-x86_64.egg/tvm/autotvm/tuner/model_based_tuner.py", line 270, in update
    self.cost_model.fit(self.xs, self.ys, self.plan_size)
  File "/usr/local/home/user1/miniconda3/envs/python3.7/lib/python3.7/site-packages/tvm-0.8.dev120+g0c7aae345-py3.7-linux-x86_64.egg/tvm/autotvm/tuner/xgboost_cost_model.py", line 184, in fit
    x_train = self._get_feature(xs)
  File "/usr/local/home/user1/miniconda3/envs/python3.7/lib/python3.7/site-packages/tvm-0.8.dev120+g0c7aae345-py3.7-linux-x86_64.egg/tvm/autotvm/tuner/xgboost_cost_model.py", line 348, in _get_feature
    ret[i, :] = t if t is not None else 0
ValueError: could not broadcast input array from shape (1057) into shape (871)

It seems it randomly happens at various points. If I change the tuner to GA or xgb-knob, it works fine. Not sure what it is about ‘xgb’ tuner. Also, it works fine if I use the built-in mobilenet model.

This is how I import the TFLite model:

diff --git a/tutorials/autotvm/tune_relay_arm.py b/tutorials/autotvm/tune_relay_arm.py
index 31fda54a9..965318860 100644
--- a/tutorials/autotvm/tune_relay_arm.py
+++ b/tutorials/autotvm/tune_relay_arm.py
@@ -117,6 +117,23 @@ def get_network(name, batch_size):
             net.params, relay.nn.softmax(net.body), None, net.type_params, net.attrs
         )
         mod = tvm.IRModule.from_expr(net)
+    elif name == 'tflite':
+        import tflite
+        tflite_model_file = '/usr/local/home/user1/Desktop/mobilenet_v1_1.0_224.tflite'
+        tflite_model_buf = open(tflite_model_file, "rb").read()
+        # Get TFLite model from buffer
+        try:
+            import tflite
+            tflite_model = tflite.Model.GetRootAsModel(tflite_model_buf, 0)
+        except AttributeError:
+            import tflite.Model
+            tflite_model = tflite.Model.Model.GetRootAsModel(tflite_model_buf, 0)
+        input_tensor = "input"
+        input_shape = (1, 224, 224, 3)
+        input_dtype = "float32"
+        mod, params = relay.frontend.from_tflite(tflite_model,
+                                         shape_dict={input_tensor: input_shape},
+                                         dtype_dict={input_tensor: input_dtype})
1 Like