pytorch3d.implicitron.tools

Tools for implicitron

pytorch3d.implicitron.tools.camera_utils.jitter_extrinsics(R: Tensor, T: Tensor, max_angle: float = 6.283185307179586, translation_std: float = 1.0, scale_std: float = 0.3)[source]

Jitter the extrinsic camera parameters R and T with a random similarity transformation. The transformation rotates by a random angle between [0, max_angle]; scales by a random factor exp(N(0, scale_std)), where N(0, scale_std) is a random sample from a normal distrubtion with zero mean and variance scale_std; and translates by a 3D offset sampled from N(0, translation_std).

pytorch3d.implicitron.tools.camera_utils.apply_camera_alignment(R: Tensor, T: Tensor, rigid_transform: Tensor, scale: Tensor)[source]
Parameters:
  • R – Camera rotation matrix of shape (N, 3, 3).

  • T – Camera translation of shape (N, 3).

  • rigid_transform – A tensor of shape (N, 4, 4) representing a batch of N 4x4 tensors that map the scene pointcloud from misaligned coords to the aligned space.

  • scale – A list of N scaling factors. A tensor of shape (N,)

Returns:

R_aligned – The aligned rotations R. T_aligned: The aligned translations T.

pytorch3d.implicitron.tools.camera_utils.get_min_max_depth_bounds(cameras, scene_center, scene_extent)[source]

Estimate near/far depth plane as: near = dist(cam_center, self.scene_center) - self.scene_extent far = dist(cam_center, self.scene_center) + self.scene_extent

pytorch3d.implicitron.tools.camera_utils.volumetric_camera_overlaps(cameras: CamerasBase, scene_extent: float = 8.0, scene_center: Tuple[float, float, float] = (0.0, 0.0, 0.0), resol: int = 16, weigh_by_ray_angle: bool = True)[source]

Compute the overlaps between viewing frustrums of all pairs of cameras in cameras.

pytorch3d.implicitron.tools.circle_fitting.get_rotation_to_best_fit_xy(points: Tensor, centroid: Tensor | None = None) Tensor[source]

Returns a rotation R such that points @ R has a best fit plane parallel to the xy plane

Parameters:
  • points – (*, N, 3) tensor of points in 3D

  • centroid – (*, 1, 3), (3,) or scalar: their centroid

Returns:

(*, 3, 3) tensor rotation matrix

class pytorch3d.implicitron.tools.circle_fitting.Circle2D(center: Tensor, radius: Tensor, generated_points: Tensor)[source]

Bases: object

Contains details of a circle in a plane. Members

center: tensor shape (2,) radius: tensor shape () generated_points: points around the circle, shape (n_points, 2)

center: Tensor
radius: Tensor
generated_points: Tensor
pytorch3d.implicitron.tools.circle_fitting.fit_circle_in_2d(points2d, *, n_points: int = 0, angles: Tensor | None = None) Circle2D[source]

Simple best fitting of a circle to 2D points. In particular, the circle which minimizes the sum of the squares of the squared-distances to the circle.

Finds (a,b) and r to minimize the sum of squares (over the x,y pairs) of

r**2 - [(x-a)**2+(y-b)**2]

i.e.

(2*a)*x + (2*b)*y + (r**2 - a**2 - b**2)*1 - (x**2 + y**2)

In addition, generates points along the circle. If angles is None (default) then n_points around the circle equally spaced are given. These begin at the point closest to the first input point. They continue in the direction which seems to match the movement of points in points2d, as judged by its signed area. If angles are provided, then n_points is ignored, and points along the circle at the given angles are returned, with the starting point and direction as before.

(Note that generated_points is affected by the order of the points in points2d, but the other outputs are not.)

Parameters:
  • points2d – N x 2 tensor of 2D points

  • n_points – number of points to generate on the circle, if angles not given

  • angles – optional angles in radians of points to generate.

Returns:

Circle2D object

class pytorch3d.implicitron.tools.circle_fitting.Circle3D(center: Tensor, radius: Tensor, normal: Tensor, generated_points: Tensor)[source]

Bases: object

Contains details of a circle in 3D. Members

center: tensor shape (3,) radius: tensor shape () normal: tensor shape (3,) generated_points: points around the circle, shape (n_points, 3)

center: Tensor
radius: Tensor
normal: Tensor
generated_points: Tensor
pytorch3d.implicitron.tools.circle_fitting.fit_circle_in_3d(points, *, n_points: int = 0, angles: Tensor | None = None, offset: Tensor | None = None, up: Tensor | None = None) Circle3D[source]

Simple best fit circle to 3D points. Uses circle_2d in the least-squares best fit plane.

In addition, generates points along the circle. If angles is None (default) then n_points around the circle equally spaced are given. These begin at the point closest to the first input point. They continue in the direction which seems to be match the movement of points. If angles is provided, then n_points is ignored, and points along the circle at the given angles are returned, with the starting point and direction as before.

Further, an offset can be given to add to the generated points; this is interpreted in a rotated coordinate system where (0, 0, 1) is normal to the circle, specifically the normal which is approximately in the direction of a given up vector. The remaining rotation is disambiguated in an unspecified but deterministic way.

(Note that generated_points is affected by the order of the points in points, but the other outputs are not.)

Parameters:
  • points2d – N x 3 tensor of 3D points

  • n_points – number of points to generate on the circle

  • angles – optional angles in radians of points to generate.

  • offset – optional tensor (3,), a displacement expressed in a “canonical” coordinate system to add to the generated points.

  • up – optional tensor (3,), a vector which helps define the “canonical” coordinate system for interpretting offset. Required if offset is used.

Returns:

Circle3D object

class pytorch3d.implicitron.tools.config.ReplaceableBase(*args, **kwargs)[source]

Bases: object

Base class for a class (a “replaceable”) which is a base class for dataclass-style implementations. The implementations can be stored in the registry. They get expanded into dataclasses with expand_args_fields. This expansion is delayed.

static __new__(cls, *args, **kwargs)[source]

These classes should be expanded only when needed (because processing fixes the list of replaceable subclasses of members of the class). It is safer if users expand the classes explicitly. But if the class gets instantiated when it hasn’t been processed, we expand it here.

class pytorch3d.implicitron.tools.config.Configurable(*args, **kwargs)[source]

Bases: object

Base class for dataclass-style classes which are not replaceable. These get expanded into a dataclass with expand_args_fields. This expansion is delayed.

static __new__(cls, *args, **kwargs)[source]

These classes should be expanded only when needed (because processing fixes the list of replaceable subclasses of members of the class). It is safer if users expand the classes explicitly. But if the class gets instantiated when it hasn’t been processed, we expand it here.

pytorch3d.implicitron.tools.config.run_auto_creation(self: Any) None[source]

Run all the functions named in self._creation_functions.

pytorch3d.implicitron.tools.config.get_default_args(C, *, _do_not_process: Tuple[type, ...] = ()) DictConfig[source]

Get the DictConfig corresponding to the defaults in a dataclass or configurable. Normal use is to provide a dataclass can be provided as C. If enable_get_default_args has been called on a function or plain class, then that function or class can be provided as C.

If C is a subclass of Configurable or ReplaceableBase, we make sure it has been processed with expand_args_fields.

Parameters:
  • C – the class or function to be processed

  • _do_not_process – (internal use) When this function is called from expand_args_fields, we specify any class currently being processed, to make sure we don’t try to process a class while it is already being processed.

Returns:

new DictConfig object, which is typed.

pytorch3d.implicitron.tools.config.enable_get_default_args(C: Any, *, overwrite: bool = True) None[source]

If C is a function or a plain class with an __init__ function, and you want get_default_args(C) to work, then add enable_get_default_args(C) straight after the definition of C. This makes a dataclass corresponding to the default arguments of C and stores it in the same module as C.

Parameters:
  • C – a function, or a class with an __init__ function. Must have types for all its defaulted args.

  • overwrite – whether to allow calling this a second time on the same function.

pytorch3d.implicitron.tools.config.expand_args_fields(some_class: Type[Y], *, _do_not_process: Tuple[type, ...] = ()) Type[Y][source]

This expands a class which inherits Configurable or ReplaceableBase classes, including dataclass processing. some_class is modified in place by this function. If expand_args_fields(some_class) has already been called, subsequent calls do nothing and return some_class unmodified. For classes of type ReplaceableBase, you can add some_class to the registry before or after calling this function. But potential inner classes need to be registered before this function is run on the outer class.

The transformations this function makes, before the concluding dataclasses.dataclass, are as follows. If X is a base class with registered subclasses Y and Z, replace a class member

x: X

and optionally

x_class_type: str = “Y” def create_x(self):…

with

x_Y_args: dict = dataclasses.field(default_factory=lambda: get_default_args(Y)) x_Z_args: dict = dataclasses.field(default_factory=lambda: get_default_args(Z)) def create_x(self):

args = self.getattr(f”x_{self.x_class_type}_args”) self.create_x_impl(self.x_class_type, args)

def create_x_impl(self, x_type, args):

x_type = registry.get(X, x_type) expand_args_fields(x_type) self.x = x_type(**args)

x_class_type: str = “UNDEFAULTED”

without adding the optional attributes if they are already there.

Similarly, replace

x: Optional[X]

and optionally

x_class_type: Optional[str] = “Y” def create_x(self):…

with

x_Y_args: dict = dataclasses.field(default_factory=lambda: get_default_args(Y)) x_Z_args: dict = dataclasses.field(default_factory=lambda: get_default_args(Z)) def create_x(self):

if self.x_class_type is None:

args = None

else:

args = self.getattr(f”x_{self.x_class_type}_args”, None)

self.create_x_impl(self.x_class_type, args)

def create_x_impl(self, x_class_type, args):
if x_class_type is None:

self.x = None return

x_type = registry.get(X, x_class_type) expand_args_fields(x_type) assert args is not None self.x = x_type(**args)

x_class_type: Optional[str] = “UNDEFAULTED”

without adding the optional attributes if they are already there.

Similarly, if X is a subclass of Configurable,

x: X

and optionally

def create_x(self):…

will be replaced with

x_args: dict = dataclasses.field(default_factory=lambda: get_default_args(X)) def create_x(self):

self.create_x_impl(True, self.x_args)

def create_x_impl(self, enabled, args):
if enabled:

expand_args_fields(X) self.x = X(**args)

else:

self.x = None

Similarly, replace,

x: Optional[X] x_enabled: bool = …

and optionally

def create_x(self):…

with

x_args: dict = dataclasses.field(default_factory=lambda: get_default_args(X)) x_enabled: bool = … def create_x(self):

self.create_x_impl(self.x_enabled, self.x_args)

def create_x_impl(self, enabled, args):
if enabled:

expand_args_fields(X) self.x = X(**args)

else:

self.x = None

Also adds the following class members, unannotated so that dataclass ignores them.

  • _creation_functions: Tuple[str, …] of all the create_ functions,

    including those from base classes (not the create_x_impl ones).

  • _known_implementations: Dict[str, Type] containing the classes which

    have been found from the registry. (used only to raise a warning if it one has been overwritten)

  • _processed_members: a Dict[str, Any] of all the members which have been

    transformed, with values giving the types they were declared to have. (E.g. {“x”: X} or {“x”: Optional[X]} in the cases above.)

In addition, if the class has a member function

@classmethod def x_tweak_args(cls, member_type: Type, args: DictConfig) -> None

then the default_factory of x_args will also have a call to x_tweak_args(X, x_args) and the default_factory of x_Y_args will also have a call to x_tweak_args(Y, x_Y_args).

In addition, if the class inherits torch.nn.Module, the generated __init__ will call torch.nn.Module’s __init__ before doing anything else.

Before any transformation of the class, if the class has a classmethod called pre_expand, it will be called with no arguments.

Note that although the *_args members are intended to have type DictConfig, they are actually internally annotated as dicts. OmegaConf is happy to see a DictConfig in place of a dict, but not vice-versa. Allowing dict lets a class user specify x_args as an explicit dict without getting an incomprehensible error.

Parameters:
  • some_class – the class to be processed

  • _do_not_process – Internal use for get_default_args: Because get_default_args calls and is called by this function, we let it specify any class currently being processed, to make sure we don’t try to process a class while it is already being processed.

Returns:

some_class itself, which has been modified in place. This allows this function to be used as a class decorator.

pytorch3d.implicitron.tools.config.get_default_args_field(C, *, _do_not_process: Tuple[type, ...] = (), _hook: Callable[[DictConfig], None] | None = None)[source]

Get a dataclass field which defaults to get_default_args(…)

Parameters:
  • C – As for get_default_args.

  • _do_not_process – As for get_default_args

  • _hook – Function called on the result before returning.

Returns:

function to return new DictConfig object

pytorch3d.implicitron.tools.config.remove_unused_components(dict_: DictConfig) None[source]

Assuming dict_ represents the state of a configurable, modify it to remove all the portions corresponding to pluggable parts which are not in use. For example, if renderer_class_type is SignedDistanceFunctionRenderer, the renderer_MultiPassEmissionAbsorptionRenderer_args will be removed. Also, if chocolate_enabled is False, then chocolate_args will be removed.

Parameters:

dict – (MODIFIED IN PLACE) a DictConfig instance

pytorch3d.implicitron.tools.eval_video_trajectory.generate_eval_video_cameras(train_cameras, n_eval_cams: int = 100, trajectory_type: str = 'figure_eight', trajectory_scale: float = 0.2, scene_center: Tuple[float, float, float] = (0.0, 0.0, 0.0), up: Tuple[float, float, float] = (0.0, 0.0, 1.0), focal_length: Tensor | None = None, principal_point: Tensor | None = None, time: Tensor | None = None, infer_up_as_plane_normal: bool = True, traj_offset: Tuple[float, float, float] | None = None, traj_offset_canonical: Tuple[float, float, float] | None = None, remove_outliers_rate: float = 0.0) PerspectiveCameras[source]

Generate a camera trajectory rendering a scene from multiple viewpoints.

Parameters:
  • train_cameras – The set of cameras from the training dataset object.

  • n_eval_cams – Number of cameras in the trajectory.

  • trajectory_type

    The type of the camera trajectory. Can be one of: circular_lsq_fit: Camera centers follow a trajectory obtained

    by fitting a 3D circle to train_cameras centers. All cameras are looking towards scene_center.

    figure_eight: Figure-of-8 trajectory around the center of the

    central camera of the training dataset.

    trefoil_knot: Same as ‘figure_eight’, but the trajectory has a shape

    of a trefoil knot (https://en.wikipedia.org/wiki/Trefoil_knot).

    figure_eight_knot: Same as ‘figure_eight’, but the trajectory has a shape

    of a figure-eight knot (https://en.wikipedia.org/wiki/Figure-eight_knot_(mathematics)).

  • trajectory_scale – The extent of the trajectory.

  • scene_center – The center of the scene in world coordinates which all the cameras from the generated trajectory look at.

  • up – The “circular_lsq_fit” vector of the scene (=the normal of the scene floor). Active for the trajectory_type=”circular”.

  • focal_length – The focal length of the output cameras. If None, an average focal length of the train_cameras is used.

  • principal_point – The principal point of the output cameras. If None, an average principal point of all train_cameras is used.

  • time – Defines the total length of the generated camera trajectory. All possible trajectories (set with the trajectory_type argument) are periodic with the period of time=2pi. E.g. setting trajectory_type=circular_lsq_fit and time=4pi, will generate a trajectory of camera poses rotating the total of 720 deg around the object.

  • infer_up_as_plane_normal – Infer the camera up vector automatically as the normal of the plane fit to the optical centers of train_cameras.

  • traj_offset – 3D offset vector added to each point of the trajectory.

  • traj_offset_canonical – 3D offset vector expressed in the local coordinates of the estimated trajectory which is added to each point of the trajectory.

  • remove_outliers_rate – the number between 0 and 1; if > 0, some outlier train_cameras will be removed from trajectory estimation; the filtering is based on camera center coordinates; top and bottom remove_outliers_rate cameras on each dimension are removed.

Returns:

Batch of camera instances which can be used as the test dataset

pytorch3d.implicitron.tools.image_utils.mask_background(image_rgb: Tensor, mask_fg: Tensor, dim_color: int = 1, bg_color: Tensor | Sequence | str | float = 0.0) Tensor[source]

Mask the background input image tensor image_rgb with bg_color. The background regions are obtained from the binary foreground segmentation mask mask_fg.

pytorch3d.implicitron.tools.metric_utils.eval_depth(pred: Tensor, gt: Tensor, crop: int = 1, mask: Tensor | None = None, get_best_scale: bool = True, mask_thr: float = 0.5, best_scale_clamp_thr: float = 0.0001) Tuple[Tensor, Tensor][source]

Evaluate the depth error between the prediction pred and the ground truth gt.

Parameters:
  • pred – A tensor of shape (N, 1, H, W) denoting the predicted depth maps.

  • gt – A tensor of shape (N, 1, H, W) denoting the ground truth depth maps.

  • crop – The number of pixels to crop from the border.

  • mask – A mask denoting the valid regions of the gt depth.

  • get_best_scale – If True, estimates a scaling factor of the predicted depth that yields the best mean squared error between pred and gt. This is typically enabled for cases where predicted reconstructions are inherently defined up to an arbitrary scaling factor.

  • mask_thr – A constant used to threshold the mask to specify the valid regions.

  • best_scale_clamp_thr – The threshold for clamping the divisor in best scale estimation.

Returns:

mse_depth – Mean squared error between pred and gt. abs_depth: Mean absolute difference between pred and gt.

pytorch3d.implicitron.tools.metric_utils.estimate_depth_scale_factor(pred, gt, mask, clamp_thr)[source]
pytorch3d.implicitron.tools.metric_utils.calc_psnr(x: Tensor, y: Tensor, mask: Tensor | None = None) Tensor[source]

Calculates the Peak-signal-to-noise ratio between tensors x and y.

pytorch3d.implicitron.tools.metric_utils.calc_mse(x: Tensor, y: Tensor, mask: Tensor | None = None) Tensor[source]

Calculates the mean square error between tensors x and y.

pytorch3d.implicitron.tools.metric_utils.calc_bce(pred: Tensor, gt: Tensor, equal_w: bool = True, pred_eps: float = 0.01, mask: Tensor | None = None, lerp_bound: float | None = None) Tensor[source]

Calculates the binary cross entropy.

pytorch3d.implicitron.tools.metric_utils.binary_cross_entropy_lerp(pred: Tensor, gt: Tensor, weight: Tensor, lerp_bound: float)[source]

Binary cross entropy which avoids exploding gradients by linearly extrapolating the log function for log(1-pred) mad log(pred) whenever pred or 1-pred is smaller than lerp_bound.

pytorch3d.implicitron.tools.metric_utils.log_lerp(x: Tensor, b: float)[source]

Linearly extrapolated log for x < b.

pytorch3d.implicitron.tools.metric_utils.rgb_l1(pred: Tensor, target: Tensor, mask: Tensor | None = None) Tensor[source]

Calculates the mean absolute error between the predicted colors pred and ground truth colors target.

pytorch3d.implicitron.tools.metric_utils.huber(dfsq: Tensor, scaling: float = 0.03) Tensor[source]

Calculates the huber function of the input squared error dfsq. The function smoothly transitions from a region with unit gradient to a hyperbolic function at dfsq=scaling.

pytorch3d.implicitron.tools.metric_utils.neg_iou_loss(predict: Tensor, target: Tensor, mask: Tensor | None = None) Tensor[source]

This is a great loss because it emphasizes on the active regions of the predict and targets

pytorch3d.implicitron.tools.metric_utils.safe_sqrt(A: Tensor, eps: float = 0.0001) Tensor[source]

performs safe differentiable sqrt

pytorch3d.implicitron.tools.metric_utils.iou(predict: Tensor, target: Tensor, mask: Tensor | None = None) Tensor[source]

This is a great loss because it emphasizes on the active regions of the predict and targets

pytorch3d.implicitron.tools.metric_utils.beta_prior(pred: Tensor, cap: float = 0.1) Tensor[source]
pytorch3d.implicitron.tools.model_io.load_stats(flstats)[source]
pytorch3d.implicitron.tools.model_io.get_model_path(fl) str[source]
pytorch3d.implicitron.tools.model_io.get_optimizer_path(fl) str[source]
pytorch3d.implicitron.tools.model_io.get_stats_path(fl, eval_results: bool = False) str[source]
pytorch3d.implicitron.tools.model_io.safe_save_model(model, stats, fl, optimizer=None, cfg=None) None[source]

This functions stores model files safely so that no model files exist on the file system in case the saving procedure gets interrupted.

This is done first by saving the model files to a temporary directory followed by (atomic) moves to the target location. Note, that this can still result in a corrupt set of model files in case interruption happens while performing the moves. It is however quite improbable that a crash would occur right at this time.

pytorch3d.implicitron.tools.model_io.save_model(model, stats, fl, optimizer=None, cfg=None)[source]
pytorch3d.implicitron.tools.model_io.save_stats(stats, fl, cfg=None)[source]
pytorch3d.implicitron.tools.model_io.load_model(fl, map_location: dict | None)[source]
pytorch3d.implicitron.tools.model_io.parse_epoch_from_model_path(model_path) int[source]
pytorch3d.implicitron.tools.model_io.get_checkpoint(exp_dir, epoch)[source]
pytorch3d.implicitron.tools.model_io.find_last_checkpoint(exp_dir, any_path: bool = False, all_checkpoints: bool = False)[source]
pytorch3d.implicitron.tools.model_io.purge_epoch(exp_dir, epoch) None[source]
pytorch3d.implicitron.tools.point_cloud_utils.get_rgbd_point_cloud(camera: CamerasBase, image_rgb: Tensor, depth_map: Tensor, mask: Tensor | None = None, mask_thr: float = 0.5, *, euclidean: bool = False) Pointclouds[source]

Given a batch of images, depths, masks and cameras, generate a single colored point cloud by unprojecting depth maps and coloring with the source pixel colors.

Parameters:
  • camera – Batch of N cameras

  • image_rgb – Batch of N images of shape (N, C, H, W). For RGB images C=3.

  • depth_map – Batch of N depth maps of shape (N, 1, H’, W’). Only positive values here are used to generate points. If euclidean=False (default) this contains perpendicular distances from each point to the camera plane (z-values). If euclidean=True, this contains distances from each point to the camera center.

  • mask – If provided, batch of N masks of the same shape as depth_map. If provided, values in depth_map are ignored if the corresponding element of mask is smaller than mask_thr.

  • mask_thr – used in interpreting mask

  • euclidean – used in interpreting depth_map.

Returns:

Pointclouds object containing one point cloud.

pytorch3d.implicitron.tools.point_cloud_utils.render_point_cloud_pytorch3d(camera, point_cloud, render_size: Tuple[int, int], point_radius: float = 0.03, topk: int = 10, eps: float = 0.01, bg_color=None, bin_size: int | None = None, **kwargs)[source]
pytorch3d.implicitron.tools.rasterize_mc.rasterize_sparse_ray_bundle(ray_bundle: ImplicitronRayBundle, features: Tensor, image_size_hw: Tuple[int, int], depth: Tensor, masks: Tensor | None = None) Tuple[Tensor, Tensor, Tensor][source]

Rasterizes sparse features corresponding to the coordinates defined by the rays in the bundle.

Parameters:
  • ray_bundle – ray bundle object with B x … x 2 pixel coordinates, it can be packed.

  • features – B x … x C tensor containing per-point rendered features.

  • image_size_hw – Tuple[image_height, image_width] containing the size of rasterized image.

  • depth – B x … x 1 tensor containing per-point rendered depth.

  • masks – B x … x 1 tensor containing the alpha mask of the rendered features.

Returns:

- image_render – B x C x H x W tensor of rasterized features - depths_render: B x 1 x H x W tensor of rasterized depth maps - masks_render: B x 1 x H x W tensor of opacities after splatting

pytorch3d.implicitron.tools.rasterize_mc.rasterize_mc_samples(xys: Tensor, feats: Tensor, image_size_hw: Tuple[int, int], radius: float = 0.03, topk: int = 5, masks: Tensor | None = None) Tuple[Tensor, Tensor][source]

Rasterizes Monte-Carlo sampled features back onto the image.

Specifically, the code uses the PyTorch3D point rasterizer to render a z-flat point cloud composed of the xy MC locations and their features.

Parameters:
  • xys – B x N x 2 2D point locations in PyTorch3D NDC convention

  • feats – B x N x dim tensor containing per-point rendered features.

  • image_size_hw – Tuple[image_height, image_width] containing the size of rasterized image.

  • radius – Rasterization point radius.

  • topk – The maximum z-buffer size for the PyTorch3D point cloud rasterizer.

  • masks – B x N x 1 tensor containing the alpha mask of the rendered features.

pytorch3d.implicitron.tools.vis_utils.get_visdom_env(visdom_env: str, exp_dir: str) str[source]

Parse out visdom environment name from the input config.

Parameters:
  • visdom_env – Name of the wisdom environment, could be empty string.

  • exp_dir – Root experiment directory.

Returns:

visdom_env

The name of the visdom environment. If the given visdom_env is

empty, return the name of the bottom directory in exp_dir.

pytorch3d.implicitron.tools.vis_utils.get_visdom_connection(server: str = 'http://localhost', port: int = 8097) Visdom | None[source]

Obtain a connection to a visdom server if visdom is installed.

Parameters:
  • server – Server address.

  • port – Server port.

Returns:

connection – The connection object.

pytorch3d.implicitron.tools.vis_utils.visualize_basics(viz: Visdom, preds: Dict[str, Any], visdom_env_imgs: str, title: str = '', visualize_preds_keys: Tuple[str, ...] = ('image_rgb', 'images_render', 'fg_probability', 'masks_render', 'depths_render', 'depth_map'), store_history: bool = False) None[source]

Visualize basic outputs of a GenericModel to visdom.

Parameters:
  • viz – The visdom object.

  • preds – A dictionary containing GenericModel outputs.

  • visdom_env_imgs – Target visdom environment name.

  • title – The title of produced visdom window.

  • visualize_preds_keys – The list of keys of preds for visualization.

  • store_history – Store the history buffer in visdom windows.

pytorch3d.implicitron.tools.vis_utils.make_depth_image(depths: Tensor, masks: Tensor, max_quantile: float = 0.98, min_quantile: float = 0.02, min_out_depth: float = 0.1, max_out_depth: float = 0.9) Tensor[source]

Convert a batch of depth maps to a grayscale image.

Parameters:
  • depths – A tensor of shape (B, 1, H, W) containing a batch of depth maps.

  • masks – A tensor of shape (B, 1, H, W) containing a batch of foreground masks.

  • max_quantile – The quantile of the input depth values which will be mapped to max_out_depth.

  • min_quantile – The quantile of the input depth values which will be mapped to min_out_depth.

  • min_out_depth – The minimal value in each depth map will be assigned this color.

  • max_out_depth – The maximal value in each depth map will be assigned this color.

Returns:

depth_image

A tensor of shape (B, 1, H, W) a batch of grayscale

depth images.