RAM++ (ONNX)

ONNX export of ram_plus_swin_large_14m.pth from xinyu1205/recognize-anything-plus-model.

Usage

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

session = ort.InferenceSession("onnx/vision_model_fp16.onnx", providers=["CUDAExecutionProvider", "CPUExecutionProvider"])
label_embed = np.load("tag_embeddings.npy")
tags = open("ram_tag_list.txt", encoding="utf-8").read().splitlines()
thresholds = np.loadtxt("ram_tag_list_threshold.txt")

image = Image.open("image.jpg").convert("RGB").resize((384, 384), Image.BILINEAR)
pixel_values = (np.asarray(image, np.float32) / 255).transpose(2, 0, 1)[None]

scores = session.run(["tag_scores"], {"pixel_values": pixel_values, "label_embed": label_embed})[0][0]
print(" | ".join(t for t, s, th in zip(tags, scores, thresholds) if s > th))

Notes

  • ImageNet normalization is inside the graph.
  • tag_embeddings.npy holds the label embeddings of the 4585 standard tags in the order of ram_tag_list.txt. Pass a subset of rows to score only some tags.
  • Files: onnx/vision_model.onnx (fp32), _fp16 (fp16 weights, float32 I/O), _int8 (8-bit weight-only MatMulNBits, requires ONNX Runtime). Opset 23 (ONNX Runtime 1.22+).
  • Changes from the original: precomputed the standard tag embeddings and exposed them as an input; the computation is unchanged.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for AX1Y2JP/recognize-anything-plus-model-ONNX

Quantized
(3)
this model