Cat2Real-DINOv3-384

Cat2Real-DINOv3-384 is a product image embedding model fine-tuned from DINOv3. It maps the real-world product images and catalog packshots to the same embedding space for similarity search.

How to Get Started with the Model

The example below demonstrates how to obtain an image embedding with the [AutoModel] class.

import torch
import cv2
import numpy as np
from torchvision import transforms
from transformers import AutoImageProcessor, AutoModel

def padding(img):
    """
    :param img: take the image as input, np.uint8 format, [0-255] range
    :return: img: square image with white pixel padded along the shorter side.
    """
    h, w, _ = img.shape
    if h > w:
        new_img = 255 * np.ones((h, h, 3)).astype(np.uint8)
        start_w = int((h-w)/2)
        new_img[:, start_w:start_w+w, :] = img
        return new_img

    elif h < w:
        new_img = 255 * np.ones((w, w, 3)).astype(np.uint8)
        start_h = int((w - h) / 2)
        new_img[start_h:start_h + h, :, :] = img
        return new_img
    else:
        return img

image_path = "your local image path"
dim = 384
image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = padding(image)
image = cv2.resize(image, (dim, dim))
transform = transforms.ToTensor()
image = transform(image)
image = image.unsqueeze(0)
model_name = "zhanganyi88/Cat2Real-DINOv3-384"
processor = AutoImageProcessor.from_pretrained(model_name)
model = AutoModel.from_pretrained(
    model_name, 
    device_map="auto", 
)
inputs = processor(images=image, return_tensors="pt").to(model.device)
with torch.inference_mode():
    outputs = model(**inputs)
embedding = outputs.pooler_output
print("embedding shape:", embedding.shape)
Downloads last month
41
Safetensors
Model size
0.3B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for zhanganyi88/Cat2Real-DINOv3-384