Skip to content

SpatialDownsample Documentation

Table of Contents

  1. Introduction
  2. Overview
  3. SpatialDownsample Class
  4. Initialization Parameters
  5. Functionality and Usage
  6. Forward Method
  7. Utility Functions
  8. Examples
  9. Example 1: Creating a SpatialDownsample Module
  10. Example 2: Using SpatialDownsample for Downsampling
  11. Additional Information
  12. References and Resources

1. Introduction

Welcome to the documentation for the Zeta library. This documentation will provide you with comprehensive information on the Zeta library, specifically focusing on the SpatialDownsample class. Before we dive into the details, let's understand the purpose and significance of this library.

1.1 Purpose

The Zeta library is designed to provide essential building blocks for deep learning architectures, making it easier for researchers and developers to implement complex models. It offers various modules and utilities, including the SpatialDownsample class, which is a key component for downsampling spatial dimensions in neural networks.

1.2 Key Features

  • Spatial Downsampling: The SpatialDownsample class allows you to efficiently reduce the spatial dimensions of your data, which is crucial for various computer vision tasks.

  • Integration: Zeta modules seamlessly integrate with popular deep learning frameworks like PyTorch, enabling you to incorporate them into your projects effortlessly.


2. Overview

The Zeta library aims to simplify deep learning model development by providing modular components that adhere to best practices in the field. One such component is the SpatialDownsample class.

2.1 SpatialDownsample Class

The SpatialDownsample class is a module designed for spatial downsampling of 3D tensors. It plays a critical role in architectures like ResNet, where downsampling is necessary to reduce spatial dimensions while increasing the number of channels.

In the following sections, we will explore the SpatialDownsample class's definition, initialization parameters, functionality, and usage.


3. SpatialDownsample Class

The SpatialDownsample class is at the core of Zeta, providing spatial downsampling capabilities for 3D tensors.

3.1 Initialization Parameters

Here are the initialization parameters for the SpatialDownsample class:

  • dim (int): The number of input channels in the tensor.

  • dim_out (int, optional): The number of output channels in the tensor after downsampling. If not specified, it defaults to the same as dim.

  • kernel_size (int): The size of the kernel used for downsampling. It determines the amount of spatial reduction in the output tensor.

3.2 Methods

The primary method of the SpatialDownsample class is the forward method, which performs the spatial downsampling operation on input tensors.


4. Functionality and Usage

Let's delve into the functionality and usage of the SpatialDownsample class.

4.1 Forward Method

The forward method of the SpatialDownsample class takes an input tensor and applies spatial downsampling using a convolution operation. Here are the parameters:

  • x (Tensor): The input tensor of shape (batch, channels, time, height, width).

The method returns a downsampled tensor of shape (batch, output_channels, time, height, width).

4.2 Usage Examples

Example 1: Creating a SpatialDownsample Module

In this example, we create an instance of the SpatialDownsample class with default settings:

downsample = SpatialDownsample(dim=64, kernel_size=3)

Example 2: Using SpatialDownsample for Downsampling

Here, we demonstrate how to use the SpatialDownsample module for downsampling an input tensor:

downsample = SpatialDownsample(dim=64, kernel_size=3)
input_data = torch.randn(1, 64, 32, 32)
output = downsample(input_data)
print(output.shape)

5. Utility Functions

The Zeta library also provides a set of utility functions used within the modules. These utility functions, such as exists, default, identity, and more, contribute to the modularity and flexibility of the library.


6. Additional Information

Here are some additional tips and information for using the Zeta library and the SpatialDownsample class effectively:

  • Experiment with different kernel sizes to control the amount of downsampling according to your specific model requirements.

  • Ensure that the input tensor (x) has the appropriate shape (batch, channels, time, height, width).


7. References and Resources

For further information and resources related to the Zeta library and deep learning, please refer to the following:

This concludes the documentation for the Zeta library and the SpatialDownsample class. You now have a comprehensive understanding of how to use this library and module for your deep learning projects. If you have any further questions or need assistance, please refer to the provided references and resources. Happy modeling with Zeta!