fancyfeast
commited on
Commit
·
8997b7a
1
Parent(s):
c6034c4
Ooops, forgot no GPU on this instance
Browse files
app.py
CHANGED
|
@@ -30,7 +30,7 @@ class DetectorModelOwl(nn.Module):
|
|
| 30 |
self.linear2 = nn.Linear(n_hidden * 2, 2)
|
| 31 |
|
| 32 |
def forward(self, pixel_values: torch.Tensor, labels: torch.Tensor | None = None):
|
| 33 |
-
with torch.autocast("
|
| 34 |
# Embed the image
|
| 35 |
outputs = self.owl(pixel_values=pixel_values, output_hidden_states=True)
|
| 36 |
x = outputs.last_hidden_state # B, N, C
|
|
@@ -74,7 +74,7 @@ def owl_predict(image: Image.Image) -> bool:
|
|
| 74 |
input_image = TVF.normalize(preped, [0.48145466, 0.4578275, 0.40821073], [0.26862954, 0.26130258, 0.27577711])
|
| 75 |
|
| 76 |
# Run
|
| 77 |
-
logits, = model(input_image.to('
|
| 78 |
probs = F.softmax(logits, dim=1)
|
| 79 |
prediction = torch.argmax(probs.cpu(), dim=1)
|
| 80 |
|
|
@@ -106,7 +106,6 @@ def predict(image: Image.Image, conf_threshold: float):
|
|
| 106 |
model = DetectorModelOwl("google/owlv2-base-patch16-ensemble", dropout=0.0)
|
| 107 |
model.load_state_dict(torch.load("far5y1y5-8000.pt", map_location="cpu"))
|
| 108 |
model.eval()
|
| 109 |
-
model.cuda()
|
| 110 |
|
| 111 |
# Load YOLO model
|
| 112 |
yolo_model = YOLO("yolo11x-train28-best.pt")
|
|
|
|
| 30 |
self.linear2 = nn.Linear(n_hidden * 2, 2)
|
| 31 |
|
| 32 |
def forward(self, pixel_values: torch.Tensor, labels: torch.Tensor | None = None):
|
| 33 |
+
with torch.autocast("cpu", dtype=torch.bfloat16):
|
| 34 |
# Embed the image
|
| 35 |
outputs = self.owl(pixel_values=pixel_values, output_hidden_states=True)
|
| 36 |
x = outputs.last_hidden_state # B, N, C
|
|
|
|
| 74 |
input_image = TVF.normalize(preped, [0.48145466, 0.4578275, 0.40821073], [0.26862954, 0.26130258, 0.27577711])
|
| 75 |
|
| 76 |
# Run
|
| 77 |
+
logits, = model(input_image.to('cpu').unsqueeze(0), None)
|
| 78 |
probs = F.softmax(logits, dim=1)
|
| 79 |
prediction = torch.argmax(probs.cpu(), dim=1)
|
| 80 |
|
|
|
|
| 106 |
model = DetectorModelOwl("google/owlv2-base-patch16-ensemble", dropout=0.0)
|
| 107 |
model.load_state_dict(torch.load("far5y1y5-8000.pt", map_location="cpu"))
|
| 108 |
model.eval()
|
|
|
|
| 109 |
|
| 110 |
# Load YOLO model
|
| 111 |
yolo_model = YOLO("yolo11x-train28-best.pt")
|