### Host PC Dependency Installation for onnx2tf Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md Commands to install the necessary Python packages for developing and running onnx2tf on a host machine. Ensures all dependencies are met for proper function. ```bash pip install -U pip \ && pip install -U onnx \ && pip install -U nvidia-pyindex \ && pip install -U onnx-graphsurgeon \ && pip install -U onnxruntime \ && pip install -U onnxsim \ && pip install -U simple_onnx_processing_tools \ && pip install -U onnx2tf \ && pip install -U h5py==3.7.0 \ && pip install -U tensorflow==2.19.0 \ && pip install -U ai_edge_litert==1.2.0 \ && pip install -U protobuf==4.25.5 \ && pip install -U tf-keras==2.19.0 \ && pip install -U ai-edge-litert==1.2.0 ``` -------------------------------- ### Docker Setup for onnx2tf Development Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md Instructions to build a Docker image for developing the onnx2tf project. This isolates the development environment and ensures consistency. ```bash git clone https://github.com/PINTO0309/onnx2tf && cd onnx2tf docker build -t onnx2tf_develop . ``` -------------------------------- ### Install Custom Flatc Binary for Ubuntu Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This snippet provides commands to download and install a custom flatc binary, essential for specific ONNX operations when using the `-coion` option. It includes instructions for both x86_64/amd64 and arm64 architectures, ensuring compatibility across different systems. ```bash # Custom flatc binary for Ubuntu 22.04+ # https://github.com/PINTO0309/onnx2tf/issues/196 # x86_64/amd64 v23.5.26 wget https://github.com/PINTO0309/onnx2tf/releases/download/1.16.31/flatc.tar.gz \ && tar -zxvf flatc.tar.gz \ && sudo chmod +x flatc \ && sudo mv flatc /usr/bin/ # arm64 v23.1.21 wget https://github.com/PINTO0309/onnx2tf/releases/download/1.26.6/flatc_arm64.tar.gz \ && tar -zxvf flatc_arm64.tar.gz \ && sudo chmod +x flatc \ && sudo mv flatc /usr/bin/ ``` -------------------------------- ### Install onnx2tf on Google Colaboratory Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This snippet outlines the steps to install onnx2tf and its dependencies within a Google Colaboratory environment using Python 3.10. It includes system package updates, downloading and installing the flatc binary, and installing various Python packages via pip, including specific versions for TensorFlow and ONNX. ```python !sudo apt-get -y update !sudo apt-get -y install python3-pip !sudo apt-get -y install python-is-python3 !wget https://github.com/PINTO0309/onnx2tf/releases/download/1.16.31/flatc.tar.gz \ && tar -zxvf flatc.tar.gz \ && sudo chmod +x flatc \ && sudo mv flatc /usr/bin/ !pip install -U pip \ && pip install tensorflow==2.19.0 \ && pip install ai_edge_litert==1.2.0 \ && pip install -U onnx==1.17.0 \ && python -m pip install onnx_graphsurgeon \ --index-url https://pypi.ngc.nvidia.com \ && pip install -U onnxruntime==1.18.1 \ && pip install -U onnxsim==0.4.33 \ && pip install -U simple_onnx_processing_tools \ && pip install -U onnx2tf \ && pip install -U protobuf==3.20.3 \ && pip install -U h5py==3.11.0 \ && pip install -U psutil==5.9.5 \ && pip install -U ml_dtypes==0.5.1 \ && pip install -U tf-keras==2.19.0 \ && pip install flatbuffers>=23.5.26 ``` -------------------------------- ### Install onnx2tf on HostPC using pip Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This code block provides a sequence of pip install commands to set up the onnx2tf environment and its dependencies on a HostPC. It ensures specific versions of ONNX, ONNX Runtime, TensorFlow, and other libraries are installed for compatibility. ```bash pip install -U onnx==1.17.0 \ && pip install -U onnx-graphsurgeon \ && pip install -U onnxruntime==1.18.1 \ && pip install -U onnxsim==0.4.33 \ && pip install -U simple_onnx_processing_tools \ && pip install -U sne4onnx>=1.0.13 \ && pip install -U sng4onnx>=1.0.4 \ && pip install -U ai_edge_litert==1.2.0 \ && pip install -U tensorflow==2.19.0 \ && pip install -U protobuf==3.20.3 \ && pip install -U onnx2tf \ && pip install -U h5py==3.11.0 \ && pip install -U psutil==5.9.5 \ && pip install -U ml_dtypes==0.5.1 \ && pip install -U tf-keras==2.19.0 \ && pip install flatbuffers>=23.5.26 ``` -------------------------------- ### Install coremltools and Convert ONNX to TensorFlow (Bash) Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md Installs the coremltools library version 8.2 and then uses the onnx2tf tool to convert an ONNX model. The -k option preserves the NCHW input channel order, -ois specifies the input shape, and -osd enables output shape definition. ```bash pip install coremltools==8.2 onnx2tf -i mobilenetv2-12.onnx -k input -ois input:1,3,224,224 -osd ``` -------------------------------- ### Install onnx2tf on HostPC using Docker Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This snippet shows how to run the onnx2tf tool using a Docker container on a HostPC. It demonstrates authentication for GHCR and Docker Hub, and how to mount the current directory into the container. This method ensures a consistent environment for conversion. ```bash # PAT authentication is required to pull from GHCR. docker login ghcr.io Username (xxxx): {Enter} Password: {Personal Access Token} Login Succeeded docker run --rm -it \ -v `pwd`:/workdir \ -w /workdir \ ghcr.io/pinto0309/onnx2tf:1.28.5 or # Authentication is not required for pulls from Docker Hub. docker run --rm -it \ -v `pwd`:/workdir \ -w /workdir \ docker.io/pinto0309/onnx2tf:1.28.5 ``` -------------------------------- ### Rewrite TFLite Input/Output OP Names using tfliteiorewriter Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This section provides instructions and examples for rewriting the input and output OP names of a TFLite model, which can be non-descriptive like `serving_default_*:0`. It involves installing a custom `flatc` compiler and the `tfliteiorewriter` package. The command-line tool `tfliteiorewriter` is used with flags to specify the input file, and rewrite rules for input/output names. ```bash # Install custom flatc wget https://github.com/PINTO0309/onnx2tf/releases/download/1.7.3/flatc.tar.gz \ && tar -zxvf flatc.tar.gz \ && sudo chmod +x flatc \ && sudo mv flatc /usr/bin/ \ && rm flatc.tar.gz # Path check which flatc /usr/bin/flatc # Install tfliteiorewriter pip install -U tfliteiorewriter # Example usage: tfliteiorewriter \ -i xxxx.tflite \ -r serving_default_input_1:0 aaa \ -r StatefulPartitionedCall:0 bbb ``` -------------------------------- ### Model Conversion and Optimization with onnx2tf and spo4onnx (Shell) Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This command sequence demonstrates how to optimize an ONNX model using spo4onnx and then convert it to TFLite using onnx2tf. It includes installing the necessary packages and running the conversion with specific arguments. ```shell python export.py \ --img_size 512 512 \ --lightglue_path weights/sjy_fused_static.onnx \ --end2end pip install -U spo4onnx onnx2tf cd weights spo4onnx -if sjy_fused_static.onnx -of sjy_fused_static_spo.onnx onnx2tf -i sjy_fused_static_spo.onnx ``` -------------------------------- ### Generate INT8 Calibration Data using Python Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This Python script demonstrates how to generate calibration data (.npy) for INT8 quantization. It reads image files, performs resizing and normalization, and saves the processed data. It also shows how to load the saved data and provides examples for specifying calibration data via CLI or script. ```python import cv2 import glob import numpy as np # Not used during data generation ################################ # You will need to do the calculations yourself using the test data MEAN = np.asarray([[[[0.485, 0.456, 0.406]]]], dtype=np.float32) # [1,1,1,3] STD = np.asarray([[[[0.229, 0.224, 0.225]]]], dtype=np.float32) # [1,1,1,3] # Not used during data generation ################################ files = glob.glob("data/*.png") img_datas = [] for idx, file in enumerate(files): bgr_img = cv2.imread(file) rgb_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2RGB) resized_img = cv2.resize(rgb_img, dsize=(200,112)) extend_batch_size_img = resized_img[np.newaxis, :] normalized_img = extend_batch_size_img / 255.0 # 0.0 - 1.0 print( f'{str(idx+1).zfill(2)}. extend_batch_size_img.shape: {extend_batch_size_img.shape}' ) # [1,112,200,3] img_datas.append(extend_batch_size_img) calib_datas = np.vstack(img_datas) print(f'calib_datas.shape: {calib_datas.shape}') # [10,112,200,3] np.save(file='data/calibdata.npy', arr=calib_datas) loaded_data = np.load('data/calibdata.npy') print(f'loaded_data.shape: {loaded_data.shape}') # [10,112,200,3] """ -cind INPUT_NAME NUMPY_FILE_PATH MEAN STD int8_calib_datas = (loaded_data - MEAN) / STD # -1.0 - 1.0 e.g. How to specify calibration data in CLI or Script respectively. 1. CLI -cind "pc_dep" "data/calibdata.npy" "[[[[0.485,0.456,0.406]]]]" "[[[[0.229,0.224,0.225]]]]" -cind "feat" "data/calibdata2.npy" "[[[[0.123,...,0.321]]]]" "[[[[0.112,...,0.451]]]]" 2. Script custom_input_op_name_np_data_path=[ ["pc_dep", "data/calibdata.npy", [[[[0.485,0.456,0.406]]]], [[[[0.229,0.224,0.225]]]]], ["feat", "data/calibdata2.npy", [[[[0.123,...,0.321]]]], [[[[0.112,...,0.451]]]], ] """ ``` -------------------------------- ### Inference with Dynamic Batch Size using Signature Runner (Python) Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md Demonstrates how to perform inference with dynamic batch sizes using the signature_runner in TFLite. This requires specifying the '-coion' option during model conversion. The code initializes an Interpreter, gets the signature runner, and then performs inference with different batch sizes. ```python import numpy as np from ai_edge_litert.interpreter import Interpreter from pprint import pprint interpreter = Interpreter(model_path="saved_model/osnet_x0_25_msmt17_float32.tflite") tf_lite_model = interpreter.get_signature_runner() inputs = { 'images': np.ones([5,256,128,3], dtype=np.float32), } tf_lite_output = tf_lite_model(**inputs) print(f"[TFLite] Model Predictions shape: {tf_lite_output['output'].shape}") print(f"[TFLite] Model Predictions:") pprint(tf_lite_output) ``` ```python import numpy as np from ai_edge_litert.interpreter import Interpreter from pprint import pprint interpreter = Interpreter(model_path="saved_model/osnet_x0_25_msmt17_float32.tflite") tf_lite_model = interpreter.get_signature_runner() inputs = { 'images': np.ones([3,256,128,3], dtype=np.float32), } tf_lite_output = tf_lite_model(**inputs) print(f"[TFLite] Model Predictions shape: {tf_lite_output['output'].shape}") print(f"[TFLite] Model Predictions:") pprint(tf_lite_output) ``` -------------------------------- ### Generate Debug Info with @print_node_info Decorator Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md This Python code demonstrates how to generate model conversion log information using the `@print_node_info` decorator. It shows how to populate the 'tf_node_info' field within the `tf_layers_dict`, including the TensorFlow operation type, inputs, and outputs. ```python tf_layers_dict[graph_node_output.name]['tf_node_info'] = \ make_tf_node_info( node_info={ 'tf_op_type': tf.image.non_max_suppression, 'tf_inputs': { 'boxes': tf_boxes, 'scores': tf_scores, 'max_output_boxes_per_class': max_output_boxes_per_class, 'iou_threshold': iou_threshold, 'score_threshold': score_threshold, }, 'tf_outputs': { 'output': tf_layers_dict[graph_node_output.name]['tf_node'], }, } ) ``` -------------------------------- ### Download and Unzip Sample Model for Validation Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This command downloads a sample ONNX model (`prelu_check.onnx`) required for validating accuracy issues. It uses `curl` to download the zip file and `unzip` to extract the ONNX model. ```bash curl \ -L https://github.com/PINTO0309/onnx2tf/files/12367312/prelu_check.onnx.zip \ -o prelu_check.onnx.zip unzip prelu_check.onnx.zip ``` -------------------------------- ### Define TensorFlow Layer Dictionary Structure Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md This Python snippet illustrates the expected structure of the `tf_layers_dict` when processing graph nodes. It defines the keys 'optype', 'shape', 'dtype', and 'tf_node' for each layer, which are essential for the conversion process. ```python tf_layers_dict[graph_node_output.name] = { 'optype': graph_node.op, 'shape': shape, 'dtype': dtype, 'tf_node': (TensorFlow Op), } ``` -------------------------------- ### Prepare for CoreML Conversion Source: https://context7.com/pinto0309/onnx2tf/llms.txt Prepare an ONNX model for CoreML conversion, maintaining NCHW format. This requires specifying the input name and shape, and using the 'osd' flag. ```bash # Prepare for CoreML conversion (maintain NCHW format) pip install coremltools==8.2 onnx2tf -i model.onnx -k input -ois "input:1,3,224,224" -osd ``` -------------------------------- ### Convert Model for INT8 Quantization using Bash Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This bash command demonstrates how to prepare a model for INT8 quantization by outputting a SavedModel with a default serving signature and converting the batch size to a static integer. Note that this procedure may lead to accuracy degradation. ```bash # Example command structure (actual parameters would be specified by the user) # onnx2tf -i input_model.onnx -o output_directory -osd -b ``` -------------------------------- ### Python: TensorFlow OP Generation - Storing TF Node Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md Generates the corresponding TensorFlow operation for the given ONNX node and stores the resulting TensorFlow node in `tf_layers_dict`. This step is crucial for building the TensorFlow graph representation of the ONNX model. ```python tf_layers_dict[graph_node_output.name]['tf_node'] = \ tf.math.abs( x=input_tensor, ``` -------------------------------- ### Python: Parameter Replacement - Input Value Modification Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md Utilizes the `@get_replacement_parameter` decorator and the `replace_parameter` function to overwrite ONNX input values based on user-defined JSON configurations. This allows for customization of model behavior by modifying specific input parameters. ```python boxes = replace_parameter( value_before_replacement=boxes, param_target='inputs', param_name=graph_node.inputs[0].name, **kwargs, ) scores = replace_parameter( value_before_replacement=scores, param_target='inputs', param_name=graph_node.inputs[1].name, **kwargs, ) ``` -------------------------------- ### Float16 Acceleration for ARM64 Source: https://context7.com/pinto0309/onnx2tf/llms.txt Enable Float16 acceleration for ARM64 ARMv8.2+ architectures. This option optimizes models for performance on compatible ARM devices. ```bash onnx2tf -i model.onnx -eatfp16 ``` -------------------------------- ### Optimize GPU Delegate Source: https://context7.com/pinto0309/onnx2tf/llms.txt Enable GPU delegate optimization for ONNX models during conversion to TensorFlow. This command optimizes the model for execution on GPUs. ```bash onnx2tf -i model.onnx -ofgd ``` -------------------------------- ### Python: ONNX Parameter Reading - Attribute Value Retrieval Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md Retrieves attribute values specific to an ONNX operator. If an attribute is not found, it defaults to the specification defined in the ONNX Operator Schemas. This ensures correct parameter handling for various ONNX operations. ```python center_point_box = graph_node.attrs.get('center_point_box', 0) ``` -------------------------------- ### Python: Preserving Graph Structure - Metadata Generation Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md Generates metadata required to maintain the overall graph structure of the model. This section captures the output shape, data type, and operation type for each node, storing it in `tf_layers_dict` to preserve the computational graph. ```python graph_node_output: gs.Variable = graph_node.outputs[0] shape = graph_node_output.shape dtype = graph_node_output.dtype tf_layers_dict[graph_node_output.name] = { 'optype': graph_node.op, 'shape': shape, 'dtype': dtype, } ``` -------------------------------- ### ONNX to TensorFlow Conversion Command with Parameter Replacement Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This command initiates the ONNX to TensorFlow conversion process using the `--param_replacement_file` or `-prf` option to specify a JSON file containing parameter replacement configurations. This is crucial for handling specific tensor format conversions and manual parameter adjustments. ```bash --param_replacement_file param_replacement.json or -prf param_replacement.json ``` -------------------------------- ### Custom Input Data Configuration for ONNX to TF Conversion Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md Specifies how to provide custom input data for operations like custom-to-ONNX-to-TF (cotof) and integer quantization (oiqt). It supports numpy file paths and optional mean/std deviation for normalization. The format varies slightly between -cotof and -oiqt modes, with -oiqt requiring mean and std for normalization and enforcing specific data types and preprocessing. Simultaneous use of both flags requires all parameters (input name, file path, mean, std) to be provided. ```shell # Usage for -cotof: # -cind # Example: # -cind onnx::Equal_0 test_cind/x_1.npy -cind onnx::Add_1 test_cind/x_2.npy -cotof # Usage for -oiqt: # -cind # Example (for image data): # -cind input0 ../input0.npy [[[[0.485]],[[0.456]],[[0.406]]]] [[[[0.229]],[[0.224]],[[0.225]]]] # Example with multiple inputs: cind=[ ["input0","../input0.npy",[[[[0.485, 0.456, 0.406]]]],[[[[0.229, 0.224, 0.225]]]]], ["input1","./input1.npy",[0.1, ..., 0.64],[0.05, ..., 0.08]], ["input2","input2.npy",[0.3],[0.07]], ] ``` -------------------------------- ### Python: ONNX Parameter Reading - Shape Transposition Determination Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md Determines if input data transposition is necessary based on ONNX and TensorFlow output shape compatibility. This process, managed by the `@inverted_operation_enable_disable` decorator, influences subsequent data manipulation. The result is stored in `tf_layers_dict`. ```python before_op_output_shape_trans_1 = \ tf_layers_dict.get(graph_node.inputs[0].name, {}).get('before_op_output_shape_trans', True) before_op_output_shape_trans_2 = \ tf_layers_dict.get(graph_node.inputs[1].name, {}).get('before_op_output_shape_trans', True) before_op_output_shape_trans = \ before_op_output_shape_trans_1 \ and before_op_output_shape_trans_2 ``` -------------------------------- ### Python: ONNX Parameter Reading - Type Annotation for Debugging Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md Adds type annotations to variables for enhanced debugging experience in IDEs like VSCode. This improves code readability and maintainability without affecting the tool's core functionality. It distinguishes between TensorFlow nodes and input data. ```python boxes = tf_layers_dict[graph_node_input_1.name]['tf_node'] \ if isinstance(graph_node_input_1, gs.Variable) else graph_node_input_1 scores = tf_layers_dict[graph_node_input_2.name]['tf_node'] \ if isinstance(graph_node_input_2, gs.Variable) else graph_node_input_2 ``` -------------------------------- ### Convert ONNX to TFLite (Initial Attempt) Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This command attempts to convert an ONNX model (`prelu_check.onnx`) to a TFLite file. The `-cotof` option is used, and this conversion is performed before applying any workarounds. ```bash onnx2tf -i prelu_check.onnx -cotof ``` -------------------------------- ### Python: ONNX Parameter Reading - Input Value Transposition and Conversion Source: https://github.com/pinto0309/onnx2tf/blob/main/CONTRIBUTING.md Transposes input values based on the `before_op_output_shape_trans` flag. If `True`, transposition occurs; otherwise, it's skipped. It also converts ONNX initializers to NumPy ndarrays. This function ensures input data is in the correct format for TensorFlow operations. ```python graph_node_input_1 = get_constant_or_variable( graph_node.inputs[0], before_op_output_shape_trans, ) graph_node_input_2 = get_constant_or_variable( graph_node.inputs[1], before_op_output_shape_trans, ) ``` -------------------------------- ### Operator Replacement and Optimization for ONNX Models Source: https://context7.com/pinto0309/onnx2tf/llms.txt Replaces specific ONNX operators with pseudo-implementations to improve compatibility or optimize for certain hardware targets. This is useful for operators that may not be well-supported or perform poorly. ```bash # Replace PReLU with pseudo-operations for better compatibility onnx2tf -i model.onnx -rtpo PReLU # Replace multiple operators onnx2tf -i model.onnx -rtpo Erf GeLU PReLU LeakyReLU ``` -------------------------------- ### Modify ONNX NMS max_output_boxes_per_class using sam4onnx Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This command-line utility modifies specific attributes of ONNX operations. It is used here to change the `max_output_boxes_per_class` attribute of the NonMaxSuppression operation to a fixed value, resolving issues with variable output shapes that hinder compatibility with TensorFlow.js and TFLite. Ensure you have `sam4onnx` installed via pip. ```bash pip install sam4onnx sam4onnx \ --op_name main01_nonmaxsuppression11 \ --input_onnx_file_path yolov7.onnx \ --output_onnx_file_path nms_yolov7_update.onnx \ --input_constants main01_max_output_boxes_per_class int64 [20] ``` -------------------------------- ### Multi-Format Export (Bash) Source: https://context7.com/pinto0309/onnx2tf/llms.txt Export an ONNX model to multiple formats including TensorFlow.js, CoreML, TFLite, and Keras variants using bash commands. This facilitates deployment across various platforms. ```bash # Export with all format options onnx2tf -i model.onnx \ -osd \ -oh5 \ -okv3 \ -otfv1pb \ -ow ``` -------------------------------- ### Python API ONNX to TensorFlow/TFLite Conversion Source: https://context7.com/pinto0309/onnx2tf/llms.txt Programmatic model conversion using the onnx2tf Python API. Allows for detailed control over conversion parameters, including signature definitions, batch size, input shape overwriting, and output formats like H5 and Keras v3. Includes an example of TFLite inference using signatures. ```python import onnx2tf import numpy as np from ai_edge_litert.interpreter import Interpreter # Basic conversion with signature definitions model = onnx2tf.convert( input_onnx_file_path='model.onnx', output_folder_path='saved_model', output_signaturedefs=True, copy_onnx_input_output_names_to_tflite=True, non_verbose=False ) # Conversion with batch size fixing and shape overwriting model = onnx2tf.convert( input_onnx_file_path='model.onnx', batch_size=1, overwrite_input_shape=['data:1,3,224,224'], output_folder_path='output_model', output_h5=True, output_keras_v3=True ) # Inference with generated TFLite model using signatures interpreter = Interpreter(model_path='saved_model/model_float32.tflite') tf_lite_model = interpreter.get_signature_runner() inputs = { 'input_name': np.ones([1, 224, 224, 3], dtype=np.float32), } output = tf_lite_model(**inputs) print(f"Output shape: {output['output_name'].shape}") ``` -------------------------------- ### Convert ONNX to TFLite with Constant Outputs (Bash) Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md This bash command converts an ONNX model to TFLite format, ensuring that constant outputs are preserved. It bypasses the `onnxsim` optimization step using the `-nuo` flag and enables constant output tracking with `-cotof`. This is useful when you need to include fixed values as outputs from the model. ```bash wget https://github.com/PINTO0309/onnx2tf/files/15292126/toy_with_constant.onnx.zip unzip toy_with_constant.onnx.zip onnx2tf -i toy_with_constant.onnx -nuo -cotof ``` -------------------------------- ### Prepare for TensorFlow.js Conversion Source: https://context7.com/pinto0309/onnx2tf/llms.txt Convert an ONNX model to a format suitable for TensorFlow.js conversion. This involves specifying input shapes and using the 'osd' and 'dgc' flags, followed by the 'tensorflowjs_converter' command. ```bash # Prepare for TensorFlow.js conversion pip install tensorflowjs onnx2tf -i model.onnx -ois "input:1,3,224,224" -osd -dgc tensorflowjs_converter \ --input_format tf_saved_model \ --output_format tfjs_graph_model \ saved_model \ tfjs_model ``` -------------------------------- ### ONNX Add Operation Parameter Replacement Configuration Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md Configuration for the 'Add' operation in ONNX. It allows for pre-processing transpose using `pre_process_transpose_perm` before the addition or post-processing transpose using `post_process_transpose_perm` after the addition. The `param_target` specifies whether the transpose is applied to 'inputs' or 'outputs'. ```json { "op_type": "Add", "param_target": "inputs", "pre_process_transpose_perm": [0,3,1,2] # Example permutation } { "op_type": "Add", "param_target": "outputs", "post_process_transpose_perm": [0,2,1] # Example permutation } ``` -------------------------------- ### Partial Model Conversion with onnx2tf Source: https://github.com/pinto0309/onnx2tf/blob/main/README.md Allows conversion of specific parts of an ONNX model by specifying input or output names. Useful for debugging or inspecting intermediate outputs. Dependencies: onnx2tf. Input: ONNX model file, input/output names. Output: Converted TFLite model subset. ```bash wget https://github.com/PINTO0309/onnx2tf/releases/download/1.25.0/cf_fus.onnx onnx2tf -i cf_fus.onnx -inimc 448 -coion ``` ```bash wget https://github.com/PINTO0309/onnx2tf/releases/download/1.25.0/cf_fus.onnx onnx2tf -i cf_fus.onnx -onimc dep_sec -coion ``` ```bash wget https://github.com/PINTO0309/onnx2tf/releases/download/1.25.0/cf_fus.onnx onnx2tf -i cf_fus.onnx -inimc 448 -onimc velocity -coion ```