Skip to content

Commit b6e0ba9

Browse files
committed
updating json to match dockerhub, fixing examples, removing warnings
1 parent be580c0 commit b6e0ba9

File tree

8 files changed

+32
-20
lines changed

8 files changed

+32
-20
lines changed

CTBoneSegmenter.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"docker":
1212
{
1313
"dockerhub_repository": "4quant/bone-segmenter-cpu",
14-
"digest": "sha256:43f13084e4d75508a0bc08b4a8c55880b4a5defb90043cb82d6a39ac25adabbf",
15-
"size": "4.6 GB"
14+
"digest": "sha256:41020bcd68cc5854aa1757b452defc52e9035d39ed19edc1b33439d327dd99b5",
15+
"size": "3.6 GB"
1616
}
1717
,
1818
"training":

Dockerfile.cpu

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ RUN pip install --upgrade pip && \
3636
conda install -c menpo opencv=2.4.11 && \
3737
conda clean -yt
3838

39-
RUN mkdir /home/deepinfer/.keras &&
39+
RUN mkdir /home/deepinfer/.keras && \
4040
mkdir /home/deepinfer/.keras/models && \
4141
echo { '"image_dim_ordering"': '"th"', '"epsilon"': 1e-07, '"floatx"': '"float32"', '"backend"': '"theano"'}>/home/deepinfer/.keras/keras.json
4242

4343

4444
RUN mkdir -p /home/deepinfer/github && \
45-
mkdir -p /home/deepinfer/github/bone-segmenter
45+
mkdir -p /home/deepinfer/github/bone-segmenter && \
4646
mkdir /home/deepinfer/data
4747

4848
WORKDIR "/home/deepinfer/github/bone-segmenter"

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ docker build -t bone-segmenter-cpu -f Dockerfile.cpu .
1717

1818
##### Running the docker
1919
```
20-
docker run -t -v [Absolute PATH to the Project Folder]/Prostate-Segmenter/prostatesegmenter/data/test/:/home/deepinfer/data deepinfer/prostate-segmenter-cpu --InputVolume /home/deepinfer/data/input.nrrd --OutputLabel /home/deepinfer/data/label_predicted_test.nrrd
20+
docker run -t -v [Absolute PATH to the Project Folder]/Bone-Segmenter/data/test/:/home/deepinfer/data 4Quant/bone-segmenter-cpu --InputVolume /home/deepinfer/data/input.nrrd --OutputLabel /home/deepinfer/data/label_predicted_test.nrrd
2121
```
2222

23+
Windows Example
24+
```
25+
docker run -t -v "C:\Users\Kevin Mader\Dropbox\4Quant\Projects\Bone-Segmenter":/home/deepinfer/data bone-segmenter-cpu --InputVolume /home/deepinfer/data/CTChest.nrrd --OutputLabel /home/deepinfer/data/label_predicted_test.nrrd
26+
```
2327

2428
# Results
2529

boneseg/segmenter.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import SimpleITK as sitk
22
import numpy as np
33

4-
from prostatesegmenter.utils import reshape_volume
4+
from boneseg.utils import reshape_volume
55

66

77
class Segmenter(object):
@@ -11,22 +11,20 @@ def __init__(self, model, threshold=0.5):
1111

1212
def __predict(self, vol_nda):
1313
predicted_label = self.model.predict_test(input_test_slices_arr=vol_nda)
14-
predicted_label[predicted_label > self.threshold] = 1
15-
predicted_label[predicted_label <= self.threshold] = 0
1614
return predicted_label
1715

1816
def segment_bone_volume(self, input_volume_path, output_mask_path, rows, cols):
1917
vol = sitk.ReadImage(input_volume_path)
20-
vol = sitk.Cast(sitk.RescaleIntensity(vol), sitk.sitkUInt8)
2118
vol_nda = sitk.GetArrayFromImage(vol)
2219
original_shape = vol_nda.shape
2320
vol_nda = reshape_volume(vol_nda, rows, cols)
2421
vol_nda = np.expand_dims(vol_nda, axis=1)
2522
label_nda = self.__predict(vol_nda)
2623
label_nda = label_nda[:, 0, :, :]
2724
# TODO: Check the indices for shape!
28-
label_nda = reshape_volume(label_nda, original_shape[1], original_shape[2])
29-
label = sitk.GetImageFromArray(label_nda)
25+
# since the zoom function interpolates, threshold it again
26+
label_nda = reshape_volume(label_nda, original_shape[1], original_shape[2])>0.5
27+
label = sitk.GetImageFromArray(label_nda.astype(np.uint8))
3028
label.CopyInformation(vol)
3129
writer = sitk.ImageFileWriter()
3230
writer.Execute(label, output_mask_path, True)

boneseg/utils.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function, absolute_import, division
12
import numpy as np
23
import os
34
import sys
@@ -25,11 +26,12 @@ def dice_coef_loss(y_true, y_pred):
2526
return 1 - dice_coef(y_true, y_pred)
2627

2728

29+
2830
def reshape_volume(nda_vol, rows, cols):
29-
from cv2 import resize, INTER_CUBIC
30-
nda_vol_reshaped = np.ndarray((nda_vol.shape[0], rows, cols), dtype=np.uint8)
31-
for i in range(len(nda_vol)):
32-
nda_vol_reshaped[i] = resize(nda_vol[i], (cols, rows), interpolation= INTER_CUBIC)
31+
from scipy.ndimage import zoom
32+
nda_vol_reshaped = np.ndarray((nda_vol.shape[0], rows, cols), dtype=np.float32)
33+
zoom_fact = (1, rows/nda_vol.shape[1], cols/nda_vol.shape[2])
34+
zoom(nda_vol, zoom_fact, output = nda_vol_reshaped)
3335
return nda_vol_reshaped
3436

3537

@@ -80,4 +82,4 @@ def dl_progress(count, block_size, total_size):
8082
os.remove(fpath)
8183
raise e
8284

83-
return fpath
85+
return fpath

figures/boneseg_predictions.png

2.73 KB
Loading

fit.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
from __future__ import print_function, absolute_import, division
2+
# Silence warnings
3+
import warnings
4+
warnings.simplefilter(action="ignore", category=FutureWarning)
5+
warnings.simplefilter(action="ignore", category=UserWarning)
6+
warnings.simplefilter(action="ignore", category=RuntimeWarning)
7+
warnings.simplefilter(action='ignore', category=DeprecationWarning)
8+
19
import getopt
210
import os
311
import sys
@@ -31,13 +39,13 @@ def main(argv):
3139
print('usage: fit.py -InputVolume <InputVolumePath> -OutputLabel <OutputLabelPath>')
3240
sys.exit()
3341
if os.path.isfile(InputVolume) and os.path.isdir(os.path.dirname(OutputLabel)):
34-
print("Making the model.")
42+
print("Building the model.")
3543
model = unet1.model(weights=True, summary=False)
36-
cnn = CNNModel(data_streamer=ds, model=model)
44+
cnn = CNNModel(model=model, mean_val = 0, max_val = 300)
3745
rows = 128
3846
cols = 128
3947
#
40-
print("Starting the segmenter.")
48+
print("Resizing images and segmenting")
4149
sg = Segmenter(cnn)
4250
sg.segment_bone_volume(InputVolume, OutputLabel, rows, cols)
4351
else:

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
python fit.py --InputVolume prostatesegmenter/data/test/Case1-t2ax-intraop.nrrd --OutputLabel prostatesegmenter/data/test/Case1-t2ax-intraop_label.nrrd
2+
python fit.py --InputVolume CTChest.nrrd --OutputLabel test_out.nrrd

0 commit comments

Comments
 (0)