Downloads · 30 days
14
10% of all-time downloads
lens-ai/adversarial-clip-vit-base-patch32_pcam_finetuned
adversarial-clip-vit-base-patch32_pcam_finetuned is a feature extraction model from lens-ai. Use it when you need embeddings to search or compare text. It is set up for transformers. The card lists the license as apache-2.0.
-This repository contains a model trained on adversarial data of the CLIP ViT Base Patch32 finetuned model on the PatchCamelyon (PCAM) dataset and also on PatchCamelyon Adversarial(PCAM) dataset.The model is optimized…
Downloads · 30 days
14
10% of all-time downloads
All-time downloads
137
Public
Repo size
1 GB
Likes
0
Public
Click a slice to open those files.
.pt1 GB · 100%
From the Hugging Face model README

-This repository contains a model trained on adversarial data of the CLIP ViT Base Patch32 finetuned model on the PatchCamelyon (PCAM) dataset and also on PatchCamelyon Adversarial(PCAM) dataset.The model is optimized for histopathological image classification.
openai/clip-vit-base-patch32Hardware: Trained on NVIDIA A100 GPU (5 epochs)
pip install transformers torch safetensors
from transformers import CLIPVisionConfig, CLIPVisionModel, CLIPFeatureExtractor
import torch
from torch import nn
class PCamClassifier(nn.Module):
def __init__(self, config_dict):
super().__init__()
self.config = CLIPVisionConfig(**config_dict)
self.vision_model = CLIPVisionModel(self.config)
self.classifier = nn.Linear(self.config.hidden_size, 2)
def forward(self, pixel_values):
outputs = self.vision_model(pixel_values)
return self.classifier(outputs.pooler_output)
# Load model
config_dict = {
"_name_or_path": "openai/clip-vit-base-patch32",
"architectures": ["CLIPVisionModel"],
"attention_dropout": 0.0,
"dropout": 0.0,
"hidden_act": "quick_gelu",
"hidden_size": 768,
"image_size": 224,
"initializer_factor": 1.0,
"initializer_range": 0.02,
"intermediate_size": 3072,
"layer_norm_eps": 1e-05,
"model_type": "clip_vision_model",
"num_attention_heads": 12,
"num_channels": 3,
"num_hidden_layers": 12,
"patch_size": 32,
"projection_dim": 512,
"torch_dtype": "float32"
}
# Initialize model
model = PCamClassifier(config_dict)
model.load_state_dict(torch.load('best_enhanced_pcam_model.pt'))
class PCamDataset(Dataset):
def __init__(self, dataset):
self.dataset = dataset
def __len__(self):
return len(self.dataset)
def __getitem__(self, idx):
example = self.dataset[idx]
image = example["image"].convert("RGB")
image_array = np.array(image) / 255.0
image_array = image_array.transpose(2, 0, 1).astype(np.float32)
return {
"pixel_values": image_array,
"labels": example["label"]
}
We plan to release:
Released under the Apache-2.0 License.
For inquiries, please reach out to Venkata Tej at LensAI.