Yifeng-Liu commited on
Commit
94f84e2
1 Parent(s): e0a73e4

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +24 -0
README.md CHANGED
@@ -98,7 +98,31 @@ Users (both direct and downstream) should be made aware of the risks, biases and
98
  Use the code below to get started with the model.
99
  ```python
100
  from transformers import AutoModelForObjectDetection, AutoImageProcessor
 
 
 
 
 
 
101
 
102
  model = AutoModelForObjectDetection.from_pretrained("Yifeng-Liu/rt-detr-finetuned-for-satellite-image-roofs-detection")
103
  image_processor = AutoImageProcessor.from_pretrained("Yifeng-Liu/rt-detr-finetuned-for-satellite-image-roofs-detection")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  ```
 
98
  Use the code below to get started with the model.
99
  ```python
100
  from transformers import AutoModelForObjectDetection, AutoImageProcessor
101
+ import torch
102
+
103
+ image_path=YOUR_IMAGE_PATH
104
+ image = cv2.imread(image_path)
105
+
106
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
107
 
108
  model = AutoModelForObjectDetection.from_pretrained("Yifeng-Liu/rt-detr-finetuned-for-satellite-image-roofs-detection")
109
  image_processor = AutoImageProcessor.from_pretrained("Yifeng-Liu/rt-detr-finetuned-for-satellite-image-roofs-detection")
110
+
111
+
112
+ CONFIDENCE_TRESHOLD = 0.5
113
+
114
+ with torch.no_grad():
115
+ model.to(device)
116
+
117
+ # load image and predict
118
+ inputs = image_processor(images=image, return_tensors='pt').to(device)
119
+ outputs = model(**inputs)
120
+
121
+ # post-process
122
+ target_sizes = torch.tensor([image.shape[:2]]).to(device)
123
+ results = image_processor.post_process_object_detection(
124
+ outputs=outputs,
125
+ threshold=CONFIDENCE_TRESHOLD,
126
+ target_sizes=target_sizes
127
+ )[0]
128
  ```