fabio-sim / Depth-Anything-ONNX

ONNX-compatible Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data
Apache License 2.0
234 stars 23 forks source link

[BUG] Cannot Slim the Model with OnnxSlim #10

Closed cverrier closed 2 months ago

cverrier commented 3 months ago

Description

Using the --slim argument when running export.py leads to a FileNotFoundError.

Reproducible Example

Within a Bash shell, I used a fresh Python 3.11.9 virtual environment and I installed the requirements (after having pinned them with pip-tools).

Running the command

python export.py --model s --precision float16 --slim

fails and raises the error

Failed to slim model: [Errno 2] No such file or directory: 'python -m onnxslim weights/depth_anything_vits14_float16.onnx weights/depth_anything_vits14_float16_slim.onnx'

How to Fix

This is due to how the arguments are passed in the subprocess.run command below: https://github.com/fabio-sim/Depth-Anything-ONNX/blob/240f1303d99afb6c2c8100e2ff2f970f20d9c7f3/export.py#L115-L121

We have to pass a list of arguments rather than a single string:

# `export.py` file, line 118
- subprocess.run(f"python -m onnxslim {model} {output}", stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
+ subprocess.run(["python", "-m", "onnxslim", model, output], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)

Since I know how to fix that, I can tackle this issue later.