-
Notifications
You must be signed in to change notification settings - Fork 5
/
convert.py
37 lines (24 loc) · 953 Bytes
/
convert.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
import argparse
import os
import tensorflow as tf
from mrtoct import ioutil
def convert(input_paths, output_path):
encoder = ioutil.TFRecordEncoder()
options = ioutil.TFRecordOptions
os.makedirs(os.path.dirname(output_path), exist_ok=True)
with tf.python_io.TFRecordWriter(output_path, options) as writer:
for input_path in input_paths:
volume = ioutil.read_nifti(input_path)
volume = ioutil.voxel_to_tensor_space(volume)
writer.write(encoder.encode(volume))
tf.logging.info(f'Wrote {input_path} to {output_path}')
def main(args):
tf.logging.set_verbosity(tf.logging.INFO)
convert(args.input_paths, args.output_path)
if __name__ == '__main__':
parser = argparse.ArgumentParser('convert', description='''
Converts NIfTI volumes to tfrecord.
''')
parser.add_argument('--input-paths', required=True, nargs='+')
parser.add_argument('--output-path', required=True)
main(parser.parse_args())