Spaces:
Build error
Build error
Trang Dang
commited on
Commit
•
67507fb
1
Parent(s):
f1ded9c
upload
Browse files
run.py
CHANGED
@@ -34,18 +34,18 @@ def pred(src):
|
|
34 |
my_sam_model.load_state_dict(torch.load("sam_model.pth", map_location=torch.device('cpu')))
|
35 |
|
36 |
new_image = np.array(Image.open(src))
|
37 |
-
inputs = processor(new_image, return_tensors="pt")
|
38 |
-
my_sam_model.eval()
|
39 |
-
|
40 |
-
# forward pass
|
41 |
-
with torch.no_grad():
|
42 |
-
|
43 |
-
|
44 |
-
# apply sigmoid
|
45 |
-
single_patch_prob = torch.sigmoid(outputs.pred_masks.squeeze(1))
|
46 |
-
# convert soft mask to hard mask
|
47 |
-
single_patch_prob = single_patch_prob.cpu().numpy().squeeze()
|
48 |
-
single_patch_prediction = (single_patch_prob > 0.5).astype(np.uint8)
|
49 |
# patches = customized_patchify(new_image)
|
50 |
|
51 |
# # Define the size of your array
|
|
|
34 |
my_sam_model.load_state_dict(torch.load("sam_model.pth", map_location=torch.device('cpu')))
|
35 |
|
36 |
new_image = np.array(Image.open(src))
|
37 |
+
# inputs = processor(new_image, return_tensors="pt")
|
38 |
+
# my_sam_model.eval()
|
39 |
+
|
40 |
+
# # forward pass
|
41 |
+
# with torch.no_grad():
|
42 |
+
# outputs = my_sam_model(**inputs, multimask_output=False)
|
43 |
+
|
44 |
+
# # apply sigmoid
|
45 |
+
# single_patch_prob = torch.sigmoid(outputs.pred_masks.squeeze(1))
|
46 |
+
# # convert soft mask to hard mask
|
47 |
+
# single_patch_prob = single_patch_prob.cpu().numpy().squeeze()
|
48 |
+
# single_patch_prediction = (single_patch_prob > 0.5).astype(np.uint8)
|
49 |
# patches = customized_patchify(new_image)
|
50 |
|
51 |
# # Define the size of your array
|