Skip to content

Commit

Permalink
Merge d21e071 into 7e4502b
Browse files Browse the repository at this point in the history
  • Loading branch information
mzr1996 committed Feb 6, 2023
2 parents 7e4502b + d21e071 commit 16d4a6d
Show file tree
Hide file tree
Showing 23 changed files with 1,084 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
hooks:
- id: flake8
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.11.5
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-yapf
Expand Down
28 changes: 21 additions & 7 deletions demo/image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,37 @@
from mmengine.fileio import dump
from rich import print_json

from mmcls.apis import inference_model, init_model
from mmcls.apis import ImageClassificationInferencer


def main():
parser = ArgumentParser()
parser.add_argument('img', help='Image file')
parser.add_argument('config', help='Config file')
parser.add_argument('checkpoint', help='Checkpoint file')
parser.add_argument('model', help='Model name or config file path')
parser.add_argument('--checkpoint', help='Checkpoint file path.')
parser.add_argument(
'--device', default='cuda:0', help='Device used for inference')
'--show',
action='store_true',
help='Whether to show the prediction result in a window.')
parser.add_argument(
'--show-dir',
type=str,
help='The directory to save the visualization image.')
parser.add_argument('--device', help='Device used for inference')
args = parser.parse_args()

# build the model from a config file and a checkpoint file
model = init_model(args.config, args.checkpoint, device=args.device)
# test a single image
result = inference_model(model, args.img)
try:
inferencer = ImageClassificationInferencer(args.model, args.checkpoint)
except ValueError:
raise ValueError(
f'Unavailable model "{args.model}", you can specify find a model '
'name or a config file or find a model name from '
'https://mmclassification.readthedocs.io/en/1.x/modelzoo_statistics.html#all-checkpoints' # noqa: E501
)
result = inferencer(args.img, show=args.show, show_dir=args.show_dir)[0]
# show the results
result.pop('pred_scores') # pred_scores is too verbose for a demo.
print_json(dump(result, file_format='json', indent=4))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
.. autoclass:: {{ name }}
:members:


..
autogenerated from source/_templates/classtemplate.rst
autogenerated from _templates/autosummary/class.rst
note it does not have :inherited-members:
14 changes: 14 additions & 0 deletions docs/en/_templates/callable.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. role:: hidden
:class: hidden-section
.. currentmodule:: {{ module }}


{{ name | underline}}

.. autoclass:: {{ name }}
:members:
:special-members: __call__

..
autogenerated from _templates/callable.rst
note it does not have :inherited-members:
13 changes: 13 additions & 0 deletions docs/en/_templates/data_transform.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. role:: hidden
:class: hidden-section
.. currentmodule:: {{ module }}


{{ name | underline}}

.. autoclass:: {{ name }}
:members: transform

..
autogenerated from _templates/callable.rst
note it does not have :inherited-members:
24 changes: 18 additions & 6 deletions docs/en/api/apis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@ These are some high-level APIs for classification tasks.
Model
------------------

.. autofunction:: list_models

.. autofunction:: get_model

.. autofunction:: init_model
.. autosummary::
:toctree: generated
:nosignatures:

list_models
get_model
init_model

Inference
------------------

.. autofunction:: inference_model
.. autosummary::
:toctree: generated
:nosignatures:
:template: callable.rst

ImageClassificationInferencer

.. autosummary::
:toctree: generated
:nosignatures:

inference_model
11 changes: 5 additions & 6 deletions docs/en/api/data_process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Processing and Augmentation

.. autosummary::
:toctree: generated
:template: classtemplate.rst
:nosignatures:
:template: data_transform.rst

Albumentations
ColorJitter
Expand All @@ -75,8 +75,8 @@ augmentation transforms, such as ``AutoAugment`` and ``RandAugment``.

.. autosummary::
:toctree: generated
:template: classtemplate.rst
:nosignatures:
:template: data_transform.rst

AutoAugment
RandAugment
Expand Down Expand Up @@ -106,7 +106,7 @@ And you can also configure a group of policies manually by selecting from the be
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst
:template: data_transform.rst

AutoContrast
Brightness
Expand All @@ -129,8 +129,8 @@ Formatting

.. autosummary::
:toctree: generated
:template: classtemplate.rst
:nosignatures:
:template: data_transform.rst

Collect
PackClsInputs
Expand Down Expand Up @@ -213,7 +213,6 @@ Note that the ``model.data_preprocessor`` has higher priority than ``data_prepro
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

ClsDataPreprocessor

Expand Down Expand Up @@ -257,7 +256,7 @@ Here is a list of batch augmentations can be used in MMClassification.
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst
:template: callable.rst

Mixup
CutMix
Expand Down
2 changes: 0 additions & 2 deletions docs/en/api/engine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Hooks
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

ClassNumCheckHook
PreciseBNHook
Expand All @@ -43,6 +42,5 @@ Optimizers
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

Lamb
2 changes: 0 additions & 2 deletions docs/en/api/evaluation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Single Label Metric
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

Accuracy
SingleLabelMetric
Expand All @@ -29,7 +28,6 @@ Multi Label Metric
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

AveragePrecision
MultiLabelMetric
Expand Down
6 changes: 0 additions & 6 deletions docs/en/api/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Classifiers
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

BaseClassifier
ImageClassifier
Expand All @@ -55,7 +54,6 @@ Backbones
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

AlexNet
BEiT
Expand Down Expand Up @@ -123,7 +121,6 @@ Necks
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

GlobalAveragePooling
GeneralizedMeanPooling
Expand All @@ -137,7 +134,6 @@ Heads
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

ClsHead
LinearClsHead
Expand All @@ -159,7 +155,6 @@ Losses
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

CrossEntropyLoss
LabelSmoothLoss
Expand All @@ -182,7 +177,6 @@ Common Components
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst

InvertedResidual
SELayer
Expand Down
15 changes: 6 additions & 9 deletions docs/en/get_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,10 @@ pip install -U openmim && mim install "mmcls>=1.0.0rc0"

To verify whether MMClassification is installed correctly, we provide some sample codes to run an inference demo.

**Step 1.** We need to download config and checkpoint files.

```shell
mim download mmcls --config resnet50_8xb32_in1k --dest .
```

**Step 2.** Verify the inference demo.

Option (a). If you install mmcls from the source, just run the following command:

```shell
python demo/image_demo.py demo/demo.JPEG resnet50_8xb32_in1k.py resnet50_8xb32_in1k_20210831-ea4938fc.pth --device cpu
python demo/image_demo.py demo/demo.JPEG resnet18_8xb32_in1k --device cpu
```

You will see the output result dict including `pred_label`, `pred_score` and `pred_class` in your terminal.
Expand All @@ -101,6 +93,11 @@ inference_model(model, 'demo/demo.JPEG')

You will see a dict printed, including the predicted label, score and category name.

```{note}
The `resnet18_8xb32_in1k` is the model name, and you can use [`mmcls.list_models`](mmcls.apis.list_models) to
explore all models, or search them on the [Model Zoo Summary](./modelzoo_statistics.md)
```

## Customize Installation

### CUDA versions
Expand Down
44 changes: 22 additions & 22 deletions docs/en/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ test_dataloader = val_dataloader

Changes in **`pipeline`**:

- The original formatting transforms **`ToTensor`****`ImageToTensor`****`Collect`** are combined as [`PackClsInputs`](mmcls.datasets.transforms.PackClsInputs).
- The original formatting transforms **`ToTensor`**, **`ImageToTensor`** and **`Collect`** are combined as [`PackClsInputs`](mmcls.datasets.transforms.PackClsInputs).
- We don't recommend to do **`Normalize`** in the dataset pipeline. Please remove it from pipelines and set it in the `data_preprocessor` field.
- The argument `flip_prob` in [**`RandomFlip`**](mmcv.transforms.RandomFlip) is renamed to `flip`.
- The argument `size` in [**`RandomCrop`**](mmcls.datasets.transforms.RandomCrop) is renamed to `crop_size`.
Expand Down Expand Up @@ -182,7 +182,7 @@ Changes in **`evaluation`**:
The `interval` is moved to `train_cfg.val_interval`, see [the schedule settings](./user_guides/config.md#schedule-settings) and the `save_best`
is moved to `default_hooks.checkpoint.save_best`, see [the runtime settings](./user_guides/config.md#runtime-settings).
- The 'accuracy' metric is renamed to [`Accuracy`](mmcls.evaluation.Accuracy).
- The 'precision''recall''f1-score' and 'support' are combined as [`SingleLabelMetric`](mmcls.evaluation.SingleLabelMetric), and use `items` argument to specify to calculate which metric.
- The 'precision', 'recall', 'f1-score' and 'support' are combined as [`SingleLabelMetric`](mmcls.evaluation.SingleLabelMetric), and use `items` argument to specify to calculate which metric.
- The 'mAP' is renamed to [`AveragePrecision`](mmcls.evaluation.AveragePrecision).
- The 'CP', 'CR', 'CF1', 'OP', 'OR', 'OF1' are combined as [`MultiLabelMetric`](mmcls.evaluation.MultiLabelMetric), and use `items` and `average` arguments to specify to calculate which metric.

Expand Down Expand Up @@ -370,7 +370,7 @@ test_cfg = dict() # Use the default test loop.
</table>

In fact, in OpenMMLab 2.0, we introduced `Loop` to control the behaviors in training, validation and test. And
the functionalities of `Runner` are also changed. You can find more details in {external+mmengine:doc}`the MMEngine tutorials <tutorials/runner>`.
the functionalities of `Runner` are also changed. You can find more details in {external+mmengine:doc}`the MMEngine tutorials <design/runner>`.

### Runtime settings

Expand Down Expand Up @@ -489,16 +489,16 @@ New field **`default_scope`**: The start point to search module for all registri

The documentation can be found [here](mmcls.apis).

| Function | Changes |
| :------------------: | :---------------------------------------------- |
| `init_model` | No changes |
| `inference_model` | No changes |
| `train_model` | Removed, use `runner.train` to train. |
| `multi_gpu_test` | Removed, use `runner.test` to test. |
| `single_gpu_test` | Removed, use `runner.test` to test. |
| `show_result_pyplot` | Waiting for support. |
| `set_random_seed` | Removed, use `mmengine.runner.set_random_seed`. |
| `init_random_seed` | Removed, use `mmengine.dist.sync_random_seed`. |
| Function | Changes |
| :------------------: | :------------------------------------------------------------------------------------------------------------------------------------- |
| `init_model` | No changes |
| `inference_model` | No changes. But we recommend to use [`mmcls.ImageClassificationInferencer`](mmcls.apis.ImageClassificationInferencer) instead. |
| `train_model` | Removed, use `runner.train` to train. |
| `multi_gpu_test` | Removed, use `runner.test` to test. |
| `single_gpu_test` | Removed, use `runner.test` to test. |
| `show_result_pyplot` | Removed, use [`mmcls.ImageClassificationInferencer`](mmcls.apis.ImageClassificationInferencer) to inference model and show the result. |
| `set_random_seed` | Removed, use `mmengine.runner.set_random_seed`. |
| `init_random_seed` | Removed, use `mmengine.dist.sync_random_seed`. |

### `mmcls.core`

Expand Down Expand Up @@ -572,15 +572,15 @@ Changes in [heads](mmcls.models.heads):

### `mmcls.utils`

| Function | Changes |
| :--------------------------: | :------------------------------------------------------------ |
| `collect_env` | No changes |
| `get_root_logger` | Removed, use `mmengine.MMLogger.get_current_instance` |
| `load_json_log` | Waiting for support |
| `setup_multi_processes` | Removed, use `mmengine.utils.dl_utils.setup_multi_processes`. |
| `wrap_non_distributed_model` | Removed, we auto wrap the model in the runner. |
| `wrap_distributed_model` | Removed, we auto wrap the model in the runner. |
| `auto_select_device` | Removed, we auto select the device in the runner. |
| Function | Changes |
| :--------------------------: | :-------------------------------------------------------------------------------------------------------------- |
| `collect_env` | No changes |
| `get_root_logger` | Removed, use [`mmengine.logging.MMLogger.get_current_instance`](mmengine.logging.MMLogger.get_current_instance) |
| `load_json_log` | Waiting for support |
| `setup_multi_processes` | Removed, use [`mmengine.utils.dl_utils.set_multi_processing`](mmengine.utils.dl_utils.set_multi_processing). |
| `wrap_non_distributed_model` | Removed, we auto wrap the model in the runner. |
| `wrap_distributed_model` | Removed, we auto wrap the model in the runner. |
| `auto_select_device` | Removed, we auto select the device in the runner. |

### Other changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
.. autoclass:: {{ name }}
:members:


..
autogenerated from source/_templates/classtemplate.rst
autogenerated from _templates/autosummary/class.rst
note it does not have :inherited-members:
14 changes: 14 additions & 0 deletions docs/zh_CN/_templates/callable.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.. role:: hidden
:class: hidden-section
.. currentmodule:: {{ module }}


{{ name | underline}}

.. autoclass:: {{ name }}
:members:
:special-members: __call__

..
autogenerated from _templates/callable.rst
note it does not have :inherited-members:
Loading

0 comments on commit 16d4a6d

Please sign in to comment.