{"id":18273989,"url":"https://github.com/longcw/roialign.pytorch","last_synced_at":"2025-04-05T01:06:00.059Z","repository":{"id":27325946,"uuid":"113186146","full_name":"longcw/RoIAlign.pytorch","owner":"longcw","description":"RoIAlign \u0026 crop_and_resize for PyTorch","archived":false,"fork":false,"pushed_at":"2022-03-01T13:16:52.000Z","size":666,"stargazers_count":556,"open_issues_count":39,"forks_count":104,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-29T00:07:02.721Z","etag":null,"topics":["pytorch"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/longcw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-05T13:32:49.000Z","updated_at":"2025-03-02T15:18:34.000Z","dependencies_parsed_at":"2022-08-07T12:16:09.089Z","dependency_job_id":null,"html_url":"https://github.com/longcw/RoIAlign.pytorch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/longcw%2FRoIAlign.pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/longcw%2FRoIAlign.pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/longcw%2FRoIAlign.pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/longcw%2FRoIAlign.pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/longcw","download_url":"https://codeload.github.com/longcw/RoIAlign.pytorch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271528,"owners_count":20911587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pytorch"],"created_at":"2024-11-05T12:08:16.961Z","updated_at":"2025-04-05T01:06:00.041Z","avatar_url":"https://github.com/longcw.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RoIAlign for PyTorch\nThis is a PyTorch version of [RoIAlign](https://arxiv.org/abs/1703.06870).\nThis implementation is based on `crop_and_resize`\nand supports both forward and backward on CPU and GPU.\n\n**NOTE:** Thanks [meikuam](https://github.com/meikuam) for updating \nthis repo for ***PyTorch 1.0***. You can find the original version for \n`torch \u003c= 0.4.1` in [pytorch_0.4](https://github.com/longcw/RoIAlign.pytorch/tree/pytorch_0.4)\nbranch.\n\n\n## Introduction\nThe `crop_and_resize` function is ported from [tensorflow](https://www.tensorflow.org/api_docs/python/tf/image/crop_and_resize),\nand has the same interface with tensorflow version, except the input feature map\nshould be in `NCHW` order in PyTorch.\nThey also have the same output value (error \u003c 1e-5) for both forward and backward as we expected,\nsee the comparision in `test.py`.\n\n**Note:**\nDocument of `crop_and_resize` can be found [here](https://www.tensorflow.org/api_docs/python/tf/image/crop_and_resize).\nAnd `RoIAlign` is a wrap of `crop_and_resize`\nthat uses boxes with *unnormalized `(x1, y1, x2, y2)`* as input\n(while `crop_and_resize` use *normalized `(y1, x1, y2, x2)`* as input).\nSee more details about the difference of\n `RoIAlign` and `crop_and_resize` in [tensorpack](https://github.com/ppwwyyxx/tensorpack/blob/6d5ba6a970710eaaa14b89d24aace179eb8ee1af/examples/FasterRCNN/model.py#L301).\n\n**Warning:**\nCurrently it only works using the default GPU (index 0)\n\n## Usage\n+ Install and test\n    ```\n    python setup.py install\n    ./test.sh\n    ```\n\n+ Use RoIAlign or crop_and_resize \n    \n    Since PyTorch 1.2.0 [Legacy autograd function with non-static forward method is deprecated.](https://github.com/pytorch/pytorch/blob/fdfc676eb6c4d9f50496e564976fbe6d124e23a5/torch/csrc/autograd/python_function.cpp#L636-L638)\n    We use new-style autograd function with static forward method. Example:\n    ```python\n    import torch\n    from roi_align import RoIAlign      # RoIAlign module\n    from roi_align import CropAndResize # crop_and_resize module\n    \n    # input feature maps (suppose that we have batch_size==2)\n    image = torch.arange(0., 49).view(1, 1, 7, 7).repeat(2, 1, 1, 1)\n    image[0] += 10\n    print('image: ', image)\n    \n    \n    # for example, we have two bboxes with coords xyxy (first with batch_id=0, second with batch_id=1).\n    boxes = torch.Tensor([[1, 0, 5, 4],\n                         [0.5, 3.5, 4, 7]])\n    \n    box_index = torch.tensor([0, 1], dtype=torch.int) # index of bbox in batch\n    \n    # RoIAlign layer with crop sizes:\n    crop_height = 4\n    crop_width = 4\n    roi_align = RoIAlign(crop_height, crop_width)\n    \n    # make crops:\n    crops = roi_align(image, boxes, box_index)\n    \n    print('crops:', crops)\n    ```\n    Output:\n    ```python\n    image:  tensor([[[[10., 11., 12., 13., 14., 15., 16.],\n          [17., 18., 19., 20., 21., 22., 23.],\n          [24., 25., 26., 27., 28., 29., 30.],\n          [31., 32., 33., 34., 35., 36., 37.],\n          [38., 39., 40., 41., 42., 43., 44.],\n          [45., 46., 47., 48., 49., 50., 51.],\n          [52., 53., 54., 55., 56., 57., 58.]]],\n\n\n        [[[ 0.,  1.,  2.,  3.,  4.,  5.,  6.],\n          [ 7.,  8.,  9., 10., 11., 12., 13.],\n          [14., 15., 16., 17., 18., 19., 20.],\n          [21., 22., 23., 24., 25., 26., 27.],\n          [28., 29., 30., 31., 32., 33., 34.],\n          [35., 36., 37., 38., 39., 40., 41.],\n          [42., 43., 44., 45., 46., 47., 48.]]]])\n          \n    crops: tensor([[[[11.0000, 12.0000, 13.0000, 14.0000],\n              [18.0000, 19.0000, 20.0000, 21.0000],\n              [25.0000, 26.0000, 27.0000, 28.0000],\n              [32.0000, 33.0000, 34.0000, 35.0000]]],\n    \n    \n            [[[24.5000, 25.3750, 26.2500, 27.1250],\n              [30.6250, 31.5000, 32.3750, 33.2500],\n              [36.7500, 37.6250, 38.5000, 39.3750],\n              [ 0.0000,  0.0000,  0.0000,  0.0000]]]])\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flongcw%2Froialign.pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flongcw%2Froialign.pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flongcw%2Froialign.pytorch/lists"}