Comments (3)
@solomonmanuelraj Could you explain what would you like to be supported?
optimum-cli export onnx -m google/owlvit-base-patch32 owlvit_onnx
& e.g.
optimum-cli onnxruntime quantize --onnx_model owlvit_onnx --output owlvit_onnx_quantized --avx512
should work. This uses dynamic quantization. The quality of the quantized model is not guaranteed though, you would need to evaluate that. For more custom usage, you would need to use the python API:
https://huggingface.co/docs/optimum/main/en/onnxruntime/usage_guides/quantization & https://huggingface.co/docs/optimum/main/en/onnxruntime/package_reference/quantization & https://huggingface.co/docs/optimum/main/en/onnxruntime/package_reference/configuration#optimum.onnxruntime.QuantizationConfig
from optimum.
@fxmarty , thanks for your quick response. yes i used your above code for the dynamic quantization on the owl-vit model.
when i refer (https://www.philschmid.de/optimizing-transformers-with-optimum - 5. Test inference with the quantized model) web page they use specific classes like (e.g. ORTModelForSequenceClassification ) to load the optimized model for inference purpose.
For zero shot object detection task we do not have ORTModelForZeroShotObjectDetection class which can be used to load the quantized onnx model for the inference purpose.
To evaluate the performance and speed evaluators are available for text_classification tasks,
##########################################################################################
rom evaluate import evaluator
from datasets import load_dataset
eval = evaluator("text-classification")
eval_dataset = load_dataset("banking77", split="test")
results = eval.compute(
model_or_pipeline=q8_clf,
data=eval_dataset,
metric="accuracy",
input_column="text",
label_column="label",
label_mapping=model.config.label2id,
strategy="simple",
)
print(results)
#####################################################################################
like to know for zeroshotobject detection task similar evaluator is available or not?
your reference will be useful
thanks
from optimum.
First, investigating this issue I found out there was an issue in the ONNX export of owlvit due to the usage of numpy in the modeling code and fixed in huggingface/transformers#29326. Please install Transformers from source as this is not yet in a release.
Then, here is an example of usage: optimum-cli export onnx --model google/owlvit-base-patch32 --task zero-shot-object-detection owlvit_onnx
and
import requests
from PIL import Image
import torch
from optimum.onnxruntime import ORTModelForCustomTasks
from transformers import AutoProcessor
processor = AutoProcessor.from_pretrained("google/owlvit-base-patch32")
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
texts = [["a photo of a cat", "a photo of a dog", "me", "hey"]]
inputs = processor(text=texts, images=image, return_tensors="pt")
model = ORTModelForCustomTasks.from_pretrained("/path/to/owlvit_onnx")
inputs = processor(text=texts, images=image, return_tensors="pt")
outputs = model(**inputs)
# Target image sizes (height, width) to rescale box predictions [batch_size, 2]
target_sizes = torch.Tensor([image.size[::-1]])
# Convert outputs (bounding boxes and class logits) to final bounding boxes and scores
results = processor.post_process_object_detection(
outputs=outputs, threshold=0.1, target_sizes=target_sizes
)
using https://huggingface.co/docs/optimum/main/en/onnxruntime/package_reference/modeling_ort#optimum.onnxruntime.ORTModelForCustomTasks that is able to handle ONNX models with arbitrary inputs/outputs.
from optimum.
Related Issues (20)
- Native Support for Gemma HOT 5
- Flash Attention v2 for Roberta-large HOT 5
- Issue converting owlv2 model to ONNX format HOT 4
- Optimum for Jetson Orin Nano HOT 1
- 似乎不支持cpu HOT 2
- Llama-2-7b is failing with bfloat16 export with onnx HOT 1
- changes to _maybe_log_save_evaluate() not reflected in optimum repo HOT 1
- 'gemma is not supported yet with the onnx backend' - Exporting on-the-fly to onnx HOT 8
- Gemma Onnx suuport HOT 5
- tflite support for gemma HOT 1
- [BUG] Mistral feature extraction export to ONNX is broken HOT 5
- [BUG] Mistral feature extraction export to ONNX is broken
- [BUG] Cannot export Gemma/Mistral to ONNX/TensorRT using INT8 HOT 9
- Cannot download ONNX external data file from Hugging Face Hub HOT 4
- Cannot download from private repository on Hugging Face using optimum 1.17 HOT 3
- onnx model issue for zeroshot facebook/bart-large-mnli HOT 1
- Mixtral-8x7B-Instruct-v0.1-GPTQ AssertionError HOT 6
- OnnxSlim support
- NoSuchFile: [ONNXRuntimeError] : 3 : NO_SUCHFILE : Load model from data/data_onnx/model.onnx failed:Load model data/data_onnx/model.onnx failed. File doesn't exist HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from optimum.