REVA-QCAV/submit.py
milesial 8008b77af6 Removed unused function and general cleanup
Former-commit-id: c34a455f1722e0b899e9e92c7766b83a9a641980
2018-04-09 05:15:24 +02:00

27 lines
689 B
Python

# used to predict all test images and encode results in a csv file
from predict import *
from unet import UNet
def submit(net, gpu=False):
dir = 'data/test/'
N = len(list(os.listdir(dir)))
with open('SUBMISSION.csv', 'a') as f:
f.write('img,rle_mask\n')
for index, i in enumerate(os.listdir(dir)):
print('{}/{}'.format(index, N))
img = Image.open(dir + i)
mask = predict_img(net, img, gpu)
enc = rle_encode(mask)
f.write('{},{}\n'.format(i, ' '.join(map(str, enc))))
if __name__ == '__main__':
net = UNet(3, 1).cuda()
net.load_state_dict(torch.load('MODEL.pth'))
submit(net, True)