-
Notifications
You must be signed in to change notification settings - Fork 2
/
noisy_labels_AN_VOC.py
49 lines (42 loc) · 1.38 KB
/
noisy_labels_AN_VOC.py
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
import numpy as np
import json
def unjson(file):
with open(file, 'r') as fo:
dict = json.load(fo)
return dict
# r is noise rate
r = 0.2
count = 0
p_a = ''
p_g = ''
a = unjson(p_a)
for i in range(len(a['annotations'])):
if np.random.random() < r:
# bird -> aeroplane
if a['annotations'][i]['category_id'] == 3:
a['annotations'][i]['category_id'] = 1
# diningtable -> chair
elif a['annotations'][i]['category_id'] == 11:
a['annotations'][i]['category_id'] = 9
# bus -> car
elif a['annotations'][i]['category_id'] == 6:
a['annotations'][i]['category_id'] = 7
# sheep -> horse
elif a['annotations'][i]['category_id'] == 17:
a['annotations'][i]['category_id'] = 13
# bicycle -> motorbike
elif a['annotations'][i]['category_id'] == 2:
a['annotations'][i]['category_id'] = 14
# motorbike -> bicycle
elif a['annotations'][i]['category_id'] == 14:
a['annotations'][i]['category_id'] = 2
# cat -> dog
elif a['annotations'][i]['category_id'] == 8:
a['annotations'][i]['category_id'] = 12
# dog -> cat
elif a['annotations'][i]['category_id'] == 12:
a['annotations'][i]['category_id'] = 8
count += 1
with open(p_g, 'w') as file:
json.dump(a, file)
print(count)