Skip to content

Output directory (args.output) ignored if input file is an absolute path in generate_cc_arrays.py #3106

@sbeneitez-intera

Description

@sbeneitez-intera

Description:

When running tensorflow/lite/micro/tools/generate_cc_arrays.py, if the input file is specified as an absolute path, the output files are not created in the directory defined by the args.output argument. Instead, they are created alongside the input file, regardless of the output directory requested.

This is because of the following line (line 145):

output_base_fname = os.path.join(args.output, os.path.splitext(input_file)[0])

If input_file is an absolute path, os.path.join ignores args.output and uses the absolute part only.

Example:

  • args.output = "/tmp/outputs"
  • input_file = "/home/user/data/model.tflite"

Actual output:

/home/user/data/model_model_data.cc
/home/user/data/model_model_data.h

Expected output:

/tmp/outputs/model_model_data.cc
/tmp/outputs/model_model_data.h

Suggested Solution:

To ensure output files are always placed in the specified output directory, even when input_file is an absolute path, use only the base filename of input_file when constructing output_base_fname. For example, replace line 145 with:

output_base_fname = os.path.join(args.output, os.path.splitext(os.path.basename(input_file))[0])

This will generate the output files in the correct directory, regardless of whether the input file path is absolute or relative.

References:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions