|
a |
|
b/evaluate_dsb_fpred_scan.py |
|
|
1 |
import sys |
|
|
2 |
import lasagne as nn |
|
|
3 |
import numpy as np |
|
|
4 |
import theano |
|
|
5 |
import pathfinder |
|
|
6 |
import utils |
|
|
7 |
from configuration import config, set_configuration |
|
|
8 |
from utils_plots import plot_slice_3d_3 |
|
|
9 |
import theano.tensor as T |
|
|
10 |
import utils_lung |
|
|
11 |
import blobs_detection |
|
|
12 |
import logger |
|
|
13 |
from collections import defaultdict |
|
|
14 |
import glob |
|
|
15 |
import data_transforms |
|
|
16 |
|
|
|
17 |
theano.config.warn_float64 = 'raise' |
|
|
18 |
|
|
|
19 |
if len(sys.argv) < 2: |
|
|
20 |
sys.exit("Usage: test_luna_scan.py <configuration_name>") |
|
|
21 |
|
|
|
22 |
config_name = sys.argv[1] |
|
|
23 |
set_configuration('configs_fpred_scan', config_name) |
|
|
24 |
|
|
|
25 |
# predictions path |
|
|
26 |
predictions_dir = utils.get_dir_path('model-predictions', pathfinder.METADATA_PATH) |
|
|
27 |
outputs_path = predictions_dir + '/%s' % config_name |
|
|
28 |
outputs_img_path = predictions_dir + '/%s_img' % config_name |
|
|
29 |
utils.auto_make_dir(outputs_img_path) |
|
|
30 |
|
|
|
31 |
blob_files = sorted(glob.glob(outputs_path + '/*.pkl')) |
|
|
32 |
|
|
|
33 |
p_transform = {'patch_size': (64, 64, 64), |
|
|
34 |
'mm_patch_size': (64, 64, 64), |
|
|
35 |
'pixel_spacing': (1., 1., 1.) |
|
|
36 |
} |
|
|
37 |
|
|
|
38 |
for p in blob_files: |
|
|
39 |
pid = utils_lung.extract_pid_filename(p, '.pkl') |
|
|
40 |
blobs = utils.load_pkl(p) |
|
|
41 |
blobs = np.asarray(sorted(blobs, key=lambda x: x[-1], reverse=True)) |
|
|
42 |
|
|
|
43 |
img, pixel_spacing = utils_lung.read_dicom_scan(pathfinder.DATA_PATH + '/' + pid) |
|
|
44 |
print pid |
|
|
45 |
for blob in blobs[:10]: |
|
|
46 |
patch_center = blob[:3] |
|
|
47 |
p1 = blob[-1] |
|
|
48 |
print p1 |
|
|
49 |
x, _ = data_transforms.transform_patch3d(data=img, |
|
|
50 |
luna_annotations=None, |
|
|
51 |
patch_center=patch_center, |
|
|
52 |
p_transform=p_transform, |
|
|
53 |
pixel_spacing=pixel_spacing, |
|
|
54 |
luna_origin=None, |
|
|
55 |
world_coord_system=False) |
|
|
56 |
|
|
|
57 |
plot_slice_3d_3(input=x, mask=x, prediction=x, |
|
|
58 |
axis=0, pid='-'.join([str(pid), str(p1)]), |
|
|
59 |
img_dir=outputs_img_path, idx=np.array(x[0, 0].shape) / 2) |
|
|
60 |
# print 'saved' |