Views
No views yet
convnextv2_base model (via timm), fine-tuned to classify images as real vs. AI-generated, with training specifically adapted for content that has passed through social media platforms (Facebook, Instagram, TikTok).ComplexDataLab/OpenFake's reddit config (real photos from photography subreddits, AI-generated images from AI-generation subreddits — carrying actual platform compression rather than simulated artifacts).1import torch
2import timm
3from huggingface_hub import hf_hub_download
4
5REPO_ID = "your-username/convnext-ai-detector-finetuned" # <-- replace with your actual repo id
6WEIGHTS_FILENAME = "best_convnext_v2_model.pth"
7
8weights_path = hf_hub_download(repo_id=REPO_ID, filename=WEIGHTS_FILENAME)
9
10model = timm.create_model("convnextv2_base", pretrained=False, num_classes=2)
11state_dict = torch.load(weights_path, map_location="cpu")
12model.load_state_dict(state_dict)
13model.eval()1from torchvision import transforms
2
3_convnext_mean = (0.485, 0.456, 0.406)
4_convnext_std = (0.229, 0.224, 0.225)
5
6infer_transform = transforms.Compose([
7 transforms.Resize(288, interpolation=transforms.InterpolationMode.LANCZOS),
8 transforms.CenterCrop(256),
9 transforms.ToTensor(),
10 transforms.Normalize(_convnext_mean, _convnext_std),
11])1from PIL import Image
2import torch.nn.functional as F
3
4image = Image.open("your_image.jpg").convert("RGB")
5tensor = infer_transform(image).unsqueeze(0)
6
7with torch.no_grad():
8 logits = model(tensor)
9 probs = F.softmax(logits, dim=1)[0]
10
11print(probs) # see "Class order" below for how to read thistorchvision.datasets.ImageFolder, which assigns class indices alphabetically by folder name. The training notebook prints this at runtime as Classes found: [...].| Index | Class |
|---|---|
| 0 | <class_0_name> (e.g. ai) |
| 1 | <class_1_name> (e.g. real) |
convnextv2_base (ImageNet-pretrained, fully fine-tuned)3e-5, cosine annealing schedulereddit-sourced portion of training data is licensed CC-BY-NC-4.0 for its proprietary-generator subsets — check licensing before commercial use of this model.