Ejemplo n.º 1
0
def get_config():
    """
    Get the CNN configuration from file
    """
    default_config = ConfigParser.SafeConfigParser()
    default_config.read(os.path.join(CURRENT_PATH, 'config', 'default.cfg'))
    user_config = ConfigParser.RawConfigParser()
    user_config.read(os.path.join(CURRENT_PATH, 'config', 'configuration.cfg'))

    # read user's configuration file
    options = load_options(default_config, user_config)
    options['tmp_folder'] = CURRENT_PATH + '/tmp'

    # set paths taking into account the host OS
    host_os = platform.system()
    if host_os == 'Linux':
        options['niftyreg_path'] = CURRENT_PATH + '/libs/linux/niftyreg'
        options['robex_path'] = CURRENT_PATH + '/libs/linux/ROBEX/runROBEX.sh'
        options['test_slices'] = 256
    elif host_os == 'Windows':
        options['niftyreg_path'] = os.path.normpath(
            os.path.join(CURRENT_PATH, 'libs', 'win', 'niftyreg'))

        options['robex_path'] = os.path.normpath(
            os.path.join(CURRENT_PATH, 'libs', 'win', 'ROBEX', 'runROBEX.bat'))
        options['test_slices'] = 256
    else:
        print "The OS system", host_os, "is not currently supported."
        exit()

    # print options when debugging
    if options['debug']:
        print_options(options)

    return options
parser.add_argument('--docker', dest='docker', action='store_true')
parser.set_defaults(docker=False)
args = parser.parse_args()
container = args.docker

# --------------------------------------------------
# load default options and update them with user information
# from utils.load_options import *
# --------------------------------------------------
default_config = ConfigParser.SafeConfigParser()
default_config.read(os.path.join(CURRENT_PATH, 'config', 'default.cfg'))
user_config = ConfigParser.RawConfigParser()
user_config.read(os.path.join(CURRENT_PATH, 'config', 'configuration.cfg'))

# read user's configuration file
options = load_options(default_config, user_config)

if options['debug']:
    print_options(options)

# tensorflow backend
device = str(options['gpu_number'])
print "DEBUG: ", device
os.environ['KERAS_BACKEND'] = 'tensorflow'
os.environ["CUDA_VISIBLE_DEVICES"] = device

# set paths taking into account the host OS
host_os = platform.system()
if host_os == 'Linux':
    options['niftyreg_path'] = CURRENT_PATH + '/libs/linux/niftyreg'
    options['robex_path'] = CURRENT_PATH + '/libs/linux/ROBEX/runROBEX.sh'