-
Notifications
You must be signed in to change notification settings - Fork 5
/
patch_sub3.py
executable file
·71 lines (50 loc) · 2.05 KB
/
patch_sub3.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python3.6
''' Patches the submission. '''
import json
import pickle
import sys
import numpy as np
import pandas as pd
from tqdm import tqdm
from debug import dprint
if len(sys.argv) != 3:
print(f'usage: {sys.argv[0]} dest.csv source.csv')
sys.exit()
sub = pd.read_csv(sys.argv[2])
with open('imagenet1000.txt') as f:
imagenet = eval(f.read())
categories = list(imagenet.values())
with open('imagenet_classes.pkl', 'rb') as ff:
predicts = pickle.load(ff)
predicts = np.vstack(predicts)
classes = np.argmax(predicts, axis=1)
imagenet_classes = [categories[classes[i]] for i in range(predicts.shape[0])]
imagenet_indices = [classes[i] for i in range(predicts.shape[0])]
confs = [predicts[i, classes[i]] for i in range(predicts.shape[0])]
MIN_CONF = 0.7
for i in tqdm(range(sub.shape[0])):
index = sub.index.values[i]
class_, conf = imagenet_classes[index], confs[index]
if conf < MIN_CONF:
continue
for c in ['warplane', 'coil', 'missile', 'conch', 'gar', 'tank',
'schooner', 'book jacket', 'scabbard', 'aircraft carrier',
'school bus', 'space shuttle', 'cannon',
'trilobite', 'tow truck', 'submarine', 'pickup', 'amphibian',
'marmot', 'mushroom', 'shield', 'French loaf',
'poncho', 'warthog']:
if class_.startswith(c + ','):
sub.landmarks.iloc[i] = ''
# for c in ['warplane', 'coil', 'missile', 'conch', 'gar', 'tank',
# 'schooner', 'book jacket', 'scabbard', 'aircraft carrier',
# 'school bus', 'trolley bus', 'space shuttle', 'cannon',
# 'trilobite', 'tow truck', 'submarine', 'pickup', 'amphibian',
# 'marmot', 'mushroom', 'passenger car', 'shield', 'French loaf',
# 'poncho', 'warthog']:
# if class_.startswith(c + ','):
# sub.landmarks.iloc[i] = ''
if imagenet_indices[index] < 400:
sub.landmarks.iloc[i] = ''
if imagenet_indices[index] >= 985:
sub.landmarks.iloc[i] = ''
sub.to_csv(sys.argv[1], index=False)