Row 6418

Row ID: 6418 | Dataset Entry | Axioma AXP Content Repository

Content Data

This page contains data entry 6418 from the Axioma AXP content repository. The structured data below represents the complete record for this entry.

Hi,

I am trying to calculate the Sum of Absolute Difference (SAD) metric of moving windows with respect to images. The current approch I am using relies on manually sliding the windows along the images. The code is attached below. Input: - windows of shape C x H x W (a C amount of different windows) - images of shape C x N x M (C amount of images - image 0 matches with window 0, etc.). Output: - SAD metrics of shape C x (N - H + 1) x (M - W + 1)

I realize that the for-loops are very time consuming. I have tried a convolution-like approach using torch.unfold(), but this lead to memory issues when a lot a channels or large images are input.

def SAD(windows: torch.Tensor, images: torch.Tensor) -> torch.Tensor: height, width = windows.shape[-2:] num_row, num_column = images.shape[-2] - windows.shape[-2], images.shape[-1] - windows.shape[-1] res = torch.zeros((windows.shape[0], num_row + 1, num_column + 1)) windows, images = windows.float(), images.float() for j in range(num_row + 1): for i in range(num_column + 1): ref = images[:, j:j + height, i:i + width] res[:, j, i] = torch.sum(torch.abs(windows - ref), dim=(1, 2)) return res

FieldValue
text Hi, I am trying to calculate the Sum of Absolute Difference (SAD) metric of moving windows with respect to images. The current approch I am using relies on manually sliding the windows along the images. The code is attached below. Input: - windows of shape C x H x W (a C amount of different windows) - images of shape C x N x M (C amount of images - image 0 matches with window 0, etc.). Output: - SAD metrics of shape C x (N - H + 1) x (M - W + 1) I realize that the for-loops …
label r/pytorch
dataType post
communityName r/pytorch
datetime 2024-05-10
username_encoded Z0FBQUFBQm5Lakwya0tOTFlkSHRLOWR6d1NpX01La0diazBEZTZkakRVTDZnRXAyZWlSTGZEb0tZamN6Umg4ZFBnSk51SG5kekozUm1VSElENmFXaVZ5eTM1X2FNRlkzNlE9PQ==
url_encoded Z0FBQUFBQm5Lak9HQWRqd1BJQnk0eDZMdmo5blRmQ2UxWUFrc3VVbU5lWUUtUmk1ejVReW4ySHVYSXpMTDVoLWsxV3pKaWhfcE1YQlk0YWctQ0FLbjNaV2w4QWhQZWpzWGdkX0tnZVFyNkRSYmZhX05Vcm1xOUVaVm9pNUpHM2pLNlBPcUh6TGxkNlRqcG9ZaHViQ21mcVFrNXJ0alJEZlo2eUk0WlozNFpINnZhUkNyVGVWVjF0d29wT2Y1VXo5R193S1JBX18wQzJ1LXMzN1RkNUVMNVUzZHVZUU9TSTQ0UT09

Raw Record

{
  "text": "Hi,\n\nI am trying to calculate the Sum of Absolute Difference (SAD) metric of moving windows with respect to images. The current approch I am using relies on manually sliding the windows along the images. The code is attached below.   \n  \nInput:   \n- windows of shape C x H x W (a C amount of different windows)  \n- images of shape C x N x M (C amount of images - image 0 matches with window 0, etc.).  \n  \nOutput:   \n- SAD metrics of shape C x (N - H + 1) x (M - W + 1)\n\nI realize that the for-loops are very time consuming. I have tried a convolution-like approach using torch.unfold(), but this lead to memory issues when a lot a channels or large images are input.\n\n    def SAD(windows: torch.Tensor, images: torch.Tensor) -> torch.Tensor:\n        height, width = windows.shape[-2:]\n        num_row, num_column = images.shape[-2] - windows.shape[-2], images.shape[-1] - windows.shape[-1]\n    \n        res = torch.zeros((windows.shape[0], num_row + 1, num_column + 1))\n        windows, images = windows.float(), images.float()\n    \n        for j in range(num_row + 1):\n            for i in range(num_column + 1):\n                ref = images[:, j:j + height, i:i + width]\n                res[:, j, i] = torch.sum(torch.abs(windows - ref), dim=(1, 2))\n    \n        return res",
  "label": "r/pytorch",
  "dataType": "post",
  "communityName": "r/pytorch",
  "datetime": "2024-05-10",
  "username_encoded": "Z0FBQUFBQm5Lakwya0tOTFlkSHRLOWR6d1NpX01La0diazBEZTZkakRVTDZnRXAyZWlSTGZEb0tZamN6Umg4ZFBnSk51SG5kekozUm1VSElENmFXaVZ5eTM1X2FNRlkzNlE9PQ==",
  "url_encoded": "Z0FBQUFBQm5Lak9HQWRqd1BJQnk0eDZMdmo5blRmQ2UxWUFrc3VVbU5lWUUtUmk1ejVReW4ySHVYSXpMTDVoLWsxV3pKaWhfcE1YQlk0YWctQ0FLbjNaV2w4QWhQZWpzWGdkX0tnZVFyNkRSYmZhX05Vcm1xOUVaVm9pNUpHM2pLNlBPcUh6TGxkNlRqcG9ZaHViQ21mcVFrNXJ0alJEZlo2eUk0WlozNFpINnZhUkNyVGVWVjF0d29wT2Y1VXo5R193S1JBX18wQzJ1LXMzN1RkNUVMNVUzZHVZUU9TSTQ0UT09"
}

Entry Information