Skip to content

Commit

Permalink
compatible csv_data_file reader
Browse files Browse the repository at this point in the history
  • Loading branch information
wyli committed Oct 7, 2019
1 parent 40032fe commit 25e6204
Show file tree
Hide file tree
Showing 32 changed files with 162 additions and 220 deletions.
2 changes: 1 addition & 1 deletion config/GAN_demo_train_config.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
############################ input configuration sections
[usimage]
csv_path_file=
csv_file=
path_to_search = ./example_volumes/gan_test_data
filename_contains = frame,img
filename_not_contains =
Expand Down
10 changes: 5 additions & 5 deletions config/default_multimodal_segmentation.ini
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
############################ input configuration sections
[T1]
csv_path_file=
csv_file=
path_to_search = ./example_volumes/multimodal_BRATS
filename_contains = T1
filename_not_contains = T1c
spatial_window_size = (64, 64, 64)
interp_order = 3

[T2]
csv_path_file=
csv_file=
path_to_search = ./example_volumes/multimodal_BRATS
filename_contains = T2
filename_not_contains =
spatial_window_size = (64, 64, 64)
interp_order = 3

[T1c]
csv_path_file=
csv_file=
path_to_search = ./example_volumes/multimodal_BRATS
filename_contains = T1c
filename_not_contains =
spatial_window_size = (64, 64, 64)
interp_order = 3

[Flair]
csv_path_file=
csv_file=
path_to_search = ./example_volumes/multimodal_BRATS
filename_contains = Flair
filename_not_contains =
spatial_window_size = (64, 64, 64)
interp_order = 3

[label]
csv_path_file=
csv_file=
path_to_search = ./example_volumes/multimodal_BRATS
filename_contains = Label
filename_not_contains =
Expand Down
4 changes: 2 additions & 2 deletions config/default_multimodal_segmentation_eval.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
############################ input configuration sections
[seg]
csv_path_file=
csv_file=
path_to_search = ./NiftyNetTestEval
filename_contains = Correct_WS3WT3WC1MergedSPCP_,_corr_corrIT
filename_not_contains =
Expand All @@ -9,7 +9,7 @@ interp_order = 0


[label]
csv_path_file=
csv_file=
path_to_search = ./NiftyNetTestEval
filename_contains = CHJP_,_vote
filename_not_contains =
Expand Down
2 changes: 1 addition & 1 deletion config/default_segmentation.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
############################ input configuration sections
[modality1]
csv_path_file=
csv_file=
path_to_search = ./example_volumes/monomodal_parcellation
filename_contains = T1
filename_removefromid = _T1
Expand Down
2 changes: 1 addition & 1 deletion config/default_segmentation_bf.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
############################ input configuration sections
[modality1]
csv_path_file=
csv_file=
path_to_search = ./example_volumes/monomodal_parcellation
filename_contains = T1
filename_not_contains =
Expand Down
8 changes: 4 additions & 4 deletions config/label_driven_registration.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ save_seg_dir = resampled_moving/

############################ input configuration sections
[image0]
csv_path_file= ./image0.csv
csv_file= ./image0.csv
path_to_search = /mnt/shared/wenqi/reg_data/us_images
filename_contains =
filename_not_contains =
spatial_window_size = (80, 112, 80)
interp_order = 3

[label0]
csv_path_file= ./label0.csv
csv_file= ./label0.csv
path_to_search = /mnt/shared/wenqi/reg_data/us_labels
filename_contains = _label000
filename_not_contains =
spatial_window_size = (80, 112, 80)
interp_order = 3

[image1]
csv_path_file= ./image1.csv
csv_file= ./image1.csv
path_to_search = /mnt/shared/wenqi/reg_data/mr_images
filename_contains =
filename_not_contains =
Expand All @@ -57,7 +57,7 @@ spatial_window_size = (80, 112, 80)
interp_order = 3

[label1]
csv_path_file= ./label1.csv
csv_file= ./label1.csv
path_to_search = /mnt/shared/wenqi/reg_data/mr_labels
filename_contains = _label000
filename_not_contains =
Expand Down
2 changes: 1 addition & 1 deletion demos/module_examples/FullCSVReaderDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"# Make sure we accept 'Label', 'label', 'LABEL'\n",
"task_param = TaskParam(['image'])\n",
"image_data_param = {'CT': {'path_to_search': '~/niftynet/data/mr_ct_regression/CT_zero_mean', 'filename_contains': 'nii'}}\n",
"# Change csv_file -> csv_path_file, csv_data_file is a csv with data\n",
"#csv_data_file is a csv with data\n",
"csv_data_param = {'label': {'csv_data_file': 'label.csv', 'to_ohe': True}}\n",
"grouping_param = {'image': (['CT'])}\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion demos/unet/U-Net_Demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"############################ input configuration sections\n",
"-[modality1]\n",
"+[cells] # you can name this whatever you want\n",
"-csv_path_file= # we will find the images by searching\n",
"-csv_file= # we will find the images by searching\n",
"-path_to_search = ./example_volumes/monomodal_parcellation\n",
"+path_to_search = ./data/u-net/PhC-C2DH-U373/niftynet_data\n",
"-filename_contains = T1\n",
Expand Down
9 changes: 4 additions & 5 deletions doc/source/config_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ understand how files are matched.

Name | Type | Example | Default
---- | ---- | ------- | -------

[csv_path_file](#csv-path-file) | `string` | `csv_path_file=file_list.csv` | `''`
[csv_file](#csv-file) | `string` | `csv_file=file_list.csv` | `''`
[path_to_search](#path-to-search) | `string` | `path_to_search=my_data/fold_1` | NiftyNet home folder
[filename_contains](#filename-contains) | `string` or `string array` | `filename_contains=foo, bar` | `''`
[filename_not_contains](#filename-not-contains) | `string` or `string array` | `filename_not_contains=foo` | `''`
Expand All @@ -167,7 +166,7 @@ understand how files are matched.
[spatial_window_size](#spatial-window-size) | `integer array` | `spatial_window_size=64, 64, 64` | `''`
[loader](#loader) | `string` | `loader=simpleitk` | `None`

###### `csv_path_file`
###### `csv_file`
A file path to a list of input images. If the file exists, input image name
list will be loaded from the file; the filename based input image search will
be disabled; [path_to_search](#path-to-search),
Expand Down Expand Up @@ -279,8 +278,8 @@ with an interpolation order of `3`.

A CSV file with the matched filenames and extracted subject names will be
generated to `T1Image.csv` in [`model_dir`](#model-dir) (by default; the CSV
file location can be specified by setting [csv_path_file](#csv-path-file)). To exclude
particular images, the [csv_path_file](#csv-path-file) can be edited manually.
file location can be specified by setting [csv_file](#csv-file)). To exclude
particular images, the [csv_file](#csv-file) can be edited manually.

This input source can be used alone, as a `T1` MRI input to an application.
It can also be used along with other modalities, a multi-modality example
Expand Down
11 changes: 6 additions & 5 deletions niftynet/contrib/csv_reader/class_seg_finnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from niftynet.network.base_net import BaseNet
from niftynet.layer.layer_util import infer_spatial_rank
from niftynet.layer.fully_connected import FullyConnectedLayer
from niftynet.layer.pool_full import PoolingLayer
# from niftynet.layer.pool_full import PoolingLayer
import tensorflow as tf


Expand Down Expand Up @@ -72,10 +72,11 @@ def layer_op(self, images, is_training, layer_id=-1):

# pooling layer
params = self.layers[1]
pool_layer = PoolingLayer(
func=params['func'],
name=params['name'])
flow_pool = pool_layer(flow)
# pool_layer = PoolingLayer(
# func=params['func'],
# name=params['name'])
# flow_pool = pool_layer(flow)
flow_pool = flow
flow_pool = tf.reshape(flow_pool, [tf.shape(images)[0], 1, 1, 1,
self.layers[1][
'n_features']])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
############################ input configuration sections
[modality1]
csv_path_file=
csv_file=
path_to_search = ./example_volumes/monomodal_parcellation
filename_contains = T1
filename_removefromid = _T1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
############################ input configuration sections
[modality1]
csv_path_file=
csv_file=
path_to_search = ./example_volumes/monomodal_parcellation
filename_contains = T1
filename_not_contains =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def check_constraint(data, constraint):

MULTI_MOD_DATA = {
'T1': ParserNamespace(
csv_path_file=os.path.join('testing_data', 'T1sampler.csv'),
csv_file=os.path.join('testing_data', 'T1sampler.csv'),
path_to_search='testing_data',
filename_contains=('_o_T1_time',),
filename_not_contains=('Parcellation',),
Expand All @@ -65,7 +65,7 @@ def check_constraint(data, constraint):
loader=None
),
'FLAIR': ParserNamespace(
csv_path_file=os.path.join('testing_data', 'FLAIRsampler.csv'),
csv_file=os.path.join('testing_data', 'FLAIRsampler.csv'),
path_to_search='testing_data',
filename_contains=('FLAIR_',),
filename_not_contains=('Parcellation',),
Expand All @@ -76,7 +76,7 @@ def check_constraint(data, constraint):
loader=None
),
'Label': ParserNamespace(
csv_path_file=os.path.join('testing_data', 'lesion.csv'),
csv_file=os.path.join('testing_data', 'lesion.csv'),
path_to_search='testing_data',
filename_contains=('LesionFin_',),
filename_not_constains=('FLAIR_',),
Expand All @@ -89,7 +89,7 @@ def check_constraint(data, constraint):
}
LABEL_TASK = {
'Lesion': ParserNamespace(
csv_path_file=os.path.join('testing_data', 'lesion.csv'),
csv_file=os.path.join('testing_data', 'lesion.csv'),
path_to_search='testing_data',
filename_contains=('LesionFin_'),
filename_not_contains=('Parcellation',),
Expand All @@ -104,7 +104,7 @@ def check_constraint(data, constraint):

MOD_2D_DATA = {
'ultrasound': ParserNamespace(
csv_path_file=os.path.join('testing_data', 'T1sampler2d.csv'),
csv_file=os.path.join('testing_data', 'T1sampler2d.csv'),
path_to_search='testing_data',
filename_contains=('2d_',),
filename_not_contains=('Parcellation',),
Expand All @@ -119,7 +119,7 @@ def check_constraint(data, constraint):

DYNAMIC_MOD_DATA = {
'T1': ParserNamespace(
csv_path_file=os.path.join('testing_data', 'T1sampler.csv'),
csv_file=os.path.join('testing_data', 'T1sampler.csv'),
path_to_search='testing_data',
filename_contains=('_o_T1_time',),
filename_not_contains=('Parcellation',),
Expand All @@ -130,7 +130,7 @@ def check_constraint(data, constraint):
loader=None
),
'FLAIR': ParserNamespace(
csv_path_file=os.path.join('testing_data', 'FLAIRsampler.csv'),
csv_file=os.path.join('testing_data', 'FLAIRsampler.csv'),
path_to_search='testing_data',
filename_contains=('FLAIR_',),
filename_not_contains=('Parcellation',),
Expand All @@ -141,7 +141,7 @@ def check_constraint(data, constraint):
loader=None
),
'Label': ParserNamespace(
csv_path_file=os.path.join('testing_data', 'labels.csv'),
csv_file=os.path.join('testing_data', 'labels.csv'),
path_to_search='testing_data',
filename_contains=('T1_', '_NeuroMorph_Parcellation',),
filename_not_constains=('FLAIR_',),
Expand All @@ -155,7 +155,7 @@ def check_constraint(data, constraint):

# LABEL_TASK = {
# 'Parcellation': ParserNamespace(
# csv_path_file=os.path.join('testing_data', 'labels.csv'),
# csv_file=os.path.join('testing_data', 'labels.csv'),
# path_to_search='testing_data',
# filename_contains=('Parcellation',),
# filename_not_constains=('FLAIR_',),
Expand Down
4 changes: 2 additions & 2 deletions niftynet/io/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
DEFAULT_INTERP_ORDER = 1
SUPPORTED_DATA_SPEC = {

'csv_path_file', 'path_to_search', 'csv_data_file', 'filename_removefromid',
'csv_file', 'path_to_search', 'csv_data_file', 'filename_removefromid',
'filename_contains', 'filename_not_contains', 'to_ohe',
'interp_order', 'loader', 'pixdim', 'axcodes', 'spatial_window_size'}

Expand Down Expand Up @@ -410,7 +410,7 @@ def _filename_to_image_list(file_list, mod_dict, data_param):
if not volume_list:
tf.logging.fatal(
"Empty filename lists, please check the csv "
"files. (removing csv_path_file keyword if it is"
"files. (removing csv_file keyword if it is"
" in the config file "
"to automatically search folders and generate new csv "
"files again)\n\n"
Expand Down
Loading

0 comments on commit 25e6204

Please sign in to comment.