From 121655a83ebf4a4de8a6c45a39190667161b1f78 Mon Sep 17 00:00:00 2001 From: jshilong Date: Fri, 1 Apr 2022 15:02:51 +0800 Subject: [PATCH 1/3] add quick install command --- docs/en/getting_started.md | 19 +++++++++++++++++++ docs/zh_cn/getting_started.md | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/docs/en/getting_started.md b/docs/en/getting_started.md index a42f3a29e..fef9fde9c 100644 --- a/docs/en/getting_started.md +++ b/docs/en/getting_started.md @@ -37,6 +37,25 @@ The required versions of MMCV, MMDetection and MMSegmentation for different vers ## Install MMDetection3D +### Quick installation instructions script + +Assuming that you already have CUDA 11.0 installed, here is a full script for quick installation of MMDetection3D with conda. +Otherwise, you should refer to the step-by-step installation instructions in the next section. + +```shell +conda create -n open-mmlab python=3.7 pytorch=1.9 cudatoolkit=11.0 torchvision -c pytorch -y +conda activate open-mmlab +pip3 install openmim +mim install mmcv-full +mim install mmdet +mim install mmsegmentation +git clone https://github.com/open-mmlab/mmdetection3d.git +cd mmdetection3d +pip3 install -e . +``` + +### Step-by-step installation instructions + **a. Create a conda virtual environment and activate it.** ```shell diff --git a/docs/zh_cn/getting_started.md b/docs/zh_cn/getting_started.md index 5784e448a..c16db0f72 100644 --- a/docs/zh_cn/getting_started.md +++ b/docs/zh_cn/getting_started.md @@ -34,6 +34,24 @@ ## MMdetection3D 安装流程 +### 快速安装脚本 + +如果你已经成功安装 CUDA 11.0,那么你可以使用这个快速安装命令进行 MMDetection3D 的安装。 否则,则参考下一小节的详细安装流程。 + +```shell +conda create -n open-mmlab python=3.7 pytorch=1.9 cudatoolkit=11.0 torchvision -c pytorch -y +conda activate open-mmlab +pip3 install openmim +mim install mmcv-full +mim install mmdet +mim install mmsegmentation +git clone https://github.com/open-mmlab/mmdetection3d.git +cd mmdetection3d +pip3 install -e . +``` + +### 详细安装流程 + **a. 使用 conda 新建虚拟环境,并进入该虚拟环境。** ```shell From 16f86605d90d65dd278acdd7d5dde50d538cffc8 Mon Sep 17 00:00:00 2001 From: zhangshilong <2392587229zsl@gmail.com> Date: Wed, 27 Apr 2022 11:45:56 +0800 Subject: [PATCH 2/3] fix SyncBatchNorm --- mmdet3d/ops/norm.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/mmdet3d/ops/norm.py b/mmdet3d/ops/norm.py index 52a1363d2..5f4162b9c 100644 --- a/mmdet3d/ops/norm.py +++ b/mmdet3d/ops/norm.py @@ -53,11 +53,27 @@ def __init__(self, *args, **kwargs): # TODO: make mmcv fp16 utils handle customized norm layers @force_fp32(out_fp16=True) def forward(self, input): + """ + Args: + input (tensor): Has shape (N, C) or (N, C, L), where N is + the batch size, C is the number of features or + channels, and L is the sequence length + + Returns: + tensor: Has shape (N, C) or (N, C, L), has same shape + as input. + """ assert input.dtype == torch.float32, \ f'input should be in float32 type, got {input.dtype}' - if dist.get_world_size() == 1 or not self.training: + using_dist = dist.is_available() and dist.is_initialized() + if (not using_dist) or dist.get_world_size() == 1 \ + or not self.training: return super().forward(input) assert input.shape[0] > 0, 'SyncBN does not support empty inputs' + is_two_dim = input.dim() == 2 + if is_two_dim: + input.unsqueeze_(2) + C = input.shape[1] mean = torch.mean(input, dim=[0, 2]) meansqr = torch.mean(input * input, dim=[0, 2]) @@ -76,7 +92,10 @@ def forward(self, input): bias = self.bias - mean * scale scale = scale.reshape(1, -1, 1) bias = bias.reshape(1, -1, 1) - return input * scale + bias + output = input * scale + bias + if is_two_dim: + output = output.squeeze(2) + return output @NORM_LAYERS.register_module('naiveSyncBN2d') @@ -107,9 +126,19 @@ def __init__(self, *args, **kwargs): # TODO: make mmcv fp16 utils handle customized norm layers @force_fp32(out_fp16=True) def forward(self, input): + """ + Args: + Input (tensor): Feature has shape (N, C, H, W). + + Returns: + tensor: Has shape (N, C, H, W), same shape as input. + """ assert input.dtype == torch.float32, \ f'input should be in float32 type, got {input.dtype}' - if dist.get_world_size() == 1 or not self.training: + using_dist = dist.is_available() and dist.is_initialized() + if (not using_dist) or \ + dist.get_world_size() == 1 or \ + not self.training: return super().forward(input) assert input.shape[0] > 0, 'SyncBN does not support empty inputs' From c8c0b5c7f6030d11ea0f4b1fa32adc2efeef4ac3 Mon Sep 17 00:00:00 2001 From: zhangshilong <2392587229zsl@gmail.com> Date: Thu, 28 Apr 2022 14:31:59 +0800 Subject: [PATCH 3/3] fix SyncBatchNorm --- mmdet3d/ops/norm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmdet3d/ops/norm.py b/mmdet3d/ops/norm.py index 5f4162b9c..98ec7f117 100644 --- a/mmdet3d/ops/norm.py +++ b/mmdet3d/ops/norm.py @@ -72,7 +72,7 @@ def forward(self, input): assert input.shape[0] > 0, 'SyncBN does not support empty inputs' is_two_dim = input.dim() == 2 if is_two_dim: - input.unsqueeze_(2) + input = input.unsqueeze(2) C = input.shape[1] mean = torch.mean(input, dim=[0, 2])