hcat.backends

class hcat.backends.convNeXt.Block(dim, drop_path=0.0, layer_scale_init_value=1e-06)

ConvNeXt Block. There are two equivalent implementations: (1) DwConv -> LayerNorm (channels_first) -> 1x1 Conv -> GELU -> 1x1 Conv; all in (N, C, H, W) (2) DwConv -> Permute to (N, H, W, C); LayerNorm (channels_last) -> Linear -> GELU -> Linear; Permute back We use (2) as we find it slightly faster in PyTorch

Args:

dim (int): Number of input channels. drop_path (float): Stochastic depth rate. Default: 0.0 layer_scale_init_value (float): Init value for Layer Scale. Default: 1e-6.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

Parameters:
  • dim (int) –

  • drop_path (Optional[float]) –

  • layer_scale_init_value (Optional[float]) –

forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor) –

Return type:

Tensor

class hcat.backends.convNeXt.ConvNeXt(in_channels=3, depths=[3, 3, 9, 3], dims=[96, 192, 384, 768], drop_path_rate=0.0, layer_scale_init_value=1e-06, out_indices=[0, 1, 2, 3], out_channels=256)
A PyTorch impl ofA ConvNet for the 2020s -

https://arxiv.org/pdf/2201.03545.pdf

Args:

in_channels (int): Number of input image channels. Default: 3 depths (tuple(int)): Number of blocks at each stage. Default: [3, 3, 9, 3] dims (int): Feature dimension at each stage. Default: [96, 192, 384, 768] drop_path_rate (float): Stochastic depth rate. Default: 0. layer_scale_init_value (float): Init value for Layer Scale. Default: 1e-6.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

Parameters:
  • in_channels (Optional[int]) –

  • depths (Optional[List[int]]) –

  • dims (Optional[List[int]]) –

  • drop_path_rate (Optional[float]) –

  • layer_scale_init_value (Optional[float]) –

  • out_indices (Optional[List[int]]) –

  • out_channels (int) –

forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

init_weights(pretrained=None)

Initialize the weights in backbone. Args:

pretrained (str, optional): Path to pre-trained weights.

Defaults to None.

class hcat.backends.convNeXt.LayerNorm(normalized_shape, eps=1e-06, data_format='channels_last')

LayerNorm that supports two data formats: channels_last (default) or channels_first. The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch_size, height, width, channels) while channels_first corresponds to inputs with shape (batch_size, channels, height, width).

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor) –

Return type:

Tensor

hcat.backends.detection.FasterRCNN_from_url(url, device, path=None)

Loads a FasterRCNN model from a url OR from a local source if available.

Parameters:
  • url (str) – URL of pretrained model path. Will save the model to the source directory of HCAT.

  • device (str) – Device to load the model to.

  • path (Optional[str]) –

Returns:

hcat.backends.detection.init_model()

Initalizes the Faster RCNN detection model for HCAT.

Returns:

Faster RCNN model