def call_server(): parser = argparse.ArgumentParser() parser.add_argument('-s', '--server_url', required=True, help='AIAA Server URI') parser.add_argument('-c', '--test_config', required=True, help='Test JSON Config') parser.add_argument('-n', '--name', help='Execute single test from config of this name') parser.add_argument('-d', '--debug', default=False, action='store_true', help='Enable debug logs') args = parser.parse_args() print('Using ARGS: {}'.format(args)) test_config = json_load_byteified(open(args.test_config)) if args.debug: logging.basicConfig( level=logging.DEBUG, format= '[%(asctime)s.%(msecs)03d][%(levelname)5s](%(name)s:%(funcName)s) - %(message)s', datefmt='%Y-%m-%d %H:%M:%S') tests = test_config.get('tests', None) if not tests: raise ValueError('no tests defined') client = client_api.AIAAClient(args.server_url) session_id = None print('Total tests available: {}'.format(len(tests))) disabled_list = [] for test in tests: name = test.get('name') disabled = test.get('disabled', False) disabled = False if args.name and args.name == name else True if args.name else disabled api = test.get('api') if disabled: disabled_list.append(name) continue print('') print( '---------------------------------------------------------------------' ) print('Running Test: {}'.format(name)) print( '---------------------------------------------------------------------' ) if name is None or api is None: raise ValueError('missing name: {} or api: {} in test'.format( name, api)) if api == 'models': label = test.get('label') models = client.model_list(label) print('++++ Listed Models: {}'.format(json.dumps(models))) continue if api == 'create_session': image_in = test.get('image_in') response = client.create_session(image_in) print('++++ Session Response: {}'.format(json.dumps(response))) session_id = response.get('session_id') continue if api == 'get_session': response = client.get_session(session_id) print('++++ Session Info: {}'.format(json.dumps(response))) continue if api == 'close_session': response = client.close_session(session_id) print('++++ Session ({}) closed: {}'.format(session_id, response)) continue if api == 'segmentation': model = test.get('model') image_in = test.get('image_in') image_out = test.get('image_out') result = client.segmentation(model, image_in, image_out) print('++++ Segmentation JSON Result: {}'.format( json.dumps(result))) print('++++ Segmentation Image result: {}'.format(image_out)) continue if api == 'dextr3d': model = test.get('model') point_set = test.get('point_set') image_in = test.get('image_in') image_out = test.get('image_out') pad = test.get('pad', 20) roi_size = test.get('roi_size', '128x128x128') result = client.dextr3d(model, point_set, image_in, image_out, pad, roi_size) print('++++ dextr3d JSON Result: {}'.format(json.dumps(result))) print('++++ dextr3d Image Result: {}'.format(image_out)) continue if api == 'deepgrow': model = test.get('model') foreground = test.get('foreground') background = test.get('background') image_in = test.get('image_in') image_out = test.get('image_out') result = client.deepgrow(model, foreground, background, image_in, image_out, foreground[-1]) print('++++ Deepgrow JSON Result: {}'.format(json.dumps(result))) print('++++ Deepgrow Image Result: {}'.format(image_out)) continue if api == 'inference': model = test.get('model') params = test.get('params') image_in = test.get('image_in') image_out = test.get('image_out') result = client.inference(model, params, image_in, image_out) print('++++ Inference JSON Result: {}'.format(json.dumps(result))) print('++++ Inference Image Result: {}'.format(image_out)) continue if api == 'mask2polygon': image_in = test.get('image_in') point_ratio = test.get('point_ratio') polygons = client.mask2polygon(image_in, point_ratio) print('++++ Mask2Polygons: {}'.format(json.dumps(polygons))) continue if api == 'fixpolygon': image_in = test.get('image_in') image_out = test.get('image_out') polygons = test.get('polygons') index = test.get('index') vertex_offset = test.get('vertex_offset') propagate_neighbor = test.get('propagate_neighbor') updated_poly = client.fixpolygon(image_in, image_out, polygons, index, vertex_offset, propagate_neighbor) print('++++ FixPolygons: {}'.format(json.dumps(updated_poly))) continue raise ValueError("Invalid API: {}".format(args.api)) if len(disabled_list) and not args.name: print('\nDisabled Tests ({}): {}'.format(len(disabled_list), ', '.join(disabled_list))) if args.name and len(disabled_list) == len(tests): print('"{}" Test NOT found; Available test names: {}'.format( args.name, disabled_list))
from flask_cors import CORS, cross_origin import sys import json import argparse import client_api app = Flask(__name__) cors = CORS(app) app.config['CORS_HEADERS'] = 'Content-Type' """Test annotation assistant server.""" sys.path.append('.') cors = CORS(app, resources={r"*": {"origins": "*"}}) ip = '10.91.4.191' port = '5000' api_version = 'v1' client = client_api.AIAAClient(ip, port, api_version) # post /fixpolygon @app.route('/fixpolygon', methods=['POST']) @cross_origin() def fix_polygon(): request_data = request.get_json() image_path = request_data.get('image_path') result_prefix = 'Outputs/spleen1_polygonUpdate' params = request_data.get('params') files = client.fixpolygon(image_path, result_prefix, params) with open('Outputs/spleen1_polygonUpdate.json') as json_file: data = json.load(json_file) return jsonify(data)
def call_server(): parser = argparse.ArgumentParser() parser.add_argument('--server_url', default='http://0.0.0.0:5000') parser.add_argument('--test_config', required=True) parser.add_argument('--debug', default=False) args = parser.parse_args() print('Using ARGS: {}'.format(args)) test_config = json_load_byteified(open(args.test_config)) if args.debug: logging.basicConfig(level=logging.DEBUG, format='[%(asctime)s.%(msecs)03d][%(levelname)5s](%(name)s:%(funcName)s) - %(message)s', datefmt='%Y-%m-%d %H:%M:%S') tests = test_config.get('tests', None) if not tests: raise ValueError('no tests defined') client = client_api.AIAAClient(args.server_url) session_id = None for test in tests: name = test.get('name') disabled = test.get('disabled', False) api = test.get('api') print('') print('---------------------------------------------------------------------') print('Running Test: {}'.format(name)) print('---------------------------------------------------------------------') if disabled: print('This test is skipped') continue if name is None or api is None: raise ValueError('missing name: {} or api: {} in test'.format(name, api)) if api == 'models': label = test.get('label') models = client.model_list(label) print('++++ Listed Models: {}'.format(json.dumps(models))) continue if api == 'create_session': image_in = test.get('image_in') response = client.create_session(image_in) print('++++ Session Response: {}'.format(json.dumps(response))) session_id = response.get('session_id') continue if api == 'get_session': response = client.get_session(session_id) print('++++ Session Info: {}'.format(json.dumps(response))) continue if api == 'close_session': response = client.close_session(session_id) print('++++ Session ({}) closed: {}'.format(session_id, response)) continue if api == 'segmentation': model = test.get('model') image_in = test.get('image_in') image_out = test.get('image_out') result = client.segmentation(model, image_in, image_out) print('++++ Segmentation Result: {}'.format(json.dumps(result))) continue if api == 'dextr3d': model = test.get('model') point_set = test.get('point_set') image_in = test.get('image_in') image_out = test.get('image_out') pad = test.get('pad', 20) roi_size = test.get('roi_size', '128x128x128') result = client.dextr3d(model, point_set, image_in, image_out, pad, roi_size) print('++++ dextr3d result: {}'.format(json.dumps(result))) continue if api == 'deepgrow': model = test.get('model') foreground = test.get('foreground') background = test.get('background') image_in = test.get('image_in') image_out = test.get('image_out') result = client.deepgrow(model, foreground, background, image_in, image_out) print('++++ Deepgrow Result: {}'.format(json.dumps(result))) continue if api == 'mask2polygon': image_in = test.get('image_in') point_ratio = test.get('point_ratio') polygons = client.mask2polygon(image_in, point_ratio) print('++++ Mask2Polygons: {}'.format(json.dumps(polygons))) continue if api == 'fixpolygon': image_in = test.get('image_in') image_out = test.get('image_out') polygons = test.get('polygons') index = test.get('index') vertex_offset = test.get('vertex_offset') propagate_neighbor = test.get('propagate_neighbor') updated_poly = client.fixpolygon(image_in, image_out, polygons, index, vertex_offset, propagate_neighbor) print('++++ FixPolygons: {}'.format(json.dumps(updated_poly))) continue raise ValueError("Invalid API: {}".format(args.api))
def call_server(): parser = argparse.ArgumentParser() parser.add_argument('--test_config') args = parser.parse_args() if not args.test_config: raise SyntaxError('test config file not specified') test_config = json.load(open(args.test_config)) server_config = test_config.get('server', None) if not server_config: raise ValueError('server not configured') ip = server_config.get('ip', '') if not ip: raise ValueError('server IP not configured') else: print("IP Address: ", ip) port = server_config.get('port', '') if not port: raise ValueError('server port not configured') else: print("Port: ", port) api_version = server_config.get('api_version', '') if not api_version: raise ValueError('API version not configured') else: print("API Version: ", api_version) tests = test_config.get('tests', None) print(tests) if not tests: raise ValueError('no tests defined') client = client_api.AIAAClient(ip, port, api_version) for test in tests: name = test.get('name') if not name: raise ValueError('missing name in test definition') api = test.get('api') if not api: raise ValueError('missing api in test definition') temp_folder = test.get('temp_folder') model_name = test.get('model') image_path = test.get('image') result_prefix = test.get('result_prefix') params = test.get('params') disabled = test.get('disabled', False) pad = test.get('pad', 20) roi_size = test.get('roi_size', '128x128x128') sigma = test.get('sigma', 3) if disabled: continue if not result_prefix: raise ValueError('missing result_prefix in test "{}"'.format(name)) if api == 'models': files = client.model_list(result_prefix) continue if not image_path: raise ValueError('missing image in test "{}"'.format(name)) if not params: raise ValueError('missing params in test "{}"'.format(name)) if api == 'dextr3d': if not model_name: raise ValueError( 'missing model name in test "{}"'.format(name)) if not temp_folder: raise ValueError( 'missing temp folder name in test "{}"'.format(name)) files = client.dextr3d(model_name, temp_folder, image_path, result_prefix + "_result_aas.nii.gz", params, pad, roi_size, sigma) elif api == 'mask2polygon': files = client.mask2polygon(image_path, result_prefix, params) elif api == 'fixpolygon': files = client.fixpolygon(image_path, result_prefix, params) else: raise ValueError("Invalid API: {}".format(args.api)) print("\nGenerated file for Test '{}':".format(name)) print(*files, sep='\n')