How to interfere with this model?

#2
by johnlockejrr - opened

How to interfere with this model? Default onnx interference won't wok.

from PIL import Image
from transformers import TrOCRProcessor
import numpy as np
import onnxruntime as ort

def predict_arabic(img, model_path="gagan3012/Qalam_onnx"):
# Load the processor
processor = TrOCRProcessor.from_pretrained(model_path)

# Prepare the image
images = img.convert("RGB")
pixel_values = processor(images, return_tensors="pt", padding=True).pixel_values

# Convert PyTorch tensor to numpy array for ONNX
pixel_values = pixel_values.detach().cpu().numpy()

# Load the ONNX model
ort_session = ort.InferenceSession(f"{model_path}.onnx")

# Prepare input for ONNX model
inputs = {ort_session.get_inputs()[0].name: pixel_values}

# Run inference
generated_ids = ort_session.run(None, inputs)[0]

# Decode the generated ids
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]

return generated_text

Unused or unrecognized kwargs: padding. Traceback (most recent call last): File "/home/incognito/huggingface-source-py3.10/a.py", line 36, in ocr_text = predict_arabic(cropped_img) File "/home/incognito/huggingface-source-py3.10/a.py", line 19, in predict_arabic ort_session = ort.InferenceSession(f"{model_path}.onnx") File "/home/incognito/huggingface-source-py3.10/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 419, in init self._create_inference_session(providers, provider_options, disabled_optimizers) File "/home/incognito/huggingface-source-py3.10/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 480, in _create_inference_session sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model) onnxruntime.capi.onnxruntime_pybind11_state.NoSuchFile: [ONNXRuntimeError] : 3 : NO_SUCHFILE : Load model from gagan3012/Qalam_onnx.onnx failed:Load model gagan3012/Qalam_onnx.onnx failed. File doesn't exist

Sign up or log in to comment