[Docs] Add code-spell pre-commit hook and fix a large mount of typos. (#470)

* Add code spell check hook

* Add codespell config

* Fix a lot of typos.

* Add formating.py to keep compatibility.
pull/489/head
Ma Zerun 2021-10-13 14:33:07 +08:00 committed by GitHub
parent 6fba107840
commit 2e6c7cf87d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 255 additions and 239 deletions

View File

@ -35,6 +35,10 @@ repos:
- id: markdownlint
args: ["-r", "~MD002,~MD013,~MD029,~MD033,~MD034",
"-t", "allow_different_nesting"]
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
- repo: https://github.com/myint/docformatter
rev: v1.3.1
hooks:

View File

@ -48,7 +48,7 @@
- Add `hparams` argument in `AutoAugment` and `RandAugment` and some other improvement. ([#398](https://github.com/open-mmlab/mmclassification/pull/398))
- Support classwise weight in losses. ([#388](https://github.com/open-mmlab/mmclassification/pull/388))
- Enhence `SELayer` to support custom squeeze channels. ([#417](https://github.com/open-mmlab/mmclassification/pull/417))
- Enhance `SELayer` to support custom squeeze channels. ([#417](https://github.com/open-mmlab/mmclassification/pull/417))
### Code Refactor
@ -118,7 +118,7 @@
- Improve test tools and add some new tools. (#322)
- Correct MobilenetV3 backbone structure and add pretained models. (#291)
- Refactor `PatchEmbed` and `HybridEmbed` as independent components. (#330)
- Refactor mixup and cutmix as `Augments` to support more funtions. (#278)
- Refactor mixup and cutmix as `Augments` to support more functions. (#278)
- Refactor weights initialization method. (#270, #318, #319)
- Refactor `LabelSmoothLoss` to support multiple calculation formulas. (#285)

View File

@ -66,7 +66,7 @@ PyTorch 1.3.1., you need to install the prebuilt PyTorch with CUDA 9.2.
conda install pytorch=1.3.1 cudatoolkit=9.2 torchvision=0.4.2 -c pytorch
```
If you build PyTorch from source instead of installing the prebuilt pacakge,
If you build PyTorch from source instead of installing the prebuilt package,
you can use more CUDA versions such as 9.0.
c. Install MMClassification repository.

View File

@ -44,7 +44,7 @@ curl -O https://raw.githubusercontent.com/pytorch/serve/master/docs/images/3dogs
curl http://127.0.0.1:8080/predictions/${MODEL_NAME} -T 3dogs.jpg
```
You should obtain a respose similar to:
You should obtain a response similar to:
```json
{

View File

@ -6,7 +6,7 @@
- [How to convert models from ONNX to TensorRT](#how-to-convert-models-from-onnx-to-tensorrt)
- [Prerequisite](#prerequisite)
- [Usage](#usage)
- [List of supported models convertable to TensorRT](#list-of-supported-models-convertable-to-tensorrt)
- [List of supported models convertible to TensorRT](#list-of-supported-models-convertible-to-tensorrt)
- [Reminders](#reminders)
- [FAQs](#faqs)
@ -55,9 +55,9 @@ python tools/deployment/onnx2tensorrt.py \
--verify \
```
## List of supported models convertable to TensorRT
## List of supported models convertible to TensorRT
The table below lists the models that are guaranteed to be convertable to TensorRT.
The table below lists the models that are guaranteed to be convertible to TensorRT.
| Model | Config | Status |
| :----------: | :--------------------------------------------------------------------------: | :----: |

View File

@ -381,7 +381,7 @@
"source": [
"### Feature extraction\n",
"\n",
"Feature extraction is another inference task. We can use pretrained model to extract sematic feature for downstream tasks. \n",
"Feature extraction is another inference task. We can use pretrained model to extract semantic feature for downstream tasks. \n",
"MMClassifcation also provides such facilities. \n",
"\n",
"Assuming we have already built model with pretrained weights, there're more steps to do:\n",
@ -461,7 +461,7 @@
"\n",
"Finetuning is the process in which parameters of a model would be adjusted very precisely in order to fit with certain dataset. Compared with training, it can can save lots of time and reduce overfitting when the new dataset is small. \n",
"\n",
"To finetune on a customized dataset, the following steps are neccessary. \n",
"To finetune on a customized dataset, the following steps are necessary. \n",
"\n",
"1. Prepare a new dataset. \n",
"2. Support it in MMCls.\n",
@ -483,7 +483,7 @@
"\n",
"Before we support a new dataset, we need download existing dataset first.\n",
"\n",
"We use [Cats and Dogs dataset](https://www.dropbox.com/s/wml49yrtdo53mie/cats_dogs_dataset_reorg.zip?dl=0) as an example. For simplicity, we have reorganized the directory structure for further usage. Origianl dataset can be found [here](https://www.kaggle.com/tongpython/cat-and-dog). The dataset consists of 8k images for training and 2k images for testing. There are 2 classes in total, i.e. cat and dog."
"We use [Cats and Dogs dataset](https://www.dropbox.com/s/wml49yrtdo53mie/cats_dogs_dataset_reorg.zip?dl=0) as an example. For simplicity, we have reorganized the directory structure for further usage. Original dataset can be found [here](https://www.kaggle.com/tongpython/cat-and-dog). The dataset consists of 8k images for training and 2k images for testing. There are 2 classes in total, i.e. cat and dog."
]
},
{
@ -603,7 +603,7 @@
"source": [
"### Support a new dataset\n",
"\n",
"Datasets in MMClassification require image and ground-truth labels to be placed in folders with the same perfix. To support a new dataset, there're two ways to generate a customized dataset. \n",
"Datasets in MMClassification require image and ground-truth labels to be placed in folders with the same prefix. To support a new dataset, there're two ways to generate a customized dataset. \n",
"\n",
"The simplest way is to convert the dataset to existing dataset formats (ImageNet). The other way is to add new Dataset class. More details can be found [here](https://github.com/open-mmlab/mmclassification/blob/master/docs/tutorials/new_dataset.md).\n",
"\n",
@ -890,7 +890,7 @@
"source": [
"Then, we need to implement `load_annotations` function in the new dataset class `CatsDogsDataset`.\n",
"\n",
"Typically, this function returns a list, where each sample is a dict, containing necessary data informations, e.g., `img_path` and `gt_label`. These will be used by `mmcv.runner` during training to load samples. "
"Typically, this function returns a list, where each sample is a dict, containing necessary data information, e.g., `img_path` and `gt_label`. These will be used by `mmcv.runner` during training to load samples. "
]
},
{
@ -909,7 +909,7 @@
"from mmcls.datasets import DATASETS, BaseDataset\n",
"\n",
"\n",
"# Regist model so that we can access the class through str in configs\n",
"# Register model so that we can access the class through str in configs\n",
"@DATASETS.register_module()\n",
"class CatsDogsDataset(BaseDataset):\n",
"\n",
@ -1279,7 +1279,7 @@
"# Specify the training annotations\n",
"cfg.data.train.ann_file = 'data/cats_dogs_dataset/train.txt'\n",
"\n",
"# The followings are the same as above\n",
"# The following is the same as above\n",
"cfg.data.samples_per_gpu = 32\n",
"cfg.data.workers_per_gpu=2\n",
"\n",
@ -1764,7 +1764,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, for the run time configs, we can simple use the defualt one and change nothing. We can now gather all the configs into one file and save it into `configs/resnet/resnet50_cats_dogs.py`.\n",
"Finally, for the run time configs, we can simple use the default one and change nothing. We can now gather all the configs into one file and save it into `configs/resnet/resnet50_cats_dogs.py`.\n",
"```python\n",
"_base_ = [\n",
" '../_base_/models/resnet50_cats_dogs.py', '../_base_/datasets/cats_dogs_dataset.py',\n",

View File

@ -39,7 +39,7 @@ Note: The value of ground-truth labels should fall in range `[0, num_classes - 1
You can write a new Dataset class inherited from `BaseDataset`, and overwrite `load_annotations(self)`,
like [CIFAR10](https://github.com/open-mmlab/mmclassification/blob/master/mmcls/datasets/cifar.py) and [ImageNet](https://github.com/open-mmlab/mmclassification/blob/master/mmcls/datasets/imagenet.py).
Typically, this function returns a list, where each sample is a dict, containing necessary data informations, e.g., `img` and `gt_label`.
Typically, this function returns a list, where each sample is a dict, containing necessary data information, e.g., `img` and `gt_label`.
Assume we are going to implement a `Filelist` dataset, which takes filelists for both training and testing. The format of annotation list is as follows:

View File

@ -215,7 +215,7 @@ model = dict(
To add a new loss function, we mainly implement the `forward` function in the loss module.
In addition, it is helpful to leverage the decorator `weighted_loss` to weight the loss for each element.
Assuming that we want to mimic a probablistic distribution generated from another classification model, we implement a L1Loss to fulfil the purpose as below.
Assuming that we want to mimic a probabilistic distribution generated from another classification model, we implement a L1Loss to fulfil the purpose as below.
1. Create a new file in `mmcls/models/losses/l1_loss.py`.

View File

@ -202,7 +202,7 @@ class ImshowInfosContextManager(BaseFigureContextManager):
show=True,
wait_time=0,
out_file=None):
"""Show image with extra infomation.
"""Show image with extra information.
Args:
img (str | ndarray): The image to be displayed.
@ -293,7 +293,7 @@ def imshow_infos(img,
fig_size=(15, 10),
wait_time=0,
out_file=None):
"""Show image with extra infomation.
"""Show image with extra information.
Args:
img (str | ndarray): The image to be displayed.

View File

@ -4,8 +4,8 @@ from .auto_augment import (AutoAugment, AutoContrast, Brightness,
Posterize, RandAugment, Rotate, Sharpness, Shear,
Solarize, SolarizeAdd, Translate)
from .compose import Compose
from .formating import (Collect, ImageToTensor, ToNumpy, ToPIL, ToTensor,
Transpose, to_tensor)
from .formatting import (Collect, ImageToTensor, ToNumpy, ToPIL, ToTensor,
Transpose, to_tensor)
from .loading import LoadImageFromFile
from .transforms import (CenterCrop, ColorJitter, Lighting, RandomCrop,
RandomErasing, RandomFlip, RandomGrayscale,

View File

@ -1,180 +1,9 @@
# Copyright (c) OpenMMLab. All rights reserved.
from collections.abc import Sequence
# flake8: noqa
import warnings
import mmcv
import numpy as np
import torch
from mmcv.parallel import DataContainer as DC
from PIL import Image
from .formatting import *
from ..builder import PIPELINES
def to_tensor(data):
"""Convert objects of various python types to :obj:`torch.Tensor`.
Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`,
:class:`Sequence`, :class:`int` and :class:`float`.
"""
if isinstance(data, torch.Tensor):
return data
elif isinstance(data, np.ndarray):
return torch.from_numpy(data)
elif isinstance(data, Sequence) and not mmcv.is_str(data):
return torch.tensor(data)
elif isinstance(data, int):
return torch.LongTensor([data])
elif isinstance(data, float):
return torch.FloatTensor([data])
else:
raise TypeError(
f'Type {type(data)} cannot be converted to tensor.'
'Supported types are: `numpy.ndarray`, `torch.Tensor`, '
'`Sequence`, `int` and `float`')
@PIPELINES.register_module()
class ToTensor(object):
def __init__(self, keys):
self.keys = keys
def __call__(self, results):
for key in self.keys:
results[key] = to_tensor(results[key])
return results
def __repr__(self):
return self.__class__.__name__ + f'(keys={self.keys})'
@PIPELINES.register_module()
class ImageToTensor(object):
def __init__(self, keys):
self.keys = keys
def __call__(self, results):
for key in self.keys:
img = results[key]
if len(img.shape) < 3:
img = np.expand_dims(img, -1)
results[key] = to_tensor(img.transpose(2, 0, 1))
return results
def __repr__(self):
return self.__class__.__name__ + f'(keys={self.keys})'
@PIPELINES.register_module()
class Transpose(object):
def __init__(self, keys, order):
self.keys = keys
self.order = order
def __call__(self, results):
for key in self.keys:
results[key] = results[key].transpose(self.order)
return results
def __repr__(self):
return self.__class__.__name__ + \
f'(keys={self.keys}, order={self.order})'
@PIPELINES.register_module()
class ToPIL(object):
def __init__(self):
pass
def __call__(self, results):
results['img'] = Image.fromarray(results['img'])
return results
@PIPELINES.register_module()
class ToNumpy(object):
def __init__(self):
pass
def __call__(self, results):
results['img'] = np.array(results['img'], dtype=np.float32)
return results
@PIPELINES.register_module()
class Collect(object):
"""Collect data from the loader relevant to the specific task.
This is usually the last stage of the data loader pipeline. Typically keys
is set to some subset of "img" and "gt_label".
Args:
keys (Sequence[str]): Keys of results to be collected in ``data``.
meta_keys (Sequence[str], optional): Meta keys to be converted to
``mmcv.DataContainer`` and collected in ``data[img_metas]``.
Default: ('filename', 'ori_shape', 'img_shape', 'flip',
'flip_direction', 'img_norm_cfg')
Returns:
dict: The result dict contains the following keys
- keys in ``self.keys``
- ``img_metas`` if avaliable
"""
def __init__(self,
keys,
meta_keys=('filename', 'ori_filename', 'ori_shape',
'img_shape', 'flip', 'flip_direction',
'img_norm_cfg')):
self.keys = keys
self.meta_keys = meta_keys
def __call__(self, results):
data = {}
img_meta = {}
for key in self.meta_keys:
if key in results:
img_meta[key] = results[key]
data['img_metas'] = DC(img_meta, cpu_only=True)
for key in self.keys:
data[key] = results[key]
return data
def __repr__(self):
return self.__class__.__name__ + \
f'(keys={self.keys}, meta_keys={self.meta_keys})'
@PIPELINES.register_module()
class WrapFieldsToLists(object):
"""Wrap fields of the data dictionary into lists for evaluation.
This class can be used as a last step of a test or validation
pipeline for single image evaluation or inference.
Example:
>>> test_pipeline = [
>>> dict(type='LoadImageFromFile'),
>>> dict(type='Normalize',
mean=[123.675, 116.28, 103.53],
std=[58.395, 57.12, 57.375],
to_rgb=True),
>>> dict(type='ImageToTensor', keys=['img']),
>>> dict(type='Collect', keys=['img']),
>>> dict(type='WrapIntoLists')
>>> ]
"""
def __call__(self, results):
# Wrap dict fields into lists
for key, val in results.items():
results[key] = [val]
return results
def __repr__(self):
return f'{self.__class__.__name__}()'
warnings.warn('DeprecationWarning: mmcls.datasets.pipelines.formating will be '
'deprecated in 2021, please replace it with '
'mmcls.datasets.pipelines.formatting.')

View File

@ -0,0 +1,180 @@
# Copyright (c) OpenMMLab. All rights reserved.
from collections.abc import Sequence
import mmcv
import numpy as np
import torch
from mmcv.parallel import DataContainer as DC
from PIL import Image
from ..builder import PIPELINES
def to_tensor(data):
"""Convert objects of various python types to :obj:`torch.Tensor`.
Supported types are: :class:`numpy.ndarray`, :class:`torch.Tensor`,
:class:`Sequence`, :class:`int` and :class:`float`.
"""
if isinstance(data, torch.Tensor):
return data
elif isinstance(data, np.ndarray):
return torch.from_numpy(data)
elif isinstance(data, Sequence) and not mmcv.is_str(data):
return torch.tensor(data)
elif isinstance(data, int):
return torch.LongTensor([data])
elif isinstance(data, float):
return torch.FloatTensor([data])
else:
raise TypeError(
f'Type {type(data)} cannot be converted to tensor.'
'Supported types are: `numpy.ndarray`, `torch.Tensor`, '
'`Sequence`, `int` and `float`')
@PIPELINES.register_module()
class ToTensor(object):
def __init__(self, keys):
self.keys = keys
def __call__(self, results):
for key in self.keys:
results[key] = to_tensor(results[key])
return results
def __repr__(self):
return self.__class__.__name__ + f'(keys={self.keys})'
@PIPELINES.register_module()
class ImageToTensor(object):
def __init__(self, keys):
self.keys = keys
def __call__(self, results):
for key in self.keys:
img = results[key]
if len(img.shape) < 3:
img = np.expand_dims(img, -1)
results[key] = to_tensor(img.transpose(2, 0, 1))
return results
def __repr__(self):
return self.__class__.__name__ + f'(keys={self.keys})'
@PIPELINES.register_module()
class Transpose(object):
def __init__(self, keys, order):
self.keys = keys
self.order = order
def __call__(self, results):
for key in self.keys:
results[key] = results[key].transpose(self.order)
return results
def __repr__(self):
return self.__class__.__name__ + \
f'(keys={self.keys}, order={self.order})'
@PIPELINES.register_module()
class ToPIL(object):
def __init__(self):
pass
def __call__(self, results):
results['img'] = Image.fromarray(results['img'])
return results
@PIPELINES.register_module()
class ToNumpy(object):
def __init__(self):
pass
def __call__(self, results):
results['img'] = np.array(results['img'], dtype=np.float32)
return results
@PIPELINES.register_module()
class Collect(object):
"""Collect data from the loader relevant to the specific task.
This is usually the last stage of the data loader pipeline. Typically keys
is set to some subset of "img" and "gt_label".
Args:
keys (Sequence[str]): Keys of results to be collected in ``data``.
meta_keys (Sequence[str], optional): Meta keys to be converted to
``mmcv.DataContainer`` and collected in ``data[img_metas]``.
Default: ('filename', 'ori_shape', 'img_shape', 'flip',
'flip_direction', 'img_norm_cfg')
Returns:
dict: The result dict contains the following keys
- keys in ``self.keys``
- ``img_metas`` if available
"""
def __init__(self,
keys,
meta_keys=('filename', 'ori_filename', 'ori_shape',
'img_shape', 'flip', 'flip_direction',
'img_norm_cfg')):
self.keys = keys
self.meta_keys = meta_keys
def __call__(self, results):
data = {}
img_meta = {}
for key in self.meta_keys:
if key in results:
img_meta[key] = results[key]
data['img_metas'] = DC(img_meta, cpu_only=True)
for key in self.keys:
data[key] = results[key]
return data
def __repr__(self):
return self.__class__.__name__ + \
f'(keys={self.keys}, meta_keys={self.meta_keys})'
@PIPELINES.register_module()
class WrapFieldsToLists(object):
"""Wrap fields of the data dictionary into lists for evaluation.
This class can be used as a last step of a test or validation
pipeline for single image evaluation or inference.
Example:
>>> test_pipeline = [
>>> dict(type='LoadImageFromFile'),
>>> dict(type='Normalize',
mean=[123.675, 116.28, 103.53],
std=[58.395, 57.12, 57.375],
to_rgb=True),
>>> dict(type='ImageToTensor', keys=['img']),
>>> dict(type='Collect', keys=['img']),
>>> dict(type='WrapIntoLists')
>>> ]
"""
def __call__(self, results):
# Wrap dict fields into lists
for key, val in results.items():
results[key] = [val]
return results
def __repr__(self):
return f'{self.__class__.__name__}()'

View File

@ -153,7 +153,7 @@ class RandomResizedCrop(object):
to the original image. Defaults to (0.08, 1.0).
ratio (tuple): Range of the random aspect ratio of the cropped image
compared to the original image. Defaults to (3. / 4., 4. / 3.).
max_attempts (int): Maxinum number of attempts before falling back to
max_attempts (int): Maximum number of attempts before falling back to
Central Crop. Defaults to 10.
efficientnet_style (bool): Whether to use efficientnet style Random
ResizedCrop. Defaults to False.
@ -219,7 +219,7 @@ class RandomResizedCrop(object):
compared to the original image size.
ratio (tuple): Range of the random aspect ratio of the cropped
image compared to the original image area.
max_attempts (int): Maxinum number of attempts before falling back
max_attempts (int): Maximum number of attempts before falling back
to central crop. Defaults to 10.
Returns:
@ -281,7 +281,7 @@ class RandomResizedCrop(object):
compared to the original image size.
ratio (tuple): Range of the random aspect ratio of the cropped
image compared to the original image area.
max_attempts (int): Maxinum number of attempts before falling back
max_attempts (int): Maximum number of attempts before falling back
to central crop. Defaults to 10.
min_covered (Number): Minimum ratio of the cropped area to the
original area. Only valid if efficientnet_style is true.
@ -313,7 +313,7 @@ class RandomResizedCrop(object):
max_target_height = min(max_target_height, height)
min_target_height = min(max_target_height, min_target_height)
# slightly differs from tf inplementation
# slightly differs from tf implementation
target_height = int(
round(random.uniform(min_target_height, max_target_height)))
target_width = int(round(target_height * aspect_ratio))
@ -895,7 +895,7 @@ class Lighting(object):
eigvec (list[list]): the eigenvector of the convariance matrix of pixel
values, respectively.
alphastd (float): The standard deviation for distribution of alpha.
Dafaults to 0.1
Defaults to 0.1
to_rgb (bool): Whether to convert img to rgb.
"""

View File

@ -12,7 +12,7 @@ class MobileNetV3(BaseBackbone):
"""MobileNetV3 backbone.
Args:
arch (str): Architechture of mobilnetv3, from {small, large}.
arch (str): Architecture of mobilnetv3, from {small, large}.
Default: small.
conv_cfg (dict, optional): Config dict for convolution layer.
Default: None, which means using conv2d.
@ -21,13 +21,13 @@ class MobileNetV3(BaseBackbone):
out_indices (None or Sequence[int]): Output from which stages.
Default: None, which means output tensors from final stage.
frozen_stages (int): Stages to be frozen (all param fixed).
Defualt: -1, which means not freezing any parameters.
Default: -1, which means not freezing any parameters.
norm_eval (bool): Whether to set norm layers to eval mode, namely,
freeze running stats (mean and var). Note: Effect on Batch Norm
and its variants only. Default: False.
with_cp (bool): Use checkpoint or not. Using checkpoint will save
some memory while slowing down the training speed.
Defualt: False.
Default: False.
"""
# Parameters to build each block:
# [kernel size, mid channels, out channels, with_se, act type, stride]

View File

@ -21,7 +21,7 @@ class RegNet(ResNet):
- wm (float): quantization parameter to quantize the width
- depth (int): depth of the backbone
- group_w (int): width of group
- bot_mul (float): bottleneck ratio, i.e. expansion of bottlneck.
- bot_mul (float): bottleneck ratio, i.e. expansion of bottleneck.
strides (Sequence[int]): Strides of the first block of each stage.
base_channels (int): Base channels after stem layer.
in_channels (int): Number of input image channels. Default: 3.

View File

@ -183,7 +183,7 @@ class RepVGGBlock(BaseModule):
self.deploy = True
def reparameterize(self):
"""Fuse all the parameters of all branchs.
"""Fuse all the parameters of all branches.
Returns:
tuple[torch.Tensor, torch.Tensor]: Parameters after fusion of all

View File

@ -28,7 +28,7 @@ class TransformerBlock(BaseModule):
drop_path_rate (float): stochastic depth rate. Default 0.
num_fcs (int): The number of fully-connected layers for FFNs. Default 2
qkv_bias (bool): Enable bias for qkv if True. Default False
act_cfg (dict): The activation config for FFNs. Defalut GELU
act_cfg (dict): The activation config for FFNs. Defaults to GELU.
norm_cfg (dict): Config dict for normalization layer. Default
layer normalization
batch_first (bool): Key, Query and Value are shape of
@ -222,7 +222,7 @@ class TNT(BaseBackbone):
attn_drop_rate (float): The drop out rate for attention layer.
Default 0.
drop_path_rate (float): stochastic depth rate. Default 0.
act_cfg (dict): The activation config for FFNs. Defalut GELU
act_cfg (dict): The activation config for FFNs. Defaults to GELU.
norm_cfg (dict): Config dict for normalization layer. Default
layer normalization
first_stride (int): The stride of the conv2d layer. We use a conv2d

View File

@ -46,13 +46,11 @@ class VGG(BaseBackbone):
num_stages (int): VGG stages, normally 5.
dilations (Sequence[int]): Dilation of each stage.
out_indices (Sequence[int], optional): Output from which stages.
If only one stage is specified, a single tensor (feature map) is
returned, otherwise multiple stages are specified, a tuple of
tensors will be returned. When it is None, the default behavior
depends on whether num_classes is specified. If num_classes <= 0,
the default value is (4, ), outputing the last feature map before
classifier. If num_classes > 0, the default value is (5, ),
outputing the classification score. Default: None.
When it is None, the default behavior depends on whether
num_classes is specified. If num_classes <= 0, the default value is
(4, ), output the last feature map before classifier. If
num_classes > 0, the default value is (5, ), output the
classification score. Default: None.
frozen_stages (int): Stages to be frozen (all param fixed). -1 means
not freezing any parameters.
norm_eval (bool): Whether to set norm layers to eval mode, namely,

View File

@ -17,7 +17,7 @@ class FFN(nn.Module):
`MultiheadAttention`.
feedforward_channels (int): The hidden dimension of FFNs.
num_fcs (int, optional): The number of fully-connected layers in
FFNs. Defaluts to 2.
FFNs. Defaults to 2.
act_cfg (dict, optional): The activation config for FFNs.
dropout (float, optional): Probability of an element to be
zeroed. Default 0.0.
@ -182,7 +182,7 @@ class TransformerEncoderLayer(nn.Module):
Default 0.0.
proj_drop (float): Probability of an element to be zeroed
after the feed forward layer. Default 0.0.
act_cfg (dict): The activation config for FFNs. Defalut GELU.
act_cfg (dict): The activation config for FFNs. Defaults to GELU.
norm_cfg (dict): Config dict for normalization layer. Default
layer normalization.
num_fcs (int): The number of fully-connected layers for FFNs.
@ -398,7 +398,7 @@ class VisionTransformer(BaseBackbone):
norm_cfg
norm_cfg (dict): Config dict for normalization layer. Default
layer normalization.
act_cfg (dict): The activation config for FFNs. Defalut GELU.
act_cfg (dict): The activation config for FFNs. Defaults to GELU.
num_fcs (int): The number of fully-connected layers for FFNs.
Default 2.
"""

View File

@ -195,7 +195,7 @@ class BaseClassifier(BaseModule, metaclass=ABCMeta):
Default: None.
Returns:
img (ndarray): Image with overlayed results.
img (ndarray): Image with overlaid results.
"""
img = mmcv.imread(img)
img = img.copy()

View File

@ -20,7 +20,7 @@ class VisionTransformerClsHead(ClsHead):
hidden_dim (int): Number of the dimensions for hidden layer. Only
available during pre-training. Default None.
act_cfg (dict): The activation config. Only available during
pre-training. Defalut Tanh.
pre-training. Defaults to Tanh.
"""
def __init__(self,

View File

@ -24,7 +24,7 @@ def asymmetric_loss(pred,
target (torch.Tensor): The ground truth label of the prediction with
shape (N, \*).
weight (torch.Tensor, optional): Sample-wise loss weight with shape
(N, ). Dafaults to None.
(N, ). Defaults to None.
gamma_pos (float): positive focusing parameter. Defaults to 0.0.
gamma_neg (float): Negative focusing parameter. We usually set
gamma_neg > gamma_pos. Defaults to 4.0.

View File

@ -20,7 +20,7 @@ def sigmoid_focal_loss(pred,
target (torch.Tensor): The ground truth label of the prediction with
shape (N, \*).
weight (torch.Tensor, optional): Sample-wise loss weight with shape
(N, ). Dafaults to None.
(N, ). Defaults to None.
gamma (float): The gamma for calculating the modulating factor.
Defaults to 2.0.
alpha (float): A balanced form for Focal Loss. Defaults to 0.25.
@ -90,7 +90,7 @@ class FocalLoss(nn.Module):
target (torch.Tensor): The ground truth label of the prediction
with shape (N, \*).
weight (torch.Tensor, optional): Sample-wise loss weight with shape
(N, \*). Dafaults to None.
(N, \*). Defaults to None.
avg_factor (int, optional): Average factor that is used to average
the loss. Defaults to None.
reduction_override (str, optional): The method used to reduce the

View File

@ -11,7 +11,7 @@ from .utils import convert_to_one_hot
@LOSSES.register_module()
class LabelSmoothLoss(nn.Module):
r"""Intializer for the label smoothed cross entropy loss.
r"""Initializer for the label smoothed cross entropy loss.
Refers to `Rethinking the Inception Architecture for Computer Vision
<https://arxiv.org/abs/1512.00567>`_
@ -133,7 +133,7 @@ class LabelSmoothLoss(nn.Module):
label (torch.Tensor): The ground truth label of the prediction
with shape (N, \*).
weight (torch.Tensor, optional): Sample-wise loss weight with shape
(N, \*). Dafaults to None.
(N, \*). Defaults to None.
avg_factor (int, optional): Average factor that is used to average
the loss. Defaults to None.
reduction_override (str, optional): The method used to reduce the

View File

@ -32,7 +32,7 @@ def weight_reduce_loss(loss, weight=None, reduction='mean', avg_factor=None):
loss (Tensor): Element-wise loss.
weight (Tensor): Element-wise weights.
reduction (str): Same as built-in losses of PyTorch.
avg_factor (float): Avarage factor when computing the mean of losses.
avg_factor (float): Average factor when computing the mean of losses.
Returns:
Tensor: Processed loss values.

View File

@ -14,10 +14,10 @@ class InvertedResidual(BaseModule):
in_channels (int): The input channels of this Module.
out_channels (int): The output channels of this Module.
mid_channels (int): The input channels of the depthwise convolution.
kernel_size (int): The kernal size of the depthwise convolution.
kernel_size (int): The kernel size of the depthwise convolution.
Default: 3.
stride (int): The stride of the depthwise convolution. Default: 1.
se_cfg (dict): Config dict for se layer. Defaul: None, which means no
se_cfg (dict): Config dict for se layer. Default: None, which means no
se layer.
conv_cfg (dict): Config dict for convolution layer. Default: None,
which means using conv2d.

View File

@ -17,3 +17,8 @@ known_first_party = mmcls
known_third_party = PIL,m2r,matplotlib,mmcv,mmdet,numpy,onnxruntime,packaging,pytest,pytorch_sphinx_theme,recommonmark,seaborn,sphinx,torch,torchvision,ts
no_lines_before = STDLIB,LOCALFOLDER
default_section = THIRDPARTY
[codespell]
skip = *.ipynb
quiet-level = 3
ignore-words-list = patten,confectionary,nd,ty,formating

View File

@ -218,7 +218,7 @@ def test_dataset_evaluation():
with pytest.raises(ValueError):
eval_results = dataset.evaluate(fake_results, metric='map')
# test multi-label evalutation
# test multi-label evaluation
dataset = MultiLabelDataset(data_prefix='', pipeline=[], test_mode=True)
dataset.data_infos = [
dict(gt_label=[1, 1, 0, -1]),

View File

@ -358,7 +358,7 @@ def test_rand_augment():
axis=-1)
np.testing.assert_array_equal(results['img'], img_augmented)
# test case where magnitude_std is negtive
# test case where magnitude_std is negative
random.seed(3)
np.random.seed(0)
results = construct_toy_data()
@ -602,7 +602,7 @@ def test_rotate():
transform = dict(type='Rotate', angle=90., center=0)
build_from_cfg(transform, PIPELINES)
# test assertion for invalid lenth of center
# test assertion for invalid length of center
with pytest.raises(AssertionError):
transform = dict(type='Rotate', angle=90., center=(0, ))
build_from_cfg(transform, PIPELINES)

View File

@ -929,7 +929,7 @@ def test_randomflip():
results = flip_module(results)
assert np.equal(results['img'], results['img2']).all()
# compare hotizontal flip with torchvision
# compare horizontal flip with torchvision
transform = dict(type='RandomFlip', flip_prob=1, direction='horizontal')
flip_module = build_from_cfg(transform, PIPELINES)
results = reset_results(results, original_img)

View File

@ -276,7 +276,7 @@ def test_repvgg_backbone():
def test_repvgg_load():
# Test ouput before and load from deploy checkpoint
# Test output before and load from deploy checkpoint
model = RepVGG('A1', out_indices=(0, 1, 2, 3))
inputs = torch.randn((1, 3, 224, 224))
ckpt_path = os.path.join(tempfile.gettempdir(), 'ckpt.pth')

View File

@ -28,14 +28,14 @@ def onnx2tensorrt(onnx_file,
max_batch_size (int): Max batch size of the model.
verify (bool, optional): Whether to verify the converted model.
Defaults to False.
workspace_size (int, optional): Maximium workspace of GPU.
workspace_size (int, optional): Maximum workspace of GPU.
Defaults to 1.
"""
import onnx
from mmcv.tensorrt import TRTWraper, onnx2trt, save_trt_engine
onnx_model = onnx.load(onnx_file)
# create trt engine and wraper
# create trt engine and wrapper
assert max_batch_size >= 1
max_shape = [max_batch_size] + list(input_shape[1:])
opt_shape_dict = {'input': [input_shape, input_shape, max_shape]}

View File

@ -221,7 +221,7 @@ if __name__ == '__main__':
if args.checkpoint:
load_checkpoint(classifier, args.checkpoint, map_location='cpu')
# conver model to onnx file
# convert model to onnx file
pytorch2onnx(
classifier,
input_shape,

View File

@ -131,7 +131,7 @@ if __name__ == '__main__':
if args.checkpoint:
load_checkpoint(classifier, args.checkpoint, map_location='cpu')
# conver model to TorchScript file
# convert model to TorchScript file
pytorch2torchscript(
classifier,
input_shape,