Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.

Commit 1e91068

Browse files
author
Tony Reina
committed
Fixed OpenVINO 3D prediction and added Jupyter Notebook
1 parent 3bb7186 commit 1e91068

5 files changed

+11
-12
lines changed

3D/inference_openvino.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def load_data(imgFile, mskFile, crop_dim, n_channels, n_out_channels, openVINO_o
133133
msks[idx] = msk
134134

135135
if openVINO_order:
136-
imgs = imgs.transpose((0, 4, 3, 1, 2))
137-
msks = msks.transpose((0, 4, 3, 1, 2))
136+
imgs = imgs.transpose((0, 4, 1, 2, 3))
137+
msks = msks.transpose((0, 4, 1, 2, 3))
138138

139139
return imgs, msks, fileIDs
140140

@@ -263,7 +263,7 @@ def main():
263263
"""
264264
This code checks to see if all of the graphs in the IR are
265265
compatible with OpenVINO. If not, then you'll need to probably
266-
try to load in an extension library from ${INTEL_CVSDK_DIR}/inference_engine/lib
266+
try to load in an extension library from ${INTEL_OPENVINO_DIR}/inference_engine/lib
267267
"""
268268
if "CPU" in plugin.device:
269269
supported_layers = plugin.get_supported_layers(net)
@@ -293,11 +293,11 @@ def main():
293293

294294
log.info("The network inputs are:")
295295
for idx, input_layer in enumerate(net.inputs.keys()):
296-
log.info("{}: {}, shape = {} [N,C,D,H,W]".format(idx,input_layer,net.inputs[input_layer].shape))
296+
log.info("{}: {}, shape = {} [N,C,H,W,D]".format(idx,input_layer,net.inputs[input_layer].shape))
297297

298298
log.info("The network outputs are:")
299299
for idx, output_layer in enumerate(net.outputs.keys()):
300-
log.info("{}: {}, shape = {} [N,C,D,H,W]".format(idx,output_layer,net.outputs[output_layer].shape))
300+
log.info("{}: {}, shape = {} [N,C,H,W,D]".format(idx,output_layer,net.outputs[output_layer].shape))
301301

302302

303303
batch_size, n_channels, depth, height, width = net.inputs[input_blob].shape
@@ -415,13 +415,12 @@ def main():
415415
ground_truth = label_data_keras[idx, :, :, :, out_channel]
416416

417417
# Transpose the OpenVINO prediction back to NCHWD (to be consistent with Keras)
418-
pred_ov = np.transpose(predictions_ov, [0,3,4,2,1])[idx, :, :, :, out_channel]
418+
pred_ov = np.transpose(predictions_ov, [0,2,3,4,1])[idx, :, :, :, out_channel]
419419
pred_keras = predictions_keras[idx, :, :, :, out_channel]
420420

421421
dice_ov = dice_score(pred_ov, ground_truth)
422422
dice_keras = dice_score(pred_keras, ground_truth)
423423

424-
dice_compare = dice_score(pred_ov, pred_keras)
425424

426425
# img = nib.Nifti1Image(imgs[idx, :, :, :, 0], np.eye(4))
427426
# img.to_filename(os.path.join(save_directory,
@@ -436,8 +435,8 @@ def main():
436435
# "{}_pred_ov.nii.gz".format(fileIDs[idx])))
437436

438437
log.info("Image file {}: OpenVINO Dice score = {:f}, "
439-
"Keras/TF Dice score = {:f}, Comparing Dice Score = {:f}".format(
440-
img_indicies[idx], dice_ov, dice_keras, dice_compare))
438+
"Keras/TF Dice score = {:f}, Maximum absolute pixel difference OV versus Keras/TF = {:.2e}".format(
439+
img_indicies[idx], dice_ov, dice_keras, np.mean(np.abs(pred_ov - pred_keras))))
441440

442441
log.info("Average inference time: \n"
443442
"OpenVINO = {} seconds (s.d. {})\n "

3D/script_slurm

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/bash
22
#SBATCH --time=48:00:00
33
#SBATCH --job-name=3d-unet-horovod
4-
#SBATCH -o /home/loic.mcgill/logs/%x_%j.out # %x job name, %N for node name, %j for jobID
4+
#SBATCH -o /home/unet/logs/%x_%j.out # %x job name, %N for node name, %j for jobID
55
#SBATCH --partition=6252
66
#SBATCH --nodes=10
77

8-
data_path=/mnt/lustrefs/mcgill/decathlon/Task01_BrainTumour/
9-
script_path=/home/loic.mcgill/scripts/unet/3D/train_horovod.py
8+
data_path=/mnt/lustrefs/unet/decathlon/Task01_BrainTumour/
9+
script_path=/home/unet/scripts/unet/3D/train_horovod.py
1010

1111
mpirun -n 20 -ppn 2 -print-rank-map -genv I_MPI_PIN_DOMAIN=socket -genv OMP_NUM_THREADS=24 -genv OMP_PROC_BIND=true -genv KMP_BLOCKTIME=1 python3 $script_path --keras_api --intraop_threads 24 --data_path $data_path

0 commit comments

Comments
 (0)