def _get_tiles(input_data, list_boundaries: List[List[float]]): all_tiles = [] input_tensor = tf.cast(input_data, tf.float64) for i, boundaries in enumerate(list_boundaries): bucketized_tensor = math_ops.bucketize(input_tensor, boundaries) bucketized_tensor = tf.reshape(bucketized_tensor, (-1, 1)) bucketized_tensor = tf.math.add(bucketized_tensor, i * (len(boundaries) - 1)) all_tiles.append(bucketized_tensor) return tf.concat(all_tiles, axis=1)
def loop_fn(i): a = array_ops.gather(x, i) return math_ops.bucketize(a, [-1, 0.5, 1])
def get_all_projected_from_3vps_modified_tf(vps, no_bins, img_dims, verbose=False): # img_dims is of form (width, height) width, height = img_dims sphere_radii, sphere_centres = utils_projection.get_sphere_params( width=width, height=height) sphere_radius_horx, sphere_radius_hory, sphere_radius_vpzx, sphere_radius_vpzy = sphere_radii sphere_centre_horx, sphere_centre_hory, sphere_centre_vpzx, sphere_centre_vpzy = sphere_centres # horizon's x-coordinate # -sphere_radius -> sphere_radius req_p_horx = get_pointonsphere_given_sphere_2points_tf( sphere_centre_horx, sphere_radius_horx, vps[0, :], vps[1, :]) bins_horx = np.arange(-sphere_radius_horx / 2, sphere_radius_horx / 2, (sphere_radius_horx) / no_bins) if verbose: print(bins_horx) target_class_horx = math_ops.bucketize(input=req_p_horx[0], boundaries=bins_horx.tolist()) - 1 if verbose: print(target_class_horx) print('-----------------------------------') # vpz's x-coordinate # -sphere_radius -> sphere_radius req_p_vpzx = get_projection_on_sphere_tf(tf.stack( [tf.reshape(vps[2, 0], (1, )), [height * 2], [0]], axis=1), sphere_centre=sphere_centre_vpzx, sphere_radius=sphere_radius_vpzx) bins_vpzx = np.arange(-sphere_radius_vpzx, sphere_radius_vpzx, (sphere_radius_vpzx * 2) / no_bins) if verbose: print(bins_vpzx) target_class_vpzx = math_ops.bucketize(input=req_p_vpzx[0, 0], boundaries=bins_vpzx.tolist()) - 1 if verbose: print(target_class_vpzx) print('-----------------------------------') # horizon's y-coordinate # -sphere_radius -> 0 req_p_hory = get_pointonsphere_given_sphere_2points_tf( sphere_centre_hory, sphere_radius_hory, vps[0, :], vps[1, :]) bins_hory = np.arange(0, sphere_radius_hory, (sphere_radius_hory) / no_bins) if verbose: print(bins_hory) target_class_hory = math_ops.bucketize(input=req_p_hory[2], boundaries=bins_hory.tolist()) - 1 if verbose: print(target_class_hory) print('-----------------------------------') # vpz's y-coordinate # -some number (> -sphere radius) -> 0 # Take z-coordinate of req_p_vpzy req_p_vpzy = get_projection_on_sphere_tf(tf.stack( [[width / 2], tf.reshape(vps[2, 1], (1, )), [0]], axis=1), sphere_centre=sphere_centre_vpzy, sphere_radius=sphere_radius_vpzy) top_most_vanishing_point = get_projection_on_sphere( np.array([[width / 2, height, 0]]), sphere_centre=sphere_centre_vpzy, sphere_radius=sphere_radius_vpzy)[0, 2] bins_vpzy = np.arange(top_most_vanishing_point, 0, abs(top_most_vanishing_point) / no_bins) if verbose: print(bins_vpzy) target_class_vpzy = math_ops.bucketize(input=req_p_vpzy[0, 2], boundaries=bins_vpzy.tolist()) - 1 if verbose: print(target_class_vpzy) print('-----------------------------------') if verbose: print(req_p_horx) # take x-coordinate print(req_p_hory) # take x-coordinate # print(req_p_vpzx) # take y-coordinate # print(req_p_vpzy) # take ZZZZZ-coordinate print('-------------------------') indices4 = tf.stack([ target_class_horx, target_class_hory, target_class_vpzx, target_class_vpzy ]) # print ("indices4", indices4) classes_map = tf.one_hot(indices4, depth=no_bins, dtype=tf.int32) # return (req_p_horx,req_p_vpzx,req_p_hory,req_p_vpzy) return classes_map, indices4