def predict(): request_body = request.get_json() instance = request_body['instance'] output = inference.estimate(instance) return jsonify(output)
def direct_process(args, net, device: str = 'cpu'): # Init. coeffdict = read_coeff(args.coeff) beta = [a for a in args.alpha] # Instantiate dataloader stereo_dataset = InferenceRun(root=args.root, pair=False, use_stereo=True) stereo_dataloader = DataLoader(stereo_dataset, batch_size=1, shuffle=False, num_workers=8, pin_memory=True) # Processing dataloader for images, floname in tqdm(stereo_dataloader, ncols=100, leave=True, unit='pair', desc=f'Evaluating {args.root}'): images = [image.to(device) for image in images] # Add to device flow_cal = [ _stereo_cal(estimate(net, images[i], images[i + 1], tensor=False), coeffdict[naming.capitalize()], args.window_size, 1 / args.fps, True) for i, naming in enumerate(['left', 'right']) ] stereo_flow = willert(flow_cal, args.theta, beta) flosave = str(floname[0]) + '_2d3c.flo' write_flow(stereo_flow, os.path.join(args.save, "stereo", flosave))
MODEL_NAME = 'synth_custom_regressor' MODEL_VERSION = 'v1' def compute_rmse(estimates, actual): rmse = math.sqrt(((pd.Series(estimates) - actual)**2).sum() / len(actual)) return rmse test_data = pd.read_csv("data/test-data.csv", header=None, names="key,x,y,alpha,beta,target".split(',')) test_instances = list( test_data.apply(lambda row: { 'x': row['x'], 'y': row['y'], 'alpha': row['alpha'], 'beta': row['beta'] }, axis=1)) estimates = inference.estimate(instances=test_instances, project=PROJECT, model_name=MODEL_NAME, version=MODEL_VERSION) rmse = compute_rmse(estimates, test_data.target) print("Test RMSE: {}".format(round(rmse, 3)))
import inference instance = { 'is_male': 'True', 'mother_age': 26.0, 'mother_race': 'Asian Indian', 'plurality': 1.0, 'gestation_weeks': 39, 'mother_married': 'True', 'cigarette_use': 'False', 'alcohol_use': 'False' } output = inference.estimate(instance) print(output)