forked from ScanNet/ScanNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance.py
More file actions
47 lines (39 loc) · 1.34 KB
/
instance.py
File metadata and controls
47 lines (39 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
#
# Instance class
#
class Instance(object):
instID = 0
labelID = 0
pixelCount = 0
medDist = -1
distConf = 0.0
def __init__(self, imgNp, instID):
if (instID == -1):
return
self.instID = int(instID)
self.labelID = int(self.getLabelID(instID))
self.pixelCount = int(self.getInstancePixels(imgNp, instID))
def getLabelID(self, instID):
return int(instID // 1000)
def getInstancePixels(self, imgNp, instLabel):
return (imgNp == instLabel).sum()
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
def toDict(self):
buildDict = {}
buildDict["instID"] = self.instID
buildDict["labelID"] = self.labelID
buildDict["pixelCount"] = self.pixelCount
buildDict["medDist"] = self.medDist
buildDict["distConf"] = self.distConf
return buildDict
def fromJSON(self, data):
self.instID = int(data["instID"])
self.labelID = int(data["labelID"])
self.pixelCount = int(data["pixelCount"])
if ("medDist" in data):
self.medDist = float(data["medDist"])
self.distConf = float(data["distConf"])
def __str__(self):
return "("+str(self.instID)+")"