-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTFAnnotation.py
More file actions
54 lines (50 loc) · 1.92 KB
/
TFAnnotation.py
File metadata and controls
54 lines (50 loc) · 1.92 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
48
49
50
51
52
53
54
import os
from object_detection.utils.dataset_util import bytes_list_feature
from object_detection.utils.dataset_util import float_list_feature
from object_detection.utils.dataset_util import int64_list_feature
from object_detection.utils.dataset_util import int64_feature
from object_detection.utils.dataset_util import bytes_feature
#Ref- https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html
class TFAnnotation:
def __init__(self):
self.xMins=[]
self.xMaxs=[]
self.yMins=[]
self.yMaxs=[]
self.textLabels=[]
self.classes=[]
self.difficult=[]
self.image=None
self.width=None
self.height=None
self.encoding=None
self.filename=None
def build(self):
w=int64_feature(self.width)
h=int64_feature(self.height)
filename=bytes_feature(self.filename.encode('utf8'))
encoding=bytes_feature(self.filename.encode('utf8'))
image=bytes_feature(self.image)
xMins=float_list_feature(self.xMins)
xMaxs=float_list_feature(self.xMaxs)
yMins=float_list_feature(self.yMins)
yMaxs=float_list_feature(self.yMaxs)
textLabels=bytes_list_feature(self.textLabels)
classes=int64_list_feature(self.classes)
difficult=int64_list_feature(self.difficult)
data={
"image/height":h,
"image/width":w,
"image/filename":filename,
"image/source_id":filename,
"image/encoded":image,
"image/format":encoding,
"image/object/bbox/xmin":xMins,
"image/object/bbox/xmax":xMaxs,
"image/object/bbox/ymin":yMins,
"image/object/bbox/ymax":yMaxs,
"image/object/class/text":textLabels,
"image/object/class/label":classes,
"image/object/difficult":difficult,
}
return data