Commit
·
79eafc7
1
Parent(s):
ea9668d
Update custom_node_furniture_mask.py
Browse files
custom_node_furniture_mask.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
import torch
|
3 |
import torchvision.transforms as T
|
4 |
from torchvision.models.segmentation import deeplabv3_resnet50
|
|
|
5 |
|
6 |
class FurnitureMaskNode:
|
7 |
def __init__(self):
|
@@ -27,12 +28,16 @@ class FurnitureMaskNode:
|
|
27 |
CATEGORY = "custom"
|
28 |
|
29 |
def detect_furniture(self, input_image):
|
|
|
30 |
input_tensor = self.transforms(input_image).unsqueeze(0)
|
31 |
with torch.no_grad():
|
32 |
output = self.model(input_tensor)['out'][0]
|
33 |
output_predictions = output.argmax(0)
|
34 |
|
35 |
-
non_furniture_classes =
|
|
|
|
|
|
|
36 |
mask = torch.zeros_like(output_predictions, dtype=torch.bool)
|
37 |
for cls in non_furniture_classes:
|
38 |
mask |= (output_predictions == cls)
|
|
|
2 |
import torch
|
3 |
import torchvision.transforms as T
|
4 |
from torchvision.models.segmentation import deeplabv3_resnet50
|
5 |
+
from PIL import Image
|
6 |
|
7 |
class FurnitureMaskNode:
|
8 |
def __init__(self):
|
|
|
28 |
CATEGORY = "custom"
|
29 |
|
30 |
def detect_furniture(self, input_image):
|
31 |
+
input_image = Image.fromarray((input_image * 255).astype('uint8'))
|
32 |
input_tensor = self.transforms(input_image).unsqueeze(0)
|
33 |
with torch.no_grad():
|
34 |
output = self.model(input_tensor)['out'][0]
|
35 |
output_predictions = output.argmax(0)
|
36 |
|
37 |
+
non_furniture_classes = list(range(1, 151)) # Adjust the range based on ADE20K classes
|
38 |
+
furniture_classes = [5, 10, 20, 25, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71] # Based on ADE20K
|
39 |
+
non_furniture_classes = [cls for cls in non_furniture_classes if cls not in furniture_classes]
|
40 |
+
|
41 |
mask = torch.zeros_like(output_predictions, dtype=torch.bool)
|
42 |
for cls in non_furniture_classes:
|
43 |
mask |= (output_predictions == cls)
|