├── 01_registry ├── model │ ├── __init__.py │ └── builder.py ├── converters │ ├── __init__.py │ ├── converter_func.py │ ├── converter_cls.py │ └── builder.py ├── 01_start.py ├── 02_start.ipynb ├── 01_start.ipynb └── 02_free_combination.ipynb ├── 02_config ├── runtime_cfg.py ├── predefined_var.py ├── refer_base_var.py ├── resnet50.py ├── config_sgd.py ├── optimizer_cfg.py ├── example.py ├── learn_read_config.py ├── resnet50_runtime.py ├── custom_imports.py ├── my_module.py ├── resnet50_lr0.01.py ├── resnet50_delete_key.py ├── cross_repo.py ├── demo_train.py └── 01_main.ipynb ├── README.md ├── .vscode └── launch.json ├── runner_demo.py ├── 03_runner └── 01.py ├── .gitignore ├── 15_minutes.py └── LICENSE /01_registry/model/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /02_config/runtime_cfg.py: -------------------------------------------------------------------------------- 1 | gpu_ids = [0, 1] 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mmengine-learn 2 | 3 | 致力于降低mmengine-learn的学习曲线陡峭程度。 -------------------------------------------------------------------------------- /02_config/predefined_var.py: -------------------------------------------------------------------------------- 1 | work_dir = './work_dir/{{fileBasenameNoExtension}}' 2 | -------------------------------------------------------------------------------- /02_config/refer_base_var.py: -------------------------------------------------------------------------------- 1 | _base_ = ['resnet50.py'] 2 | a = {{_base_.model}} 3 | -------------------------------------------------------------------------------- /02_config/resnet50.py: -------------------------------------------------------------------------------- 1 | _base_ = ['optimizer_cfg.py'] 2 | model = dict(type='ResNet', depth=50) 3 | -------------------------------------------------------------------------------- /02_config/config_sgd.py: -------------------------------------------------------------------------------- 1 | optimizer = dict(type='SGD', lr=0.1, momentum=0.9, weight_decay=0.0001) 2 | -------------------------------------------------------------------------------- /02_config/optimizer_cfg.py: -------------------------------------------------------------------------------- 1 | optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001) 2 | -------------------------------------------------------------------------------- /02_config/example.py: -------------------------------------------------------------------------------- 1 | model = dict(type='CustomModel', in_channels=[1, 2, 3]) 2 | optimizer = dict(type='SGD', lr=0.01) 3 | -------------------------------------------------------------------------------- /02_config/learn_read_config.py: -------------------------------------------------------------------------------- 1 | test_int = 1 2 | test_list = [1, 2, 3] 3 | test_dict = dict(key1='value1', key2=0.1) 4 | -------------------------------------------------------------------------------- /02_config/resnet50_runtime.py: -------------------------------------------------------------------------------- 1 | _base_ = ['optimizer_cfg.py', 'runtime_cfg.py'] 2 | model = dict(type='ResNet', depth=50) 3 | -------------------------------------------------------------------------------- /01_registry/model/builder.py: -------------------------------------------------------------------------------- 1 | # model/builder.py 2 | from mmengine import Registry 3 | # 创建转换器的注册器 4 | CONVERTERS = Registry('converter') 5 | -------------------------------------------------------------------------------- /02_config/custom_imports.py: -------------------------------------------------------------------------------- 1 | custom_imports = dict(imports=['my_module'], allow_failed_imports=False) 2 | optimizer = dict(type='CustomOptim') 3 | -------------------------------------------------------------------------------- /02_config/my_module.py: -------------------------------------------------------------------------------- 1 | from mmengine.registry import OPTIMIZERS 2 | 3 | 4 | @OPTIMIZERS.register_module() 5 | class CustomOptim: 6 | pass 7 | -------------------------------------------------------------------------------- /02_config/resnet50_lr0.01.py: -------------------------------------------------------------------------------- 1 | _base_ = ['optimizer_cfg.py', 'runtime_cfg.py'] 2 | model = dict(type='ResNet', depth=50) 3 | optimizer = dict(lr=0.01) 4 | -------------------------------------------------------------------------------- /02_config/resnet50_delete_key.py: -------------------------------------------------------------------------------- 1 | _base_ = ['optimizer_cfg.py', 'runtime_cfg.py'] 2 | model = dict(type='ResNet', depth=50) 3 | optimizer = dict(_delete_=True, type='SGD', lr=0.01) 4 | -------------------------------------------------------------------------------- /01_registry/converters/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from .builder import CONVERTERS 3 | from .converter_cls import Converter1 4 | from .converter_func import converter3 5 | 6 | __all__ = ['CONVERTERS', 'Converter1', 'converter3'] 7 | -------------------------------------------------------------------------------- /02_config/cross_repo.py: -------------------------------------------------------------------------------- 1 | _base_ = [ 2 | 'mmdet::_base_/schedules/schedule_1x.py', 3 | 'mmdet::_base_/datasets/coco_instance.py', 4 | 'mmdet::_base_/default_runtime.py', 5 | 'mmdet::_base_/models/faster-rcnn_r50_fpn.py', 6 | ] 7 | -------------------------------------------------------------------------------- /01_registry/converters/converter_func.py: -------------------------------------------------------------------------------- 1 | # converters/converter_func.py 2 | from .builder import CONVERTERS 3 | from .converter_cls import Converter1 4 | 5 | 6 | @CONVERTERS.register_module() 7 | def converter3(a, b): 8 | return Converter1(a, b) 9 | -------------------------------------------------------------------------------- /01_registry/converters/converter_cls.py: -------------------------------------------------------------------------------- 1 | # converters/converter_cls.py 2 | from .builder import CONVERTERS 3 | 4 | # 使用注册器管理模块 5 | 6 | @CONVERTERS.register_module() 7 | class Converter1(object): 8 | def __init__(self, a, b): 9 | self.a = a 10 | self.b = b 11 | 12 | 13 | @CONVERTERS.register_module() 14 | class Converter2(object): 15 | def __init__(self, a, b, c): 16 | self.a = a 17 | self.b = b 18 | self.c = c 19 | -------------------------------------------------------------------------------- /01_registry/01_start.py: -------------------------------------------------------------------------------- 1 | # import converters 2 | 3 | # from import CONVERTERS 4 | # import converters 5 | # custom_imports = dict( 6 | # imports=['.converters'], allow_failed_imports=False) 7 | 8 | from converters import CONVERTERS 9 | 10 | a_value = 'a_value' 11 | b_value = 'b_value' 12 | 13 | converter_cfg = dict(type='Converter1', a=123, b=1213) 14 | converter = CONVERTERS.build(converter_cfg) 15 | 16 | converter3_cfg = dict(type='converter3', a=a_value, b=b_value) 17 | # returns the calling result 18 | converter3 = CONVERTERS.build(converter3_cfg) 19 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Python: config File", 9 | "type": "python", 10 | "request": "launch", 11 | "program": "${file}", 12 | "console": "integratedTerminal", 13 | // "env": { 14 | // "PYTHONPATH": "./" 15 | // }, 16 | "justMyCode": false 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /01_registry/converters/builder.py: -------------------------------------------------------------------------------- 1 | # model/builder.py 2 | from mmengine import Registry 3 | # 创建转换器的注册器 4 | CONVERTERS = Registry('converter') 5 | 6 | 7 | 8 | # 创建一个构建方法 9 | def build_converter(cfg, registry, *args, **kwargs): 10 | cfg_ = cfg.copy() 11 | converter_type = cfg_.pop('type') 12 | if converter_type not in registry: 13 | raise KeyError(f'Unrecognized converter type {converter_type}') 14 | else: 15 | converter_cls = registry.get(converter_type) 16 | 17 | converter = converter_cls(*args, **kwargs, **cfg_) 18 | return converter 19 | 20 | 21 | # 创建一个用于转换器的注册器,并将 `build_converter` 传递给 `build_func` 参数 22 | CONVERTERS_CUSTOM = Registry('converter', build_func=build_converter) 23 | -------------------------------------------------------------------------------- /02_config/demo_train.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | from mmengine.config import Config, DictAction 4 | 5 | 6 | def parse_args(): 7 | parser = argparse.ArgumentParser(description='Train a model') 8 | parser.add_argument('config', help='train config file path') 9 | parser.add_argument( 10 | '--cfg-options', 11 | nargs='+', 12 | action=DictAction, 13 | help='override some settings in the used config, the key-value pair ' 14 | 'in xxx=yyy format will be merged into config file. If the value to ' 15 | 'be overwritten is a list, it should be like key="[a,b]" or key=a,b ' 16 | 'It also allows nested list/tuple values, e.g. key="[(a,b),(c,d)]" ' 17 | 'Note that the quotation marks are necessary and that no white space ' 18 | 'is allowed.') 19 | 20 | args = parser.parse_args() 21 | return args 22 | 23 | 24 | def main(): 25 | args = parse_args() 26 | cfg = Config.fromfile(args.config) 27 | if args.cfg_options is not None: 28 | cfg.merge_from_dict(args.cfg_options) 29 | print(cfg) 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /runner_demo.py: -------------------------------------------------------------------------------- 1 | # 准备训练任务所需要的模块 2 | import torch 3 | from torch import nn 4 | from torchvision import transforms 5 | from torchvision import datasets 6 | from torch.utils.data import DataLoader 7 | from mmengine.model import BaseModel 8 | from mmengine.optim.scheduler import MultiStepLR 9 | 10 | # 定义一个多层感知机网络 11 | class Network(BaseModel): 12 | def __init__(self): 13 | super().__init__() 14 | self.mlp = nn.Sequential(nn.Linear(28 * 28, 128), nn.ReLU(), nn.Linear(128, 128), nn.ReLU(), nn.Linear(128, 10)) 15 | self.loss = nn.CrossEntropyLoss() 16 | 17 | def forward(self, batch_inputs: torch.Tensor, data_samples = None, mode: str = 'tensor'): 18 | x = batch_inputs.flatten(1) 19 | x = self.mlp(x) 20 | if mode == 'loss': 21 | return {'loss': self.loss(x, data_samples)} 22 | elif mode == 'predict': 23 | return x.argmax(1) 24 | else: 25 | return x 26 | 27 | model = Network() 28 | 29 | # 构建优化器 30 | optimzier = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.9) 31 | # 构建参数调度器用于调整学习率 32 | lr_scheduler = MultiStepLR(milestones=[2], by_epoch=True) 33 | # 构建手写数字识别 (MNIST) 数据集 34 | train_dataset = datasets.MNIST(root="MNIST", download=True, train=True, transform=transforms.ToTensor()) 35 | # 构建数据加载器 36 | train_dataloader = DataLoader(dataset=train_dataset, batch_size=10, num_workers=2) -------------------------------------------------------------------------------- /01_registry/02_start.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 12, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "\n", 18 | "# \n", 19 | "from converters import CONVERTERS\n", 20 | "\n", 21 | "# 设置converter的config\n", 22 | "converter_cfg = dict(type='Converter1', a=123, b=1213)\n", 23 | "\n", 24 | "# 实例化Converter1\n", 25 | "converter = CONVERTERS.build(converter_cfg)\n", 26 | "print(converter)\n", 27 | "# converter3_cfg = dict(type='converter3', a=213, b=2323)\n", 28 | "# converter3 = CONVERTERS.build(converter3_cfg)" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 4, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "from converters import CONVERTERS\n", 38 | "converter_cfg = dict(type='Converter2', a=1, b=2, c=3)\n", 39 | "converter = CONVERTERS.build(converter_cfg)" 40 | ] 41 | } 42 | ], 43 | "metadata": { 44 | "kernelspec": { 45 | "display_name": "Python 3.9.12 ('mmdet-yolo')", 46 | "language": "python", 47 | "name": "python3" 48 | }, 49 | "language_info": { 50 | "codemirror_mode": { 51 | "name": "ipython", 52 | "version": 3 53 | }, 54 | "file_extension": ".py", 55 | "mimetype": "text/x-python", 56 | "name": "python", 57 | "nbconvert_exporter": "python", 58 | "pygments_lexer": "ipython3", 59 | "version": "3.9.12" 60 | }, 61 | "orig_nbformat": 4, 62 | "vscode": { 63 | "interpreter": { 64 | "hash": "b8e27fa7a4910f0db2656c6311d3024d4c4814786eee182f5bdf8dbffc78e0c0" 65 | } 66 | } 67 | }, 68 | "nbformat": 4, 69 | "nbformat_minor": 2 70 | } 71 | -------------------------------------------------------------------------------- /03_runner/01.py: -------------------------------------------------------------------------------- 1 | # 准备训练任务所需要的模块 2 | from mmengine.runner import Runner 3 | import torch 4 | from torch import nn 5 | from torchvision import transforms 6 | from torchvision import datasets 7 | from torch.utils.data import DataLoader 8 | from mmengine.model import BaseModel 9 | from mmengine.optim.scheduler import MultiStepLR 10 | 11 | # 定义一个多层感知机网络 12 | 13 | 14 | class Network(BaseModel): 15 | def __init__(self): 16 | super().__init__() 17 | self.mlp = nn.Sequential(nn.Linear( 18 | 28 * 28, 128), nn.ReLU(), nn.Linear(128, 128), nn.ReLU(), nn.Linear(128, 10)) 19 | self.loss = nn.CrossEntropyLoss() 20 | 21 | def forward(self, batch_inputs: torch.Tensor, data_samples=None, mode: str = 'tensor'): 22 | x = batch_inputs.flatten(1) 23 | x = self.mlp(x) 24 | if mode == 'loss': 25 | return {'loss': self.loss(x, data_samples)} 26 | elif mode == 'predict': 27 | return x.argmax(1) 28 | else: 29 | return x 30 | 31 | 32 | model = Network() 33 | 34 | # 构建优化器 35 | optimizer = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.9) 36 | # 构建参数调度器用于调整学习率 37 | lr_scheduler = MultiStepLR(optimizer, milestones=[2], by_epoch=True) 38 | # 构建手写数字识别 (MNIST) 数据集 39 | train_dataset = datasets.MNIST( 40 | root="MNIST", download=True, train=True, transform=transforms.ToTensor()) 41 | # 构建数据加载器 42 | train_dataloader = DataLoader( 43 | dataset=train_dataset, batch_size=10, num_workers=2) 44 | 45 | 46 | # 训练相关参数设置,按轮次训练,训练3轮 47 | # train_cfg = dict(by_epoch=True, max_epochs=3) 48 | train_cfg = dict(by_epoch=False, max_iters=9000) 49 | # 初始化执行器 50 | runner = Runner(model, 51 | work_dir='./train_mnist', # 工作目录,用于保存模型和日志 52 | train_cfg=train_cfg, 53 | train_dataloader=train_dataloader, 54 | optim_wrapper=dict(optimizer=optimizer), 55 | param_scheduler=lr_scheduler) 56 | # 执行训练 57 | runner.train() 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | data -------------------------------------------------------------------------------- /15_minutes.py: -------------------------------------------------------------------------------- 1 | import torch.nn.functional as F 2 | import torchvision 3 | import torchvision.transforms as transforms 4 | from torch.optim import SGD 5 | from torch.utils.data import DataLoader 6 | 7 | from mmengine.evaluator import BaseMetric 8 | from mmengine.model import BaseModel 9 | from mmengine.runner import Runner 10 | 11 | 12 | class MMResNet50(BaseModel): 13 | def __init__(self): 14 | super().__init__() 15 | self.resnet = torchvision.models.resnet50() 16 | 17 | def forward(self, imgs, labels, mode): 18 | x = self.resnet(imgs) 19 | if mode == 'loss': 20 | return {'loss': F.cross_entropy(x, labels)} 21 | elif mode == 'predict': 22 | return x, labels 23 | 24 | 25 | class Accuracy(BaseMetric): 26 | def process(self, data_batch, data_samples): 27 | score, gt = data_samples 28 | self.results.append({ 29 | 'batch_size': len(gt), 30 | 'correct': (score.argmax(dim=1) == gt).sum().cpu(), 31 | }) 32 | 33 | def compute_metrics(self, results): 34 | total_correct = sum(item['correct'] for item in results) 35 | total_size = sum(item['batch_size'] for item in results) 36 | return dict(accuracy=100 * total_correct / total_size) 37 | 38 | 39 | norm_cfg = dict(mean=[0.491, 0.482, 0.447], std=[0.202, 0.199, 0.201]) 40 | train_dataloader = DataLoader(batch_size=32, 41 | shuffle=True, 42 | dataset=torchvision.datasets.CIFAR10( 43 | 'data/cifar10', 44 | train=True, 45 | download=True, 46 | transform=transforms.Compose([ 47 | transforms.RandomCrop(32, padding=4), 48 | transforms.RandomHorizontalFlip(), 49 | transforms.ToTensor(), 50 | transforms.Normalize(**norm_cfg) 51 | ]))) 52 | 53 | val_dataloader = DataLoader(batch_size=32, 54 | shuffle=False, 55 | dataset=torchvision.datasets.CIFAR10( 56 | 'data/cifar10', 57 | train=False, 58 | download=True, 59 | transform=transforms.Compose([ 60 | transforms.ToTensor(), 61 | transforms.Normalize(**norm_cfg) 62 | ]))) 63 | 64 | runner = Runner( 65 | model=MMResNet50(), 66 | work_dir='./work_dir', 67 | train_dataloader=train_dataloader, 68 | optim_wrapper=dict(optimizer=dict(type=SGD, lr=0.001, momentum=0.9)), 69 | train_cfg=dict(by_epoch=True, max_epochs=5, val_interval=1), 70 | val_dataloader=val_dataloader, 71 | val_cfg=dict(), 72 | val_evaluator=dict(type=Accuracy), 73 | ) 74 | runner.train() 75 | -------------------------------------------------------------------------------- /01_registry/01_start.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 67, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "from mmengine import Registry\n", 10 | "# scope 表示注册器的作用域,如果不设置,默认为包名,例如在 mmdetection 中,它的 scope 为 mmdet\n", 11 | "ACTIVATION = Registry('activation', scope='mmengine')" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 68, 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "import torch.nn as nn\n", 21 | "import torch\n", 22 | "\n", 23 | "# 使用注册器管理模块\n", 24 | "@ACTIVATION.register_module()\n", 25 | "class Sigmoid(nn.Module):\n", 26 | " def __init__(self):\n", 27 | " super().__init__()\n", 28 | "\n", 29 | " def forward(self, x):\n", 30 | " print('call Sigmoid.forward')\n", 31 | " x = torch.sigmoid(x)\n", 32 | " return x\n", 33 | "\n", 34 | "@ACTIVATION.register_module()\n", 35 | "class ReLU(nn.Module):\n", 36 | " def __init__(self, inplace=False):\n", 37 | " super().__init__()\n", 38 | "\n", 39 | " def forward(self, x):\n", 40 | " print('call ReLU.forward')\n", 41 | " x = torch.relu(x)\n", 42 | " return x\n", 43 | "\n", 44 | "@ACTIVATION.register_module()\n", 45 | "class Softmax(nn.Module):\n", 46 | " def __init__(self):\n", 47 | " super().__init__()\n", 48 | "\n", 49 | " def forward(self, x):\n", 50 | " print('call Softmax.forward')\n", 51 | " x = torch.softmax(x)\n", 52 | " return x" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 69, 58 | "metadata": {}, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "{'Sigmoid': , 'ReLU': , 'Softmax': }\n" 65 | ] 66 | } 67 | ], 68 | "source": [ 69 | "print(ACTIVATION.module_dict)\n" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": 70, 75 | "metadata": {}, 76 | "outputs": [ 77 | { 78 | "name": "stdout", 79 | "output_type": "stream", 80 | "text": [ 81 | "call Sigmoid.forward\n", 82 | "tensor([0.2689, 0.7311])\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "import torch\n", 88 | "input = torch.Tensor([-1, 1])\n", 89 | "\n", 90 | "act_cfg = dict(type='Sigmoid')\n", 91 | "activation = ACTIVATION.build(act_cfg)\n", 92 | "output = activation(input)\n", 93 | "# call Sigmoid.forward\n", 94 | "print(output)\n", 95 | "# tensor([0.0159, 0.0815])" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 72, 101 | "metadata": {}, 102 | "outputs": [ 103 | { 104 | "name": "stdout", 105 | "output_type": "stream", 106 | "text": [ 107 | "call ReLU.forward\n", 108 | "tensor([0., 1.])\n" 109 | ] 110 | } 111 | ], 112 | "source": [ 113 | "input = torch.Tensor([-1, 1])\n", 114 | "\n", 115 | "act_cfg = dict(type='ReLU', inplace=True)\n", 116 | "activation = ACTIVATION.build(act_cfg)\n", 117 | "output = activation(input)\n", 118 | "# call Sigmoid.forward\n", 119 | "print(output)\n", 120 | "# tensor([0.0159, 0.0815])" 121 | ] 122 | } 123 | ], 124 | "metadata": { 125 | "kernelspec": { 126 | "display_name": "Python 3.9.12 ('mmdet-yolo')", 127 | "language": "python", 128 | "name": "python3" 129 | }, 130 | "language_info": { 131 | "codemirror_mode": { 132 | "name": "ipython", 133 | "version": 3 134 | }, 135 | "file_extension": ".py", 136 | "mimetype": "text/x-python", 137 | "name": "python", 138 | "nbconvert_exporter": "python", 139 | "pygments_lexer": "ipython3", 140 | "version": "3.9.12" 141 | }, 142 | "orig_nbformat": 4, 143 | "vscode": { 144 | "interpreter": { 145 | "hash": "b8e27fa7a4910f0db2656c6311d3024d4c4814786eee182f5bdf8dbffc78e0c0" 146 | } 147 | } 148 | }, 149 | "nbformat": 4, 150 | "nbformat_minor": 2 151 | } 152 | -------------------------------------------------------------------------------- /02_config/01_main.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/config_sgd.py\n", 10 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/cross_repo.py\n", 11 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/custom_imports.py\n", 12 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/demo_train.py\n", 13 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/example.py\n", 14 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/learn_read_config.py\n", 15 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/my_module.py\n", 16 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/optimizer_cfg.py\n", 17 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/predefined_var.py\n", 18 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/refer_base_var.py\n", 19 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/resnet50_delete_key.py\n", 20 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/resnet50_lr0.01.py\n", 21 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/resnet50_runtime.py\n", 22 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/resnet50.py\n", 23 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/runtime_cfg.py\n", 24 | "!wget https://raw.githubusercontent.com/open-mmlab/mmengine/main/docs/resources/config/modify_base_var.py" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": null, 30 | "metadata": {}, 31 | "outputs": [], 32 | "source": [ 33 | "from mmengine.config import Config\n", 34 | "\n", 35 | "cfg = Config.fromfile('learn_read_config.py')\n", 36 | "print(cfg)" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "print(cfg.test_int)\n", 46 | "print(cfg.test_list)\n", 47 | "print(cfg.test_dict)\n", 48 | "cfg.test_int = 2\n", 49 | "\n", 50 | "print(cfg['test_int'])\n", 51 | "print(cfg['test_list'])\n", 52 | "print(cfg['test_dict'])\n", 53 | "cfg['test_list'][1] = 3\n", 54 | "print(cfg['test_list'])" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "from mmengine import Config\n", 64 | "from mmengine.registry import OPTIMIZERS\n", 65 | "\n", 66 | "import torch.nn as nn\n", 67 | "\n", 68 | "cfg = Config.fromfile('config_sgd.py')\n", 69 | "\n", 70 | "model = nn.Conv2d(1, 1, 1)\n", 71 | "cfg.optimizer.params = model.parameters()\n", 72 | "optimizer = OPTIMIZERS.build(cfg.optimizer)\n", 73 | "print(optimizer)" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "metadata": {}, 80 | "outputs": [], 81 | "source": [ 82 | "cfg = Config.fromfile('resnet50.py')\n", 83 | "print(cfg.optimizer)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": null, 89 | "metadata": {}, 90 | "outputs": [], 91 | "source": [ 92 | "cfg = Config.fromfile('resnet50_runtime.py')\n", 93 | "print(cfg.optimizer)" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [ 102 | "cfg = Config.fromfile('resnet50_lr0.01.py')\n", 103 | "print(cfg.optimizer)" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 13, 109 | "metadata": {}, 110 | "outputs": [], 111 | "source": [ 112 | "cfg = Config.fromfile('resnet50_delete_key.py')\n", 113 | "print(cfg.optimizer)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [ 122 | "cfg = Config.fromfile('refer_base_var.py')\n", 123 | "print(cfg.a)" 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": null, 129 | "metadata": {}, 130 | "outputs": [], 131 | "source": [ 132 | "cfg = Config.fromfile('modify_base_var.py')\n", 133 | "print(cfg.a)" 134 | ] 135 | } 136 | ], 137 | "metadata": { 138 | "kernelspec": { 139 | "display_name": "Python 3.9.12 ('mmdet-yolo')", 140 | "language": "python", 141 | "name": "python3" 142 | }, 143 | "language_info": { 144 | "codemirror_mode": { 145 | "name": "ipython", 146 | "version": 3 147 | }, 148 | "file_extension": ".py", 149 | "mimetype": "text/x-python", 150 | "name": "python", 151 | "nbconvert_exporter": "python", 152 | "pygments_lexer": "ipython3", 153 | "version": "3.9.12" 154 | }, 155 | "orig_nbformat": 4, 156 | "vscode": { 157 | "interpreter": { 158 | "hash": "b8e27fa7a4910f0db2656c6311d3024d4c4814786eee182f5bdf8dbffc78e0c0" 159 | } 160 | } 161 | }, 162 | "nbformat": 4, 163 | "nbformat_minor": 2 164 | } 165 | -------------------------------------------------------------------------------- /01_registry/02_free_combination.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 7, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "ename": "TypeError", 10 | "evalue": "__init__() missing 1 required positional argument: 'act_type'", 11 | "output_type": "error", 12 | "traceback": [ 13 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 14 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 15 | "\u001b[1;32m/project/openmmlab2/mmengine-learn/01_registry/02_free_combination.ipynb Cell 1\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 16\u001b[0m x \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mact(x)\n\u001b[1;32m 17\u001b[0m \u001b[39mreturn\u001b[39;00m x\n\u001b[0;32m---> 19\u001b[0m conv_block \u001b[39m=\u001b[39m ConvBlock()\n", 16 | "\u001b[0;31mTypeError\u001b[0m: __init__() missing 1 required positional argument: 'act_type'" 17 | ] 18 | } 19 | ], 20 | "source": [ 21 | "# 原始方式\n", 22 | "\n", 23 | "import torch.nn as nn\n", 24 | "\n", 25 | "class ConvBlock(nn.Module):\n", 26 | "\n", 27 | " def __init__(self, act_type):\n", 28 | " self.conv = nn.Conv2d()\n", 29 | " if act_type == 'relu':\n", 30 | " self.act = nn.ReLU()\n", 31 | " elif act_type == 'gelu':\n", 32 | " self.act = nn.GELU()\n", 33 | "\n", 34 | " def forward(self, x):\n", 35 | " x = self.conv(x)\n", 36 | " x = self.act(x)\n", 37 | " return x\n", 38 | "\n", 39 | "conv_block = ConvBlock()\n" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 5, 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "ename": "KeyError", 49 | "evalue": "'Conv2d is already registered in model at torch.nn.modules.conv'", 50 | "output_type": "error", 51 | "traceback": [ 52 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 53 | "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", 54 | "\u001b[1;32m/project/openmmlab2/mmengine-learn/01_registry/02_free_combination.ipynb Cell 2\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mmmengine\u001b[39;00m \u001b[39mimport\u001b[39;00m MODELS\n\u001b[1;32m 4\u001b[0m \u001b[39m# 将卷积和激活模块注册到 MODELS\u001b[39;00m\n\u001b[0;32m----> 5\u001b[0m MODELS\u001b[39m.\u001b[39;49mregister_module(module\u001b[39m=\u001b[39;49mnn\u001b[39m.\u001b[39;49mConv2d)\n\u001b[1;32m 6\u001b[0m MODELS\u001b[39m.\u001b[39mregister_module(module\u001b[39m=\u001b[39mnn\u001b[39m.\u001b[39mReLU)\n\u001b[1;32m 7\u001b[0m MODELS\u001b[39m.\u001b[39mregister_module(module\u001b[39m=\u001b[39mnn\u001b[39m.\u001b[39mGELU)\n", 55 | "File \u001b[0;32m/project/openmmlab2/mmengine/mmengine/registry/registry.py:512\u001b[0m, in \u001b[0;36mRegistry.register_module\u001b[0;34m(self, name, force, module)\u001b[0m\n\u001b[1;32m 510\u001b[0m \u001b[39m# use it as a normal method: x.register_module(module=SomeClass)\u001b[39;00m\n\u001b[1;32m 511\u001b[0m \u001b[39mif\u001b[39;00m module \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m--> 512\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_register_module(module\u001b[39m=\u001b[39;49mmodule, module_name\u001b[39m=\u001b[39;49mname, force\u001b[39m=\u001b[39;49mforce)\n\u001b[1;32m 513\u001b[0m \u001b[39mreturn\u001b[39;00m module\n\u001b[1;32m 515\u001b[0m \u001b[39m# use it as a decorator: @x.register_module()\u001b[39;00m\n", 56 | "File \u001b[0;32m/project/openmmlab2/mmengine/mmengine/registry/registry.py:462\u001b[0m, in \u001b[0;36mRegistry._register_module\u001b[0;34m(self, module, module_name, force)\u001b[0m\n\u001b[1;32m 460\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m force \u001b[39mand\u001b[39;00m name \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_module_dict:\n\u001b[1;32m 461\u001b[0m existed_module \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mmodule_dict[name]\n\u001b[0;32m--> 462\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mKeyError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00mname\u001b[39m}\u001b[39;00m\u001b[39m is already registered in \u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mname\u001b[39m}\u001b[39;00m\u001b[39m \u001b[39m\u001b[39m'\u001b[39m\n\u001b[1;32m 463\u001b[0m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39mat \u001b[39m\u001b[39m{\u001b[39;00mexisted_module\u001b[39m.\u001b[39m\u001b[39m__module__\u001b[39m\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m)\n\u001b[1;32m 464\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_module_dict[name] \u001b[39m=\u001b[39m module\n", 57 | "\u001b[0;31mKeyError\u001b[0m: 'Conv2d is already registered in model at torch.nn.modules.conv'" 58 | ] 59 | } 60 | ], 61 | "source": [ 62 | "import torch.nn as nn\n", 63 | "from mmengine import MODELS\n", 64 | "\n", 65 | "# 将卷积和激活模块注册到 MODELS\n", 66 | "# MODELS.register_module(module=nn.Conv2d)\n", 67 | "# MODELS.register_module(module=nn.ReLU)\n", 68 | "# MODELS.register_module(module=nn.GELU)\n", 69 | "\n", 70 | "class ConvBlock(nn.Module):\n", 71 | "\n", 72 | " def __init__(self, conv_cfg, act_cfg):\n", 73 | " self.conv = MODELS.build(conv_cfg)\n", 74 | " self.pool = MODELS.build(act_cfg)\n", 75 | "\n", 76 | " def forward(self, x):\n", 77 | " x = self.conv(x)\n", 78 | " x = self.act(x)\n", 79 | " return x\n", 80 | "\n", 81 | "# 注意,conv_cfg 和 act_cfg 可以通过解析配置文件得到\n", 82 | "conv_cfg = dict(type='Conv2d', in_channels=3, out_channels=256, kernel_size=3)\n", 83 | "act_cfg = dict(type='GELU')\n", 84 | "conv_block = ConvBlock(conv_cfg, act_cfg)" 85 | ] 86 | } 87 | ], 88 | "metadata": { 89 | "kernelspec": { 90 | "display_name": "Python 3.9.12 ('mmdet-yolo')", 91 | "language": "python", 92 | "name": "python3" 93 | }, 94 | "language_info": { 95 | "codemirror_mode": { 96 | "name": "ipython", 97 | "version": 3 98 | }, 99 | "file_extension": ".py", 100 | "mimetype": "text/x-python", 101 | "name": "python", 102 | "nbconvert_exporter": "python", 103 | "pygments_lexer": "ipython3", 104 | "version": "3.9.12" 105 | }, 106 | "orig_nbformat": 4, 107 | "vscode": { 108 | "interpreter": { 109 | "hash": "b8e27fa7a4910f0db2656c6311d3024d4c4814786eee182f5bdf8dbffc78e0c0" 110 | } 111 | } 112 | }, 113 | "nbformat": 4, 114 | "nbformat_minor": 2 115 | } 116 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------