Open kondounagi opened 4 years ago
$ ssh -F /dev/null user@192.168.11.4 Fri
$ byobu
$ cd /home/user/ai-edge/ai-edge-contest-4th/3rd/platform/Vitis-AI
$ ./gpu_docker_run.sh
$ conda activate vitis-ai-tensorflow
このissue先頭の二つのコマンドが使える
以下で作業する
$ /workspace/model_development
vai_q_tensorflow quantize --input_frozen_graph unko/bisenetv2_from_onnx.pb --input_nodes image_array --input_shapes ?,1216,1936,3 --output_nodes category --input_fn input_fn.calib_input --method 1 --calib_iter 20 --output_dir ./Vitis-AI-Quantizer/vai_q_tensorflow/quantize_results
を実行すると, 以下のエラーが返ってきた.
Traceback (most recent call last):
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/bin/vai_q_tensorflow", line 11, in <module>
sys.exit(run_main())
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 943, in run_main
app.run(main=my_main, argv=[sys.argv[0]] + unparsed)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/platform/app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/absl/app.py", line 303, in run
_run_main(main, args)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 942, in <lambda>
my_main = lambda unused_args: main(unused_args, FLAGS)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 621, in main
flags.skip_check)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 343, in quantize_frozen
check_float_graph(input_graph_def, input_fn, q_config, s_config)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 258, in check_float_graph
feed_dict = gen_feed_dict(input_tensors, inputs)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/utils.py", line 140, in gen_feed_dict
"key {} not found, please check your input_fn.".format(name))
ValueError: key image_array not found, please check your input_fn.
input_fn.py内のcalib_inputで,
return {"image_array": images}
としたらこのエラーは出なくなった.
次のエラー
Traceback (most recent call last):
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/bin/vai_q_tensorflow", line 11, in <module>
sys.exit(run_main())
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 943, in run_main
app.run(main=my_main, argv=[sys.argv[0]] + unparsed)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/platform/app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/absl/app.py", line 303, in run
_run_main(main, args)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 942, in <lambda>
my_main = lambda unused_args: main(unused_args, FLAGS)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 621, in main
flags.skip_check)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 343, in quantize_frozen
check_float_graph(input_graph_def, input_fn, q_config, s_config)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 259, in check_float_graph
sess.run(output_tensors, feed_dict)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 956, in run
run_metadata_ptr)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1156, in _run
(np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (1, 1216, 1936, 3) for Tensor 'image_array:0', which has shape '(1, 3, 1216, 1936)'
pytorchはNCHWの形でデータを扱うけど, tensorflowはNHWCの順で扱うらしく, 変換の過程ではこれをきちんと扱えていないようで, Quntizationする途中, shape関連のエラーが出ているよう.
vai_q_tensorflow quantize --input_frozen_graph unko/bisenetv2_cityscapes_frozen.pb --input_nodes input_tensor --input_shapes ?,512,1024,3 --output_nodes final_output --input_fn input_fn.calib_input --method 1 --calib_iter 20 --output_dir ./Vitis-AI-Quantizer/vai_q_tensorflow/quantize_results
run after rebuilding tensorflow
same error, rebuild docker image itself
same error
[Traceback (most recent call last):
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/bin/vai_q_tensorflow", line 11, in <module>
sys.exit(run_main())
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 943, in run_main
app.run(main=my_main, argv=[sys.argv[0]] + unparsed)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/platform/app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/absl/app.py", line 303, in run
_run_main(main, args)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 942, in <lambda>
my_main = lambda unused_args: main(unused_args, FLAGS)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 621, in main
flags.skip_check)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 346, in quantize_frozen
q_config, s_config)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/decent_q.py", line 277, in calibrate_frozen
q_config)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/contrib/decent_q/python/quantize_graph.py", line 184, in CreateQuantizeCalibrationGraphDef
input_graph_def_string, config.to_string(), status)
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/framework/errors_impl.py", line 556, in __exit__
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Mul constant NHWC input to batch norm has bad shape: [96]]
Traceback (most recent call last):
File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/bin/vai_q_tensorflow", line 11, in
(ちょっと話が逸れるが, )作ったpbファイルを使ってevaluateする. (pbファイルを変更する)
python tools/cityscapes/evaluate_bisenetv2_cityscapes.py --pb_file_path ./checkpoint/bisenetv2_cityscapes_frozen.pb --dataset_dir ./data/example_dataset/cityscapes
vai_q_tensorflow quantize --input_frozen_graph unko/bisenetv2_cityscapes_frozen.pb --input_nodes input_tensor --input_shapes ?,512,1024,3 --output_nodes BiseNetV2/prediction --input_fn input_fn.calib_input --method 1 --calib_iter 20 --output_dir ./Vitis-AI-Quantizer/vai_q_tensorflow/quantize_results
replace batch_normalization with BatchNormalization
when batch_size=1
vai_q_tensorflow quantize --input_frozen_graph unko/bisenetv2_cityscapes_frozen1222_batch1.pb --input_nodes input_tensor --input_shapes 1,512,1024,3 --output_nodes final_output --input_fn input_fn.calib_input --method 1 --calib_iter 20 --output_dir ./Vitis-AI-Quantizer/vai_q_tensorflow/quantize_results
when batch_size=3
vai_q_tensorflow quantize --input_frozen_graph unko/bisenetv2_cityscapes_frozen1222_batch3.pb --input_nodes input_tensor --input_shapes 3,512,1024,3 --output_nodes BiseNetV2/prediction --input_fn input_fn.calib_input --method 1 --calib_iter 20 --output_dir ./Vitis-AI-Quantizer/vai_q_tensorflow/quantize_results
in both case, get following code
tensorflow.python.framework.errors_impl.InvalidArgumentError: Mul constant NHWC input to batch norm has bad shape: [96]