-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombine_results.py
64 lines (55 loc) · 2.13 KB
/
combine_results.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
import pandas as pd
import os
import argparse
import collections
parser = argparse.ArgumentParser(description='Hyperparams')
parser.add_argument('--file_path_empty', nargs='?', type=str, default='',
help='CSV file path for empty masks')
parser.add_argument('--file_path_non_empty', nargs='?', type=str, default='',
help='CSV file path for non-empty masks')
args = parser.parse_args()
print(args)
root_path = os.path.join('results_combined')
if not os.path.exists(root_path):
os.makedirs(root_path)
##leak_df = pd.read_csv(os.path.join('..', 'datasets', 'siim', 'sample_submission_leak.csv'), index_col=0)
empty_df = pd.read_csv(args.file_path_empty, index_col=0)
non_empty_df = pd.read_csv(args.file_path_non_empty, index_col=0)
empty_dict = empty_df.to_dict('index')
non_empty_dict = non_empty_df.to_dict('index')
new_dict = collections.OrderedDict()
num_empty = 0
missed_non_empty = 0
num_non_empty = 0
##num_leak = 0
for d in empty_dict:
"""
if len(leak_df[leak_df.index == d]['EncodedPixels']) > 1:
num_leak += 1
non_empty_mask = non_empty_dict[d]['EncodedPixels']
if '0 1' in non_empty_mask[:3]:
missed_non_empty += 1
new_dict[d] = '-1'
else:
new_dict[d] = non_empty_mask
num_non_empty += 1
continue
#"""
if '-1' in empty_dict[d]['EncodedPixels']:
new_dict[d] = '-1'
num_empty += 1
else:
non_empty_mask = non_empty_dict[d]['EncodedPixels']
if '0 1' in non_empty_mask[:3]:
missed_non_empty += 1
new_dict[d] = '-1'
else:
new_dict[d] = non_empty_mask
num_non_empty += 1
print('empty: {}; non-empty: {}; missed non-empty: {}'.format(num_empty, num_non_empty, missed_non_empty))
##print('empty: {}; non-empty: {}; missed non-empty: {}; leak: {}'.format(num_empty, num_non_empty, missed_non_empty, num_leak))
sub = pd.DataFrame.from_dict(new_dict, orient='index')
sub.index.names = ['ImageId']
sub.columns = ['EncodedPixels']
sub.to_csv(os.path.join(root_path, 'combined.csv'))
##sub.to_csv(os.path.join(root_path, 'combined+leak.csv'))