Instructions to use Arioron/Vex-OncoDetect-BC-CT-Fusion with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Arioron/Vex-OncoDetect-BC-CT-Fusion with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Arioron/Vex-OncoDetect-BC-CT-Fusion", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download tester.py from Arioron/Vex-OncoDetect-BC-CT-Fusion: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/Arioron/Vex-OncoDetect-BC-CT-Fusion/resolve/main/tester.py
- Command line
-
hf download hf://Arioron/Vex-OncoDetect-BC-CT-Fusion/tester.py
-
curl -L -o tester.py https://huggingface.co/Arioron/Vex-OncoDetect-BC-CT-Fusion/resolve/main/tester.py
1.34 kB
| import torch | |
| import torch.nn as nn | |
| from torchvision import transforms | |
| import timm | |
| from PIL import Image | |
| device = 'cuda' | |
| processor = transforms.Compose([ | |
| transforms.Resize((224, 224)), | |
| transforms.ToTensor(), | |
| transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) | |
| ]) | |
| class SwinBinaryClassifier(nn.Module): | |
| def __init__(self): | |
| super().__init__() | |
| self.backbone = timm.create_model('swin_tiny_patch4_window7_224', pretrained=False, num_classes=0) | |
| in_f = self.backbone.num_features | |
| self.classifier = nn.Linear(in_f, 1) | |
| def forward(self, x): | |
| x = self.backbone(x) | |
| return self.classifier(x) | |
| model = SwinBinaryClassifier().to(device) | |
| model.load_state_dict(torch.load('./breastcancer_model.pth')) | |
| image = Image.open('./tests/Benign Masses/20586908 (12)_Benign.png').convert("RGB") | |
| input_tensor = processor(image) | |
| input_batch = input_tensor.unsqueeze(0) # Add a batch dimension | |
| # Move the input and model to GPU if available | |
| if torch.cuda.is_available(): | |
| input_batch = input_batch.to('cuda') | |
| model.to('cuda') | |
| # Make a prediction | |
| with torch.no_grad(): | |
| output = model(input_batch) | |
| preds = (torch.sigmoid(output) > 0.5).int() | |
| classes = ['Benign', 'Malignant'] | |
| # Print the predicted class | |
| print(f'Predicted class: {classes[preds]}') |