File size: 2,364 Bytes
99ddb81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
license: cc-by-4.0
library_name: transformers
tags:
- style-similarity
- feature-extraction
- image-feature-extraction
- csd
pipeline_tag: image-feature-extraction
---

# CSD (ViT-L/14) — HuggingFace format

Unofficial `transformers`-format port of the **CSD** style model from *"Measuring Style
Similarity in Diffusion Models"* (Somepalli, Gupta, Gupta, Shrivastava, Goldstein, Feizi;
2024). Loads via `trust_remote_code` with **no `clip` / `open_clip` runtime dependency** —
the OpenAI CLIP ViT-L/14 vision tower is vendored into `modeling_csd.py` and the released
CSD weights are stored as `model.safetensors`.

> **Not an official release.** Original code: https://github.com/learn2phoenix/CSD (MIT).
> Official checkpoint mirror: https://huggingface.co/tomg-group-umd/CSD-ViT-L (CC-BY-4.0).
> This repo repackages that checkpoint for `AutoModel.from_pretrained`.

## What it is

A CLIP ViT-L/14 vision backbone (projection removed) whose pre-projection feature (1024-d)
is mapped by a learned **style** head and a **content** head to 768-d descriptors, each
L2-normalized. Style similarity between two images is the cosine of their style embeddings.

## Usage

```python
import torch
from PIL import Image
from transformers import AutoModel, AutoImageProcessor

model = AutoModel.from_pretrained("bigshanedogg/CSD", trust_remote_code=True).eval()
proc = AutoImageProcessor.from_pretrained("bigshanedogg/CSD", trust_remote_code=True)

px = proc(images=Image.open("a.png"), return_tensors="pt")["pixel_values"]
out = model(pixel_values=px)
style = out.embeddings            # (1, 768), L2-normalized style descriptor
content = out.content_embeddings  # (1, 768), L2-normalized content descriptor
```

The image processor resizes the short side to 224 (BICUBIC), center-crops 224, and applies
the CLIP mean/std — matching the upstream CSD preprocessing.

## Licensing

- Port (modeling/config/processing): **MIT** — Copyright (c) 2026 bigshanedogg.
- CSD original code: **MIT** — Copyright (c) 2023 the CSD authors (https://github.com/learn2phoenix/CSD).
- Released CSD weights (`model.safetensors`, from `tomg-group-umd/CSD-ViT-L`): **CC-BY-4.0** —
  attribute Somepalli et al. / University of Maryland.
- Vendored ViT tower: **MIT** — Copyright (c) 2021 OpenAI (https://github.com/openai/CLIP), MODIFIED.

See `LICENSE` for the full notices.