2017-11-30 06:19:52 +00:00
|
|
|
# used to predict all test images and encode results in a csv file
|
2017-09-26 19:00:51 +00:00
|
|
|
|
2017-08-21 16:00:07 +00:00
|
|
|
import os
|
|
|
|
from PIL import Image
|
|
|
|
from predict import *
|
|
|
|
from utils import encode
|
2017-11-30 05:45:19 +00:00
|
|
|
from unet import UNet
|
2017-08-21 16:00:07 +00:00
|
|
|
|
|
|
|
def submit(net, gpu=False):
|
|
|
|
dir = 'data/test/'
|
|
|
|
|
|
|
|
N = len(list(os.listdir(dir)))
|
2017-09-26 19:00:51 +00:00
|
|
|
with open('SUBMISSION.csv', 'a') as f:
|
|
|
|
|
2017-08-21 16:00:07 +00:00
|
|
|
f.write('img,rle_mask\n')
|
|
|
|
for index, i in enumerate(os.listdir(dir)):
|
|
|
|
print('{}/{}'.format(index, N))
|
2017-09-26 19:00:51 +00:00
|
|
|
|
2017-08-21 16:00:07 +00:00
|
|
|
img = Image.open(dir + i)
|
|
|
|
|
|
|
|
mask = predict_img(net, img, gpu)
|
2017-09-26 19:00:51 +00:00
|
|
|
enc = rle_encode(mask)
|
2017-08-21 16:00:07 +00:00
|
|
|
f.write('{},{}\n'.format(i, ' '.join(map(str, enc))))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
net = UNet(3, 1).cuda()
|
2017-09-26 19:00:51 +00:00
|
|
|
net.load_state_dict(torch.load('MODEL.pth'))
|
2017-08-21 16:00:07 +00:00
|
|
|
submit(net, True)
|