Shortcuts

Tutorial 6: Useful Tools

We provide lots of useful tools under tools/ directory.

The structure of this guide is as follows:

Get the FLOPs and params

We provide a script adapted from flops-counter.pytorch to compute the FLOPs and params of a given model.

python tools/analysis_tools/get_flops.py ${CONFIG_FILE} [--shape ${INPUT_SHAPE}]

For example,

python tools/analysis_tools/get_flops.py configs/resotorer/srresnet.py --shape 40 40

You will get the result like this.

==============================
Input shape: (3, 40, 40)
Flops: 4.07 GMac
Params: 1.52 M
==============================

Note: This tool is still experimental and we do not guarantee that the number is correct. You may well use the result for simple comparisons, but double check it before you adopt it in technical reports or papers.

(1) FLOPs are related to the input shape while parameters are not. The default input shape is (1, 3, 250, 250). (2) Some operators are not counted in FLOPs like GN and custom operators. You can add support for new operators by modifying mmcv/cnn/utils/flops_counter.py.

Publish a model

Before you upload a model to AWS, you may want to

  1. convert model weights to CPU tensors

  2. delete the optimizer states and

  3. compute the hash of the checkpoint file and append time and the hash id to the filename.

python tools/model_converters/publish_model.py ${INPUT_FILENAME} ${OUTPUT_FILENAME}

E.g.,

python tools/model_converters/publish_model.py work_dirs/stylegan2/latest.pth stylegan2_c2_8xb4_ffhq-1024x1024.pth

The final output filename will be stylegan2_c2_8xb4_ffhq-1024x1024_{time}-{hash id}.pth.

Read the Docs v: zyh/re-docs
Versions
master
latest
stable
zyh-re-docs
zyh-doc-notfound-extend
zyh-api-rendering
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.