Download Objectdetection/model_loader.py from Goutham204/Object_detection: direct link, hf CLI and curl.
- Browser
- Download file 517 Bytes
-
https://huggingface.co/Goutham204/Object_detection/resolve/c20cd657ed6454ff69ee811cfeccee00a6e07b6e/Objectdetection/model_loader.py
- Command line
-
hf download hf://Goutham204/Object_detection@c20cd657ed6454ff69ee811cfeccee00a6e07b6e/Objectdetection/model_loader.py
-
curl -L -o model_loader.py https://huggingface.co/Goutham204/Object_detection/resolve/c20cd657ed6454ff69ee811cfeccee00a6e07b6e/Objectdetection/model_loader.py
517 Bytes
| import torch | |
| import torchvision | |
| from torchvision.models.detection.faster_rcnn import FastRCNNPredictor | |
| def get_model(num_classes): | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True) | |
| in_features = model.roi_heads.box_predictor.cls_score.in_features | |
| model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes) | |
| model.to(device) | |
| model.eval() | |
| return model, device | |