Views
No views yet
1from transformers import AutoModelForImageClassification
2import torch
3
4# Load model for feature extraction
5model = AutoModelForImageClassification.from_pretrained(
6 "BiliSakura/MoCo-TP-ResNet-50",
7 trust_remote_code=True
8)
9
10# Inference - extract features
11model.eval()
12input_image = torch.randn(1, 3, 224, 224) # (batch, channels, height, width)
13
14with torch.no_grad():
15 outputs = model(pixel_values=input_image, return_dict=True)
16 features = outputs["features"] # Shape: (1, 2048)1from transformers import AutoModelForImageClassification, AutoConfig
2import torch.nn as nn
3
4# Load config and modify num_labels
5config = AutoConfig.from_pretrained(
6 "BiliSakura/MoCo-TP-ResNet-50",
7 trust_remote_code=True
8)
9config.num_labels = 10 # Your number of classes
10
11# Load model
12model = AutoModelForImageClassification.from_pretrained(
13 "BiliSakura/MoCo-TP-ResNet-50",
14 config=config,
15 trust_remote_code=True
16)
17
18# The model will automatically replace the identity head with a classification head
19# Now you can fine-tune on your dataset1@article{ayush2021geography,
2 title={Geography-Aware Self-Supervised Learning},
3 author={Ayush, Kumar and Uzkent, Burak and Meng, Chenlin and Tanmay, Kumar and Burke, Marshall and Lobell, David and Ermon, Stefano},
4 journal={ICCV},
5 year={2021}
6}