Views
No views yet
Training data: ImageNet-1K.
FeatureExtractor (edges, color segmentation, grayscale histogram).224×224 unless you trained otherwise).model.safetensors.1import torch
2from huggingface_hub import hf_hub_download
3from safetensors.torch import load_file
4
5# 1) Import your model & config from the VisualSplit repo
6from visualsplit.models.CrossViT import CrossViTForPreTraining, CrossViTConfig
7from visualsplit.utils import FeatureExtractor
8
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
11# 2) Build a config matching your training (edit if you changed widths/depths)
12config = CrossViTConfig(
13 image_size=224, # change if your training size differs
14 patch_size=16,
15 # ... any other config fields your repo exposes
16)
17
18model = CrossViTForPreTraining(config).to(device)
19model.eval()
20
21# 3) Download and load state dict from this model repo
22# Replace REPO_ID with your Hugging Face model id, e.g. "HenryQUQ/visualsplit")
23ckpt_path = hf_hub_download(repo_id="REPO_ID", filename="model.safetensors")
24state_dict = load_file(ckpt_path)
25missing, unexpected = model.load_state_dict(state_dict, strict=False)
26print("Missing keys:", missing)
27print("Unexpected keys:", unexpected)
28
29# 4) Prepare an input image and extract descriptors
30from PIL import Image
31from torchvision import transforms
32
33image = Image.open("input.jpg").convert("RGB")
34transform = transforms.Compose([
35 transforms.Resize((config.image_size, config.image_size)),
36 transforms.ToTensor(),
37])
38pixel_values = transform(image).unsqueeze(0).to(device) # (1, 3, H, W)
39
40# FeatureExtractor provided by the repo should return the required tensors
41extractor = FeatureExtractor().to(device)
42with torch.no_grad():
43 edge, gray_hist, segmented_rgb, _ = extractor(pixel_values)
44
45# 5) Run inference (reconstruction)
46with torch.no_grad():
47 outputs = model(
48 source_edge=edge,
49 source_gray_level_histogram=gray_hist,
50 source_segmented_rgb=segmented_rgb,
51 )
52# Your repo’s forward returns may differ; adjust the key accordingly:
53reconstructed = outputs["logits_reshape"] # (1, 3, H, W)
54
55# 6) Convert to PIL for visualisation
56to_pil = transforms.ToPILImage()
57recon_img = to_pil(reconstructed.squeeze(0).cpu().clamp(0, 1))
58recon_img.save("reconstructed.png")
59print("Saved to reconstructed.png")notebook/validation.ipynb)FeatureExtractor to compute edges, color-segmented RGB, and grayscale histograms,1# clone the VisualSplit code
2git clone https://github.com/HenryQUQ/VisualSplit.git
3cd VisualSplit
4# pip install -e .This repository only hosts the trained checkpoint for inference. Follow the GitHub repo for the full training pipeline and data preparation scripts.
1@inproceedings{Qu2025VisualSplit,
2 title = {Exploring Image Representation with Decoupled Classical Visual Descriptors},
3 author = {Qu, Chenyuan and Chen, Hao and Jiao, Jianbo},
4 booktitle = {British Machine Vision Conference (BMVC)},
5 year = {2025}
6}