lain-m21 / pytorch-to-tflite-example

Convert MobileNetV3Small defined and pre-trained in PyTorch to a TFLite quantized model
75 stars 13 forks source link

ValueError: Shape must be rank 1 but is rank 0 for '314/cond/Reshape_4' (op: 'Reshape') with input shapes: [1,16,1,1], []. #5

Open mgarbade opened 4 years ago

mgarbade commented 4 years ago

I tried to execute your script. Since I could not download the predtrained weights using download_weight.sh I downloaded them manually from here: https://github.com/d-li14/mobilenetv3.pytorch

This is the full error message:

WARNING:tensorflow:From /home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:181: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.

WARNING:tensorflow:From /home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:186: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2020-03-04 09:45:20.031768: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-03-04 09:45:20.054585: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3600000000 Hz
2020-03-04 09:45:20.054910: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x56315456ec20 executing computations on platform Host. Devices:
2020-03-04 09:45:20.054923: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2020-03-04 09:45:20.055583: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library libcuda.so.1
2020-03-04 09:45:20.536153: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-03-04 09:45:20.536641: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: 
name: TITAN RTX major: 7 minor: 5 memoryClockRate(GHz): 1.77
pciBusID: 0000:01:00.0
2020-03-04 09:45:20.536649: I tensorflow/stream_executor/platform/default/dlopen_checker.cc:62] Not built with GPU enabled. Skip GPU library dlopen check.
2020-03-04 09:45:20.536676: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-03-04 09:45:20.537149: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-03-04 09:45:20.537602: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2020-03-04 09:45:22.168244: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-03-04 09:45:22.168264: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0 
2020-03-04 09:45:22.168269: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N 
2020-03-04 09:45:22.168414: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-03-04 09:45:22.168889: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-03-04 09:45:22.169340: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:1005] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-03-04 09:45:22.169784: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 22177 MB memory) -> physical GPU (device: 0, name: TITAN RTX, pci bus id: 0000:01:00.0, compute capability: 7.5)
WARNING:tensorflow:From /home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:190: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.

2020-03-04 09:45:22.175870: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
WARNING:tensorflow:From /home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:1834: The name tf.nn.fused_batch_norm is deprecated. Please use tf.compat.v1.nn.fused_batch_norm instead.

Traceback (most recent call last):
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1864, in _create_c_op
    c_op = c_api.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape must be rank 1 but is rank 0 for '314/cond/Reshape_4' (op: 'Reshape') with input shapes: [1,16,1,1], [].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 98, in <module>
    main()
  File "main.py", line 42, in main
    pytorch2savedmodel(onnx_model_path, saved_model_dir)
  File "/home/garbade/libs/pytorch-to-tflite-example/converters.py", line 14, in pytorch2savedmodel
    change_ordering=True, verbose=False)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/onnx2keras/converter.py", line 146, in onnx_to_keras
    node_name
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/onnx2keras/normalization_layers.py", line 52, in convert_batchnorm
    layers[node_name] = bn(input_0)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/keras/engine/base_layer.py", line 457, in __call__
    output = self.call(inputs, **kwargs)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/keras/layers/normalization.py", line 206, in call
    training=training)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3123, in in_train_phase
    x = switch(training, x, alt)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3058, in switch
    else_expression_fn)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1988, in cond
    orig_res_f, res_f = context_f.BuildCondBranch(false_fn)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1814, in BuildCondBranch
    original_result = fn()
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/keras/layers/normalization.py", line 167, in normalize_inference
    epsilon=self.epsilon)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 1908, in batch_normalization
    mean = tf.reshape(mean, (-1))
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 7715, in reshape
    "Reshape", tensor=tensor, shape=shape, name=name)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper
    op_def=op_def)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3616, in create_op
    op_def=op_def)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2027, in __init__
    control_input_ops)
  File "/home/garbade/miniconda3/envs/py36_trch2tf/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1867, in _create_c_op
    raise ValueError(str(e))
ValueError: Shape must be rank 1 but is rank 0 for '314/cond/Reshape_4' (op: 'Reshape') with input shapes: [1,16,1,1], [].