forked from milesial/Pytorch-UNet
-
Notifications
You must be signed in to change notification settings - Fork 5
/
checkoutput.py
63 lines (34 loc) · 1.36 KB
/
checkoutput.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
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 6 15:11:21 2019
@author: Admin
"""
import numpy as np
import torch
import torch.nn.functional as F
from PIL import Image
from unet import UNet2
from utils import resize_and_crop, normalize, split_img_into_squares, hwc_to_chw, merge_masks, dense_crf
if __name__ == "__main__":
im = Image.open("303.png")
net = UNet2(n_channels=3, n_classes=1)
net.load_state_dict(torch.load("CP67.pth"))
net.eval()
img = resize_and_crop(im, scale=1)
img = normalize(img)
#left_square, right_square = split_img_into_squares(img)
img1 = hwc_to_chw(img)
#right_square = hwc_to_chw(right_square)
X_left = torch.from_numpy(img1).unsqueeze(0)
#X_right = torch.from_numpy(right_square).unsqueeze(0)
with torch.no_grad():
output_left = net(X_left)
# output_right = net(X_right)
left_probs = output_left.squeeze(0)
# right_probs = output_right.squeeze(0)
left_probs = left_probs.cpu().detach().numpy()
#right_probs = tf(right_probs.cpu())
left_mask_np = left_probs.squeeze()
left_mask_np = np.uint8(np.abs(left_mask_np*255))
im2 = Image.fromarray(left_mask_np)
im2.save("out_temp.jpg")