Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --onnx to wd14 tagger #864

Merged
merged 4 commits into from
Oct 9, 2023
Merged

Add --onnx to wd14 tagger #864

merged 4 commits into from
Oct 9, 2023

Conversation

Isotr0py
Copy link
Contributor

@Isotr0py Isotr0py commented Oct 8, 2023

Related issue: #854

  • Add --onnx for wd14 tagger to run onnx model
  • Make tensorflow optional for wd14 tagger

Though the onnx model in SmilingWolf/wd-v1-4-convnext-tagger-v2 can only use batch_size=1, it still has a faster tagging speed than keras.

Tested on i9-13900HX CPU windows environment:

  • onnx: about 3.37it/s
  • tensorflow: about 1.42s/it

@kohya-ss
Copy link
Owner

kohya-ss commented Oct 9, 2023

Thank you for this! This is really useful!

@kohya-ss kohya-ss merged commit 8a2d68d into kohya-ss:dev Oct 9, 2023
1 check passed
@kohya-ss
Copy link
Owner

kohya-ss commented Oct 9, 2023

I have tried to change the batch size of the model on the fly according to this issue:
onnx/onnx#2182

but no luck 😅 The result for all images was the same.

@Isotr0py
Copy link
Contributor Author

Isotr0py commented Oct 9, 2023

Yes, changing the batch size of the model on the fly will cause wrong results, because we may break the model graph on the fly.
For other tagger, change the batch size of the model on the fly will fail because they have different calculation graph.

It seems that the dynamic shape onnx model exported from original tensorflow model using onnx/tensorflow-onnx can work well:

python -m tf2onnx.convert --saved-model ./wd-v1-4-convnext-tagger-v2/ --output convnext-tagger-v2.onnx --opset 13 --verbose --inputs input_1:0[-1,448,448,3]

@Isotr0py Isotr0py deleted the onnx branch December 3, 2023 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants