PINTO0309 / tflite2tensorflow

Generate saved_model, tfjs, tf-trt, EdgeTPU, CoreML, quantized tflite, ONNX, OpenVINO, Myriad Inference Engine blob and .pb from .tflite. Support for building environments with Docker. It is possible to directly access the host PC GUI and the camera to verify the operation. NVIDIA GPU (dGPU) support. Intel iHD GPU (iGPU) support. Supports inverse quantization of INT8 quantization model.
https://qiita.com/PINTO
MIT License
258 stars 38 forks source link

Latest docker image: error: unrecognized arguments #7

Closed MaHoef closed 3 years ago

MaHoef commented 3 years ago

Hello Pinto, I am following the tutorial form here: https://github.com/geaxgx/openvino_hand_tracker Can it be that in the latest docker version the API has changed?

This is what I do: marco@CHROTZ:/tmp/depthai_hand_tracker$ docker run --gpus all -it --rm \ -v pwd:/workspace/resources \ -e LOCAL_UID=$(id -u $USER) \ -e LOCAL_GID=$(id -g $USER) \ pinto0309/tflite2tensorflow:latest bash

NVIDIA Release 20.09 (build 15985252)

NVIDIA TensorRT 7.1.3 (c) 2016-2020, NVIDIA CORPORATION. All rights reserved. Container image (c) 2020, NVIDIA CORPORATION. All rights reserved.

https://developer.nvidia.com/tensorrt

To install Python sample dependencies, run /opt/tensorrt/python/python_setup.sh

To install open source parsers, plugins, and samples, run /opt/tensorrt/install_opensource.sh. See https://github.com/NVIDIA/TensorRT for more information.

error: XDG_RUNTIME_DIR not set in the environment. [setupvars.sh] OpenVINO environment initialized

wget https://github.com/google/mediapipe/blob/master/mediapipe/modules/hand_landmark/hand_landmark.tflite wget https://github.com/google/mediapipe/blob/master/mediapipe/modules/palm_detection/palm_detection.tflite

tflite2tensorflow --model_path ./hand_landmark.tflite --model_output_path palm_detection --flatc_path /home/user/flatc --schema_path /home/user/schema.fbs --output_pb True tflite2tensorflow: error: unrecognized arguments: True

tflite2tensorflow --model_path ./hand_landmark.tflite --model_output_path palm_detection --flatc_path /home/user/flatc --schema_path /home/user/schema.fbs --output_pb
output json command = /home/user/flatc -t --strict-json --defaults-json -o . /home/user/schema.fbs -- ./hand_landmark.tflite /home/user/flatc: error: binary "./hand_landmark.tflite" does not have expected file_identifier "TFL3", use --raw-binary to read this file anyway.

Thanks Marco

PINTO0309 commented 3 years ago

You have issued a Pull Request to the repository you are referring to.

https://github.com/geaxgx/openvino_hand_tracker/pull/1

MaHoef commented 3 years ago

Hi Pinto, thanks for the quick replay. I have seen the command line change. However, I still can't convert the google models to TF as the tool claims: does not have expected file_identifier "TFL3" I don't need the openvino outputs. My intention is to use a TF float model, convert it to the h5 format and use the Xilinx compiler with it.

PINTO0309 commented 3 years ago

I'm going to bed now since it's late at night today, but I'll check tomorrow. I'm not sure, but updating to tf-nightly might work.

PINTO0309 commented 3 years ago

@MaHoef To generate .h5, which is very old and officially deprecated, a special procedure is required; to generate saved_model, it can be easily converted without any particular error. I don't know the specifics of Xilinx compiler, but I would not recommend using .h5.

$ docker run -it --rm \
  -v `pwd`:/home/user/workdir \
  --net=host \
  --privileged \
  pinto0309/openvino2tensorflow:latest

$ cd workdir

$ wget https://github.com/google/mediapipe/blob/master/mediapipe/modules/hand_landmark/hand_landmark.tflite

$ tflite2tensorflow \
--model_path hand_landmark.tflite \
--flatc_path ../flatc \
--schema_path ../schema.fbs \
--output_pb

$ tflite2tensorflow \
--model_path hand_landmark.tflite \
--flatc_path ../flatc \
--schema_path ../schema.fbs \
--output_no_quant_float32_tflite

$ $INTEL_OPENVINO_DIR/deployment_tools/model_optimizer/mo_tf.py \
--saved_model_dir saved_model \
--output_dir saved_model/openvino/FP32

$ openvino2tensorflow \
--model_path saved_model/openvino/FP32/saved_model.xml \
--output_h5

Screenshot from 2021-05-13 08-40-22 Screenshot from 2021-05-13 08-42-01

MaHoef commented 3 years ago

Hello Pinto, thanks for the hint with the old format. Even for tf2 Xilinx uses this format: vai_c_tensorflow2 -m ./tf2_resnet50_imagenet_224_224_7.76G_1.3/quantized/quantized.h5 -a ./arch.json -n resnet50

Thanks for providing the files via google drive, really nice from you.

I tried to reproduce exactly what you did. Very strange as I still get the error: ../flatc: error: binary "hand_landmark.tflite" does not have expected file_identifier "TFL3"

I attached the full log, maybe you have an idea tflite2tensorflow.log

PINTO0309 commented 3 years ago

Can you successfully visualize the tflite file you downloaded with the tool at the URL below? There is a good chance that the file you downloaded is corrupt. https://netron.app/

MaHoef commented 3 years ago

You were absolutely right, the image was corrupt. Wget is not the tool to download something from github. It works now as expected. I will proceed now to get the converted model compiled by the Xilinx tools which might be a challenge. Thank you Marco