Repository: namepllet/HandOccNet Branch: master Commit: 65ba997c9ce8 Files: 55 Total size: 311.4 KB Directory structure: gitextract_dl_xba82/ ├── .gitignore ├── README.md ├── common/ │ ├── base.py │ ├── logger.py │ ├── nets/ │ │ ├── backbone.py │ │ ├── cbam.py │ │ ├── hand_head.py │ │ ├── mano_head.py │ │ ├── regressor.py │ │ └── transformer.py │ ├── timer.py │ └── utils/ │ ├── __init__.py │ ├── camera.py │ ├── dir.py │ ├── fitting.py │ ├── mano.py │ ├── manopth/ │ │ ├── .gitignore │ │ ├── LICENSE │ │ ├── README.md │ │ ├── environment.yml │ │ ├── examples/ │ │ │ ├── manopth_demo.py │ │ │ └── manopth_mindemo.py │ │ ├── mano/ │ │ │ ├── __init__.py │ │ │ └── webuser/ │ │ │ ├── __init__.py │ │ │ ├── lbs.py │ │ │ ├── posemapper.py │ │ │ ├── serialization.py │ │ │ ├── smpl_handpca_wrapper_HAND_only.py │ │ │ └── verts.py │ │ ├── manopth/ │ │ │ ├── __init__.py │ │ │ ├── argutils.py │ │ │ ├── demo.py │ │ │ ├── manolayer.py │ │ │ ├── rodrigues_layer.py │ │ │ ├── rot6d.py │ │ │ ├── rotproj.py │ │ │ └── tensutils.py │ │ ├── setup.py │ │ └── test/ │ │ └── test_demo.py │ ├── optimizers/ │ │ ├── __init__.py │ │ ├── lbfgs_ls.py │ │ └── optim_factory.py │ ├── preprocessing.py │ ├── transforms.py │ └── vis.py ├── data/ │ ├── DEX_YCB/ │ │ └── DEX_YCB.py │ └── HO3D/ │ └── HO3D.py ├── demo/ │ ├── demo.py │ ├── demo_fitting.py │ └── output.obj ├── main/ │ ├── config.py │ ├── model.py │ ├── test.py │ └── train.py └── requiremets.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Created by .ignore support plugin (hsz.mobi) ### Python template # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so *.npy #*.png *.jpg *.out output data/*/data # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib64/ parts/ sdist/ var/ wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # pyenv .python-version # celery beat schedule file celerybeat-schedule # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ ### macOS template # General .DS_Store .AppleDouble .LSOverride # Icon must end with two \r Icon # Thumbnails ._* # Files that might appear in the root of a volume .DocumentRevisions-V100 .fseventsd .Spotlight-V100 .TemporaryItems .Trashes .VolumeIcon.icns .com.apple.timemachine.donotpresent # Directories potentially created on remote AFP share .AppleDB .AppleDesktop Network Trash Folder Temporary Items .apdisk ### JetBrains template # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff .idea/**/workspace.xml .idea/**/tasks.xml .idea/**/dictionaries .idea/**/shelf # Sensitive or high-churn files .idea/**/dataSources/ .idea/**/dataSources.ids .idea/**/dataSources.local.xml .idea/**/sqlDataSources.xml .idea/**/dynamic.xml .idea/**/uiDesigner.xml .idea/**/dbnavigator.xml # Gradle .idea/**/gradle.xml .idea/**/libraries # CMake cmake-build-debug/ cmake-build-release/ # Mongo Explorer plugin .idea/**/mongoSettings.xml # File-based project format *.iws # IntelliJ out/ # mpeltonen/sbt-idea plugin .idea_modules/ # JIRA plugin atlassian-ide-plugin.xml # Cursive Clojure plugin .idea/replstate.xml # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties # Editor-based Rest Client .idea/httpRequests ================================================ FILE: README.md ================================================ # HandOccNet: Occlusion-Robust 3D Hand Mesh Estimation Network ## Introduction This repository is the offical [Pytorch](https://pytorch.org/) implementation of **[HandOccNet: Occlusion-Robust 3D Hand Mesh Estimation Network (CVPR 2022)](https://arxiv.org/abs/2203.14564)**. Below is the overall pipeline of HandOccNet. ![overall pipeline](./asset/model.png) ## Quick demo * Install **[PyTorch](https://pytorch.org)** and Python >= 3.7.4 and run `sh requirements.sh`. * Download `snapshot_demo.pth.tar` from [here](https://drive.google.com/drive/folders/1OlyV-qbzOmtQYdzV6dbQX4OtAU5ajBOa?usp=sharing) and place at `demo` folder. * Prepare `input.jpg` at `demo` folder. * Download `MANO_RIGHT.pkl` from [here](https://mano.is.tue.mpg.de/) and place at `common/utils/manopth/mano/models`. * Go to `demo` folder and edit `bbox` in [here](https://github.com/namepllet/HandOccNet/blob/185492e0e5b08c47e37039c5d67e3f2b099a6f9e/demo/demo.py#L61). * Run `python demo.py --gpu 0` if you want to run on gpu 0. * You can see `hand_bbox.png`, `hand_image.png`, and `output.obj`. * Run `python demo_fitting.py --gpu 0 --depth 0.5` if you want to get the hand mesh's translation from the camera. The depth argument is initialization for the optimization. * You can see `fitting_input_3d_mesh.json` that contains the translation and MANO parameters, `fitting_input_3dmesh.obj`, `fitting_input_2d_prediction.png`, and `fitting_input_projection.png`. ## Directory ### Root The `${ROOT}` is described as below. ``` ${ROOT} |-- data |-- demo |-- common |-- main |-- output ``` * `data` contains data loading codes and soft links to images and annotations directories. * `demo` contains demo codes. * `common` contains kernel codes for HandOccNet. * `main` contains high-level codes for training or testing the network. * `output` contains log, trained models, visualized outputs, and test result. ### Data You need to follow directory structure of the `data` as below. ``` ${ROOT} |-- data | |-- HO3D | | |-- data | | | |-- train | | | | |-- ABF10 | | | | |-- ...... | | | |-- evaluation | | | |-- annotations | | | | |-- HO3D_train_data.json | | | | |-- HO3D_evaluation_data.json | |-- DEX_YCB | | |-- data | | | |-- 20200709-subject-01 | | | |-- ...... | | | |-- annotations | | | | |--DEX_YCB_s0_train_data.json | | | | |--DEX_YCB_s0_test_data.json ``` * Download HO3D(version 2) data and annotation files [[data](https://www.tugraz.at/institute/icg/research/team-lepetit/research-projects/hand-object-3d-pose-annotation/)][[annotation files](https://drive.google.com/drive/folders/1pmRpgv38PXvlLOODtoxpTYnIpYTkNV6b?usp=sharing)] * Download DexYCB data and annotation files [[data](https://dex-ycb.github.io/)][[annotation files](https://drive.google.com/drive/folders/1pmRpgv38PXvlLOODtoxpTYnIpYTkNV6b?usp=sharing)] ### Pytorch MANO layer * For the MANO layer, I used [manopth](https://github.com/hassony2/manopth). The repo is already included in `common/utils/manopth`. * Download `MANO_RIGHT.pkl` from [here](https://mano.is.tue.mpg.de/) and place at `common/utils/manopth/mano/models`. ### Output You need to follow the directory structure of the `output` folder as below. ``` ${ROOT} |-- output | |-- log | |-- model_dump | |-- result | |-- vis ``` * Creating `output` folder as soft link form is recommended instead of folder form because it would take large storage capacity. * `log` folder contains training log file. * `model_dump` folder contains saved checkpoints for each epoch. * `result` folder contains final estimation files generated in the testing stage. * `vis` folder contains visualized results. ## Running HandOccNet ### Start * Install **[PyTorch](https://pytorch.org)** and Python >= 3.7.4 and run `sh requirements.sh`. * In the `main/config.py`, you can change settings of the model including dataset to use and input size and so on. ### Train In the `main` folder, set trainset in `config.py` (as 'HO3D' or 'DEX_YCB') and run ```bash python train.py --gpu 0-3 ``` to train HandOccNet on the GPU 0,1,2,3. `--gpu 0,1,2,3` can be used instead of `--gpu 0-3`. ### Test Place trained model at the `output/model_dump/`. In the `main` folder, set testset in `config.py` (as 'HO3D' or 'DEX_YCB') and run ```bash python test.py --gpu 0-3 --test_epoch {test epoch} ``` to test HandOccNet on the GPU 0,1,2,3 with {test epoch}th epoch trained model. `--gpu 0,1,2,3` can be used instead of `--gpu 0-3`. * For the HO3D dataset, pred{test epoch}.zip will be generated in `output/result` folder. You can upload it to the [codalab challenge](https://competitions.codalab.org/competitions/22485) and see the results. * Our trained model can be downloaded from [here](https://drive.google.com/drive/folders/1OlyV-qbzOmtQYdzV6dbQX4OtAU5ajBOa?usp=sharing) ## Results Here I report the performance of the HandOccNet.

## Reference ``` @InProceedings{Park_2022_CVPR_HandOccNet, author = {Park, JoonKyu and Oh, Yeonguk and Moon, Gyeongsik and Choi, Hongsuk and Lee, Kyoung Mu}, title = {HandOccNet: Occlusion-Robust 3D Hand Mesh Estimation Network}, booktitle = {Conference on Computer Vision and Pattern Recognition (CVPR)}, year = {2022} } ``` ## Acknowledgements For this project, we relied on research codes from: * [I2L-MeshNet_RELEASE](https://github.com/mks0601/I2L-MeshNet_RELEASE) * [Semi-Hand-Object](https://github.com/stevenlsw/Semi-Hand-Object) * [attention-module](https://github.com/Jongchan/attention-module) ================================================ FILE: common/base.py ================================================ import os import os.path as osp import math import time import glob import abc from torch.utils.data import DataLoader import torch.optim import torchvision.transforms as transforms from timer import Timer from logger import colorlogger from torch.nn.parallel.data_parallel import DataParallel from config import cfg from model import get_model # dynamic dataset import exec('from ' + cfg.trainset + ' import ' + cfg.trainset) exec('from ' + cfg.testset + ' import ' + cfg.testset) class Base(object): __metaclass__ = abc.ABCMeta def __init__(self, log_name='logs.txt'): self.cur_epoch = 0 # timer self.tot_timer = Timer() self.gpu_timer = Timer() self.read_timer = Timer() # logger self.logger = colorlogger(cfg.log_dir, log_name=log_name) @abc.abstractmethod def _make_batch_generator(self): return @abc.abstractmethod def _make_model(self): return class Trainer(Base): def __init__(self): super(Trainer, self).__init__(log_name = 'train_logs.txt') def get_optimizer(self, model): model_params = filter(lambda p: p.requires_grad, model.parameters()) optimizer = torch.optim.Adam(model_params, lr=cfg.lr) return optimizer def save_model(self, state, epoch): file_path = osp.join(cfg.model_dir,'snapshot_{}.pth.tar'.format(str(epoch))) torch.save(state, file_path) self.logger.info("Write snapshot into {}".format(file_path)) def load_model(self, model, optimizer): model_file_list = glob.glob(osp.join(cfg.model_dir,'*.pth.tar')) cur_epoch = max([int(file_name[file_name.find('snapshot_') + 9 : file_name.find('.pth.tar')]) for file_name in model_file_list]) ckpt_path = osp.join(cfg.model_dir, 'snapshot_' + str(cur_epoch) + '.pth.tar') ckpt = torch.load(ckpt_path) start_epoch = ckpt['epoch'] + 1 model.load_state_dict(ckpt['network'], strict=False) #optimizer.load_state_dict(ckpt['optimizer']) self.logger.info('Load checkpoint from {}'.format(ckpt_path)) return start_epoch, model, optimizer def set_lr(self, epoch): for e in cfg.lr_dec_epoch: if epoch < e: break if epoch < cfg.lr_dec_epoch[-1]: idx = cfg.lr_dec_epoch.index(e) for g in self.optimizer.param_groups: g['lr'] = cfg.lr * (cfg.lr_dec_factor ** idx) else: for g in self.optimizer.param_groups: g['lr'] = cfg.lr * (cfg.lr_dec_factor ** len(cfg.lr_dec_epoch)) def get_lr(self): for g in self.optimizer.param_groups: cur_lr = g['lr'] return cur_lr def _make_batch_generator(self): # data load and construct batch generator self.logger.info("Creating dataset...") train_dataset = eval(cfg.trainset)(transforms.ToTensor(), "train") self.itr_per_epoch = math.ceil(len(train_dataset) / cfg.num_gpus / cfg.train_batch_size) self.batch_generator = DataLoader(dataset=train_dataset, batch_size=cfg.num_gpus*cfg.train_batch_size, shuffle=True, num_workers=cfg.num_thread, pin_memory=True) def _make_model(self): # prepare network self.logger.info("Creating graph and optimizer...") model = get_model('train') model = DataParallel(model).cuda() optimizer = self.get_optimizer(model) if cfg.continue_train: start_epoch, model, optimizer = self.load_model(model, optimizer) else: start_epoch = 0 model.train() self.start_epoch = start_epoch self.model = model self.optimizer = optimizer class Tester(Base): def __init__(self, test_epoch): self.test_epoch = int(test_epoch) super(Tester, self).__init__(log_name = 'test_logs.txt') def _make_batch_generator(self): # data load and construct batch generator self.logger.info("Creating dataset...") self.test_dataset = eval(cfg.testset)(transforms.ToTensor(), "test") self.batch_generator = DataLoader(dataset=self.test_dataset, batch_size=cfg.num_gpus*cfg.test_batch_size, shuffle=False, num_workers=cfg.num_thread, pin_memory=True) def _make_model(self): model_path = os.path.join(cfg.model_dir, 'snapshot_%d.pth.tar' % self.test_epoch) assert os.path.exists(model_path), 'Cannot find model at ' + model_path self.logger.info('Load checkpoint from {}'.format(model_path)) # prepare network self.logger.info("Creating graph...") model = get_model('test') model = DataParallel(model).cuda() ckpt = torch.load(model_path) model.load_state_dict(ckpt['network'], strict=False) model.eval() self.model = model def _evaluate(self, outs, cur_sample_idx): eval_result = self.test_dataset.evaluate(outs, cur_sample_idx) return eval_result def _print_eval_result(self, test_epoch): self.test_dataset.print_eval_result(test_epoch) ================================================ FILE: common/logger.py ================================================ import logging import os OK = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' END = '\033[0m' PINK = '\033[95m' BLUE = '\033[94m' GREEN = OK RED = FAIL WHITE = END YELLOW = WARNING class colorlogger(): def __init__(self, log_dir, log_name='train_logs.txt'): # set log self._logger = logging.getLogger(log_name) self._logger.setLevel(logging.INFO) log_file = os.path.join(log_dir, log_name) if not os.path.exists(log_dir): os.makedirs(log_dir) file_log = logging.FileHandler(log_file, mode='a') file_log.setLevel(logging.INFO) console_log = logging.StreamHandler() console_log.setLevel(logging.INFO) formatter = logging.Formatter( "{}%(asctime)s{} %(message)s".format(GREEN, END), "%m-%d %H:%M:%S") file_log.setFormatter(formatter) console_log.setFormatter(formatter) self._logger.addHandler(file_log) self._logger.addHandler(console_log) def debug(self, msg): self._logger.debug(str(msg)) def info(self, msg): self._logger.info(str(msg)) def warning(self, msg): self._logger.warning(WARNING + 'WRN: ' + str(msg) + END) def critical(self, msg): self._logger.critical(RED + 'CRI: ' + str(msg) + END) def error(self, msg): self._logger.error(RED + 'ERR: ' + str(msg) + END) ================================================ FILE: common/nets/backbone.py ================================================ import torch.nn as nn import torch.nn.functional as F import torch.utils.model_zoo as model_zoo from torchvision import ops import torch from nets.cbam import SpatialGate class FPN(nn.Module): def __init__(self, pretrained=True): super(FPN, self).__init__() self.in_planes = 64 resnet = resnet50(pretrained=pretrained) self.toplayer = nn.Conv2d(2048, 256, kernel_size=1, stride=1, padding=0) # Reduce channels self.layer0 = nn.Sequential(resnet.conv1, resnet.bn1, resnet.leakyrelu, resnet.maxpool) self.layer1 = nn.Sequential(resnet.layer1) self.layer2 = nn.Sequential(resnet.layer2) self.layer3 = nn.Sequential(resnet.layer3) self.layer4 = nn.Sequential(resnet.layer4) # Smooth layers #self.smooth1 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.smooth2 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) self.smooth3 = nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1) # Lateral layers self.latlayer1 = nn.Conv2d(1024, 256, kernel_size=1, stride=1, padding=0) self.latlayer2 = nn.Conv2d( 512, 256, kernel_size=1, stride=1, padding=0) self.latlayer3 = nn.Conv2d( 256, 256, kernel_size=1, stride=1, padding=0) # Attention Module self.attention_module = SpatialGate() self.pool = nn.AvgPool2d(2, stride=2) def _upsample_add(self, x, y): _, _, H, W = y.size() return F.interpolate(x, size=(H,W), mode='bilinear', align_corners=False) + y def forward(self, x): # Bottom-up c1 = self.layer0(x) c2 = self.layer1(c1) c3 = self.layer2(c2) c4 = self.layer3(c3) c5 = self.layer4(c4) # Top-down p5 = self.toplayer(c5) p4 = self._upsample_add(p5, self.latlayer1(c4)) p3 = self._upsample_add(p4, self.latlayer2(c3)) p2 = self._upsample_add(p3, self.latlayer3(c2)) # Smooth #p4 = self.smooth1(p4) p3 = self.smooth2(p3) p2 = self.smooth3(p2) # Attention p2 = self.pool(p2) primary_feats, secondary_feats = self.attention_module(p2) return primary_feats, secondary_feats class ResNet(nn.Module): def __init__(self, block, layers, num_classes=1000): self.inplanes = 64 super(ResNet, self).__init__() self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False) self.bn1 = nn.BatchNorm2d(64) self.leakyrelu = nn.LeakyReLU(inplace=True) self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1) self.layer1 = self._make_layer(block, 64, layers[0]) self.layer2 = self._make_layer(block, 128, layers[1], stride=2) self.layer3 = self._make_layer(block, 256, layers[2], stride=2) self.layer4 = self._make_layer(block, 512, layers[3], stride=2) self.avgpool = nn.AvgPool2d(7, stride=1) self.fc = nn.Linear(512 * block.expansion, num_classes) for m in self.modules(): if isinstance(m, nn.Conv2d): nn.init.kaiming_normal_(m.weight, mode="fan_out", nonlinearity="leaky_relu") elif isinstance(m, nn.BatchNorm2d): nn.init.constant_(m.weight, 1) nn.init.constant_(m.bias, 0) def _make_layer(self, block, planes, blocks, stride=1): downsample = None if stride != 1 or self.inplanes != planes * block.expansion: downsample = nn.Sequential( nn.Conv2d(self.inplanes, planes * block.expansion, kernel_size=1, stride=stride, bias=False), nn.BatchNorm2d(planes * block.expansion)) layers = [] layers.append(block(self.inplanes, planes, stride, downsample)) self.inplanes = planes * block.expansion for i in range(1, blocks): layers.append(block(self.inplanes, planes)) return nn.Sequential(*layers) def forward(self, x): x = self.conv1(x) x = self.bn1(x) x = self.leakyrelu(x) x = self.maxpool(x) x = self.layer1(x) x = self.layer2(x) x = self.layer3(x) x = self.layer4(x) x = x.mean(3).mean(2) x = x.view(x.size(0), -1) x = self.fc(x) return x def resnet50(pretrained=False, **kwargs): """Constructs a ResNet-50 model Encoder""" model = ResNet(Bottleneck, [3, 4, 6, 3], **kwargs) if pretrained: model.load_state_dict(model_zoo.load_url("https://download.pytorch.org/models/resnet50-19c8e357.pth")) return model def conv3x3(in_planes, out_planes, stride=1): return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=False) class BasicBlock(nn.Module): expansion = 1 def __init__(self, inplanes, planes, stride=1, downsample=None): super(BasicBlock, self).__init__() self.conv1 = conv3x3(inplanes, planes, stride) self.bn1 = nn.BatchNorm2d(planes) self.leakyrelu = nn.LeakyReLU(inplace=True) self.conv2 = conv3x3(planes, planes) self.bn2 = nn.BatchNorm2d(planes) self.downsample = downsample self.stride = stride def forward(self, x): residual = x out = self.conv1(x) out = self.bn1(out) out = self.leakyrelu(out) out = self.conv2(out) out = self.bn2(out) if self.downsample is not None: residual = self.downsample(x) out += residual out = self.leakyrelu(out) return out class Bottleneck(nn.Module): expansion = 4 def __init__(self, inplanes, planes, stride=1, downsample=None): super(Bottleneck, self).__init__() self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False) self.bn1 = nn.BatchNorm2d(planes) self.conv2 = nn.Conv2d( planes, planes, kernel_size=3, stride=stride, padding=1, bias=False ) self.bn2 = nn.BatchNorm2d(planes) self.conv3 = nn.Conv2d( planes, planes * self.expansion, kernel_size=1, bias=False ) self.bn3 = nn.BatchNorm2d(planes * self.expansion) self.leakyrelu = nn.LeakyReLU(inplace=True) self.downsample = downsample self.stride = stride def forward(self, x): residual = x out = self.conv1(x) out = self.bn1(out) out = self.leakyrelu(out) out = self.conv2(out) out = self.bn2(out) out = self.leakyrelu(out) out = self.conv3(out) out = self.bn3(out) if self.downsample is not None: residual = self.downsample(x) out += residual out = self.leakyrelu(out) return out ================================================ FILE: common/nets/cbam.py ================================================ import torch import math import torch.nn as nn import torch.nn.functional as F class BasicConv(nn.Module): def __init__(self, in_planes, out_planes, kernel_size, stride=1, padding=0, dilation=1, groups=1, relu=True, bn=True, bias=False): super(BasicConv, self).__init__() self.out_channels = out_planes self.conv = nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride=stride, padding=padding, dilation=dilation, groups=groups, bias=bias) self.bn = nn.BatchNorm2d(out_planes,eps=1e-5, momentum=0.01, affine=True) if bn else None self.relu = nn.ReLU() if relu else None def forward(self, x): x = self.conv(x) if self.bn is not None: x = self.bn(x) if self.relu is not None: x = self.relu(x) return x class Flatten(nn.Module): def forward(self, x): return x.view(x.size(0), -1) class ChannelGate(nn.Module): def __init__(self, gate_channels, reduction_ratio=16, pool_types=['avg', 'max']): super(ChannelGate, self).__init__() self.gate_channels = gate_channels self.mlp = nn.Sequential( Flatten(), nn.Linear(gate_channels, gate_channels // reduction_ratio), nn.ReLU(), nn.Linear(gate_channels // reduction_ratio, gate_channels) ) self.pool_types = pool_types def forward(self, x): channel_att_sum = None for pool_type in self.pool_types: if pool_type=='avg': avg_pool = F.avg_pool2d( x, (x.size(2), x.size(3)), stride=(x.size(2), x.size(3))) channel_att_raw = self.mlp( avg_pool ) elif pool_type=='max': max_pool = F.max_pool2d( x, (x.size(2), x.size(3)), stride=(x.size(2), x.size(3))) channel_att_raw = self.mlp( max_pool ) elif pool_type=='lp': lp_pool = F.lp_pool2d( x, 2, (x.size(2), x.size(3)), stride=(x.size(2), x.size(3))) channel_att_raw = self.mlp( lp_pool ) elif pool_type=='lse': # LSE pool only lse_pool = logsumexp_2d(x) channel_att_raw = self.mlp( lse_pool ) if channel_att_sum is None: channel_att_sum = channel_att_raw else: channel_att_sum = channel_att_sum + channel_att_raw scale = F.sigmoid( channel_att_sum ).unsqueeze(2).unsqueeze(3).expand_as(x) return x * scale def logsumexp_2d(tensor): tensor_flatten = tensor.view(tensor.size(0), tensor.size(1), -1) s, _ = torch.max(tensor_flatten, dim=2, keepdim=True) outputs = s + (tensor_flatten - s).exp().sum(dim=2, keepdim=True).log() return outputs class ChannelPool(nn.Module): def forward(self, x): return torch.cat( (torch.max(x,1)[0].unsqueeze(1), torch.mean(x,1).unsqueeze(1)), dim=1 ) class SpatialGate(nn.Module): def __init__(self): super(SpatialGate, self).__init__() kernel_size = 7 self.compress = ChannelPool() self.spatial = BasicConv(2, 1, kernel_size, stride=1, padding=(kernel_size-1) // 2, relu=False) def forward(self, x): x_compress = self.compress(x) x_out = self.spatial(x_compress) scale = F.sigmoid(x_out) # broadcasting return x*scale, x*(1-scale) class CBAM(nn.Module): def __init__(self, gate_channels, reduction_ratio=16, pool_types=['avg', 'max'], no_spatial=False): super(CBAM, self).__init__() self.ChannelGate = ChannelGate(gate_channels, reduction_ratio, pool_types) self.no_spatial=no_spatial if not no_spatial: self.SpatialGate = SpatialGate() def forward(self, x): x_out = self.ChannelGate(x) if not self.no_spatial: x_out = self.SpatialGate(x_out) return x_out ================================================ FILE: common/nets/hand_head.py ================================================ import torch from torch import nn import torch.nn.functional as F class hand_regHead(nn.Module): def __init__(self, roi_res=32, joint_nb=21, stacks=1, channels=256, blocks=1): """ Args: inr_res: input image size joint_nb: hand joint num """ super(hand_regHead, self).__init__() # hand head self.out_res = roi_res self.joint_nb = joint_nb self.channels = channels self.blocks = blocks self.stacks = stacks self.betas = nn.Parameter(torch.ones((self.joint_nb, 1), dtype=torch.float32)) center_offset = 0.5 vv, uu = torch.meshgrid(torch.arange(self.out_res).float(), torch.arange(self.out_res).float()) uu, vv = uu + center_offset, vv + center_offset self.register_buffer("uu", uu / self.out_res) self.register_buffer("vv", vv / self.out_res) self.softmax = nn.Softmax(dim=2) block = Bottleneck self.features = self.channels // block.expansion hg, res, fc, score, fc_, score_ = [], [], [], [], [], [] for i in range(self.stacks): hg.append(Hourglass(block, self.blocks, self.features, 4)) res.append(self.make_residual(block, self.channels, self.features, self.blocks)) fc.append(BasicBlock(self.channels, self.channels, kernel_size=1)) score.append(nn.Conv2d(self.channels, self.joint_nb, kernel_size=1, bias=True)) if i < self.stacks - 1: fc_.append(nn.Conv2d(self.channels, self.channels, kernel_size=1, bias=True)) score_.append(nn.Conv2d(self.joint_nb, self.channels, kernel_size=1, bias=True)) self.hg = nn.ModuleList(hg) self.res = nn.ModuleList(res) self.fc = nn.ModuleList(fc) self.score = nn.ModuleList(score) self.fc_ = nn.ModuleList(fc_) self.score_ = nn.ModuleList(score_) def make_residual(self, block, inplanes, planes, blocks, stride=1): skip = None if stride != 1 or inplanes != planes * block.expansion: skip = nn.Sequential( nn.Conv2d(inplanes, planes * block.expansion, kernel_size=1, stride=stride, bias=True)) layers = [] layers.append(block(inplanes, planes, stride, skip)) for i in range(1, blocks): layers.append(block(inplanes, planes)) return nn.Sequential(*layers) def spatial_softmax(self, latents): latents = latents.view((-1, self.joint_nb, self.out_res ** 2)) latents = latents * self.betas heatmaps = self.softmax(latents) heatmaps = heatmaps.view(-1, self.joint_nb, self.out_res, self.out_res) return heatmaps def generate_output(self, heatmaps): predictions = torch.stack(( torch.sum(torch.sum(heatmaps * self.uu, dim=2), dim=2), torch.sum(torch.sum(heatmaps * self.vv, dim=2), dim=2)), dim=2) return predictions def forward(self, x): out, encoding, preds = [], [], [] for i in range(self.stacks): y = self.hg[i](x) y = self.res[i](y) y = self.fc[i](y) latents = self.score[i](y) heatmaps= self.spatial_softmax(latents) out.append(heatmaps) predictions = self.generate_output(heatmaps) preds.append(predictions) if i < self.stacks - 1: fc_ = self.fc_[i](y) score_ = self.score_[i](heatmaps) x = x + fc_ + score_ encoding.append(x) else: encoding.append(y) return out, encoding, preds class BasicBlock(nn.Module): def __init__(self, in_planes, out_planes, kernel_size,groups=1): super(BasicBlock, self).__init__() self.block = nn.Sequential( nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size, stride=1, padding=((kernel_size - 1) // 2), groups=groups,bias=True), nn.BatchNorm2d(out_planes), nn.LeakyReLU(inplace=True) ) def forward(self, x): return self.block(x) class Residual(nn.Module): def __init__(self, numIn, numOut): super(Residual, self).__init__() self.numIn = numIn self.numOut = numOut self.bn = nn.BatchNorm2d(self.numIn) self.leakyrelu = nn.LeakyReLU(inplace=True) self.conv1 = nn.Conv2d(self.numIn, self.numOut // 2, bias=True, kernel_size=1) self.bn1 = nn.BatchNorm2d(self.numOut // 2) self.conv2 = nn.Conv2d(self.numOut // 2, self.numOut // 2, bias=True, kernel_size=3, stride=1, padding=1) self.bn2 = nn.BatchNorm2d(self.numOut // 2) self.conv3 = nn.Conv2d(self.numOut // 2, self.numOut, bias=True, kernel_size=1) if self.numIn != self.numOut: self.conv4 = nn.Conv2d(self.numIn, self.numOut, bias=True, kernel_size=1) def forward(self, x): residual = x out = self.bn(x) out = self.leakyrelu(out) out = self.conv1(out) out = self.bn1(out) out = self.leakyrelu(out) out = self.conv2(out) out = self.bn2(out) out = self.leakyrelu(out) out = self.conv3(out) if self.numIn != self.numOut: residual = self.conv4(x) return out + residual class Bottleneck(nn.Module): expansion = 2 def __init__(self, inplanes, planes, stride=1, skip=None, groups=1): super(Bottleneck, self).__init__() self.bn1 = nn.BatchNorm2d(inplanes) self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=True, groups=groups) self.bn2 = nn.BatchNorm2d(planes) self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=True, groups=groups) self.bn3 = nn.BatchNorm2d(planes) self.conv3 = nn.Conv2d(planes, planes * 2, kernel_size=1, bias=True, groups=groups) self.leakyrelu = nn.LeakyReLU(inplace=True) # negative_slope=0.01 self.skip = skip self.stride = stride def forward(self, x): residual = x out = self.bn1(x) out = self.leakyrelu(out) out = self.conv1(out) out = self.bn2(out) out = self.leakyrelu(out) out = self.conv2(out) out = self.bn3(out) out = self.leakyrelu(out) out = self.conv3(out) if self.skip is not None: residual = self.skip(x) out += residual return out class Hourglass(nn.Module): def __init__(self, block, num_blocks, planes, depth): super(Hourglass, self).__init__() self.depth = depth self.block = block self.hg = self._make_hour_glass(block, num_blocks, planes, depth) def _make_residual(self, block, num_blocks, planes): layers = [] for i in range(0, num_blocks): # channel changes: planes*block.expansion->planes->2*planes layers.append(block(planes * block.expansion, planes)) return nn.Sequential(*layers) def _make_hour_glass(self, block, num_blocks, planes, depth): hg = [] for i in range(depth): res = [] for j in range(3): # 3 residual modules composed of a residual unit # <2*planes><2*planes> res.append(self._make_residual(block, num_blocks, planes)) if i == 0: # i=0 in a recursive construction build the basic network path # see: low2 = self.hg[n-1][3](low1) # <2*planes><2*planes> res.append(self._make_residual(block, num_blocks, planes)) hg.append(nn.ModuleList(res)) return nn.ModuleList(hg) def _hour_glass_forward(self, n, x): up1 = self.hg[n - 1][0](x) # skip branches low1 = F.max_pool2d(x, 2, stride=2) low1 = self.hg[n - 1][1](low1) if n > 1: low2 = self._hour_glass_forward(n - 1, low1) else: low2 = self.hg[n - 1][3](low1) # only for depth=1 basic path of the hourglass network low3 = self.hg[n - 1][2](low2) up2 = F.interpolate(low3, scale_factor=2) # scale_factor=2 should be consistent with F.max_pool2d(2,stride=2) out = up1 + up2 return out def forward(self, x): # depth: order of the hourglass network # do network forward recursively return self._hour_glass_forward(self.depth, x) class hand_Encoder(nn.Module): def __init__(self, num_heatmap_chan=21, num_feat_chan=256, size_input_feature=(32, 32), nRegBlock=4, nRegModules=2): super(hand_Encoder, self).__init__() self.num_heatmap_chan = num_heatmap_chan self.num_feat_chan = num_feat_chan self.size_input_feature = size_input_feature self.nRegBlock = nRegBlock self.nRegModules = nRegModules self.heatmap_conv = nn.Conv2d(self.num_heatmap_chan, self.num_feat_chan, bias=True, kernel_size=1, stride=1) self.encoding_conv = nn.Conv2d(self.num_feat_chan, self.num_feat_chan, bias=True, kernel_size=1, stride=1) reg = [] for i in range(self.nRegBlock): for j in range(self.nRegModules): reg.append(Residual(self.num_feat_chan, self.num_feat_chan)) self.reg = nn.ModuleList(reg) self.maxpool = nn.MaxPool2d(kernel_size=2, stride=2) self.downsample_scale = 2 ** self.nRegBlock # fc layers self.num_feat_out = self.num_feat_chan * (size_input_feature[0] * size_input_feature[1] // (self.downsample_scale ** 2)) def forward(self, hm_list, encoding_list): x = self.heatmap_conv(hm_list[-1]) + self.encoding_conv(encoding_list[-1]) if len(encoding_list) > 1: x = x + encoding_list[-2] # x: B x num_feat_chan x 32 x 32 for i in range(self.nRegBlock): for j in range(self.nRegModules): x = self.reg[i * self.nRegModules + j](x) x = self.maxpool(x) # x: B x num_feat_chan x 2 x 2 out = x.view(x.size(0), -1) return out ================================================ FILE: common/nets/mano_head.py ================================================ import torch from torch import nn from torch.nn import functional as F from utils.mano import MANO mano = MANO() def batch_rodrigues(theta): # theta N x 3 l1norm = torch.norm(theta + 1e-8, p=2, dim=1) angle = torch.unsqueeze(l1norm, -1) normalized = torch.div(theta, angle) angle = angle * 0.5 v_cos = torch.cos(angle) v_sin = torch.sin(angle) quat = torch.cat([v_cos, v_sin * normalized], dim=1) return quat2mat(quat) def quat2mat(quat): """Convert quaternion coefficients to rotation matrix. """ norm_quat = quat norm_quat = norm_quat / norm_quat.norm(p=2, dim=1, keepdim=True) w, x, y, z = norm_quat[:, 0], norm_quat[:, 1], norm_quat[:, 2], norm_quat[:, 3] B = quat.size(0) w2, x2, y2, z2 = w.pow(2), x.pow(2), y.pow(2), z.pow(2) wx, wy, wz = w * x, w * y, w * z xy, xz, yz = x * y, x * z, y * z rotMat = torch.stack([w2 + x2 - y2 - z2, 2 * xy - 2 * wz, 2 * wy + 2 * xz, 2 * wz + 2 * xy, w2 - x2 + y2 - z2, 2 * yz - 2 * wx, 2 * xz - 2 * wy, 2 * wx + 2 * yz, w2 - x2 - y2 + z2], dim=1).view(B, 3, 3) return rotMat def quat2aa(quaternion): """Convert quaternion vector to angle axis of rotation.""" if not torch.is_tensor(quaternion): raise TypeError("Input type is not a torch.Tensor. Got {}".format( type(quaternion))) if not quaternion.shape[-1] == 4: raise ValueError("Input must be a tensor of shape Nx4 or 4. Got {}" .format(quaternion.shape)) # unpack input and compute conversion q1 = quaternion[..., 1] q2 = quaternion[..., 2] q3 = quaternion[..., 3] sin_squared_theta = q1 * q1 + q2 * q2 + q3 * q3 sin_theta = torch.sqrt(sin_squared_theta) cos_theta = quaternion[..., 0] two_theta = 2.0 * torch.where( cos_theta < 0.0, torch.atan2(-sin_theta, -cos_theta), torch.atan2(sin_theta, cos_theta)) k_pos = two_theta / sin_theta k_neg = 2.0 * torch.ones_like(sin_theta) k = torch.where(sin_squared_theta > 0.0, k_pos, k_neg) angle_axis = torch.zeros_like(quaternion)[..., :3] angle_axis[..., 0] += q1 * k angle_axis[..., 1] += q2 * k angle_axis[..., 2] += q3 * k return angle_axis def mat2quat(rotation_matrix, eps=1e-6): """Convert 3x4 rotation matrix to 4d quaternion vector""" if not torch.is_tensor(rotation_matrix): raise TypeError("Input type is not a torch.Tensor. Got {}".format( type(rotation_matrix))) if len(rotation_matrix.shape) > 3: raise ValueError( "Input size must be a three dimensional tensor. Got {}".format( rotation_matrix.shape)) if not rotation_matrix.shape[-2:] == (3, 4): raise ValueError( "Input size must be a N x 3 x 4 tensor. Got {}".format( rotation_matrix.shape)) rmat_t = torch.transpose(rotation_matrix, 1, 2) mask_d2 = rmat_t[:, 2, 2] < eps mask_d0_d1 = rmat_t[:, 0, 0] > rmat_t[:, 1, 1] mask_d0_nd1 = rmat_t[:, 0, 0] < -rmat_t[:, 1, 1] t0 = 1 + rmat_t[:, 0, 0] - rmat_t[:, 1, 1] - rmat_t[:, 2, 2] q0 = torch.stack([rmat_t[:, 1, 2] - rmat_t[:, 2, 1], t0, rmat_t[:, 0, 1] + rmat_t[:, 1, 0], rmat_t[:, 2, 0] + rmat_t[:, 0, 2]], -1) t0_rep = t0.repeat(4, 1).t() t1 = 1 - rmat_t[:, 0, 0] + rmat_t[:, 1, 1] - rmat_t[:, 2, 2] q1 = torch.stack([rmat_t[:, 2, 0] - rmat_t[:, 0, 2], rmat_t[:, 0, 1] + rmat_t[:, 1, 0], t1, rmat_t[:, 1, 2] + rmat_t[:, 2, 1]], -1) t1_rep = t1.repeat(4, 1).t() t2 = 1 - rmat_t[:, 0, 0] - rmat_t[:, 1, 1] + rmat_t[:, 2, 2] q2 = torch.stack([rmat_t[:, 0, 1] - rmat_t[:, 1, 0], rmat_t[:, 2, 0] + rmat_t[:, 0, 2], rmat_t[:, 1, 2] + rmat_t[:, 2, 1], t2], -1) t2_rep = t2.repeat(4, 1).t() t3 = 1 + rmat_t[:, 0, 0] + rmat_t[:, 1, 1] + rmat_t[:, 2, 2] q3 = torch.stack([t3, rmat_t[:, 1, 2] - rmat_t[:, 2, 1], rmat_t[:, 2, 0] - rmat_t[:, 0, 2], rmat_t[:, 0, 1] - rmat_t[:, 1, 0]], -1) t3_rep = t3.repeat(4, 1).t() mask_c0 = mask_d2 * mask_d0_d1 mask_c1 = mask_d2 * ~mask_d0_d1 mask_c2 = ~mask_d2 * mask_d0_nd1 mask_c3 = ~mask_d2 * ~mask_d0_nd1 mask_c0 = mask_c0.view(-1, 1).type_as(q0) mask_c1 = mask_c1.view(-1, 1).type_as(q1) mask_c2 = mask_c2.view(-1, 1).type_as(q2) mask_c3 = mask_c3.view(-1, 1).type_as(q3) q = q0 * mask_c0 + q1 * mask_c1 + q2 * mask_c2 + q3 * mask_c3 q /= torch.sqrt(t0_rep * mask_c0 + t1_rep * mask_c1 + # noqa t2_rep * mask_c2 + t3_rep * mask_c3) # noqa q *= 0.5 return q def rot6d2mat(x): """Convert 6D rotation representation to 3x3 rotation matrix. Based on Zhou et al., "On the Continuity of Rotation Representations in Neural Networks", CVPR 2019 """ a1 = x[:, 0:3] a2 = x[:, 3:6] b1 = F.normalize(a1) b2 = F.normalize(a2 - torch.einsum('bi,bi->b', b1, a2).unsqueeze(-1) * b1) b3 = torch.cross(b1, b2, dim=1) return torch.stack((b1, b2, b3), dim=-1) def mat2aa(rotation_matrix): """Convert 3x4 rotation matrix to Rodrigues vector""" def convert_points_to_homogeneous(points): if not torch.is_tensor(points): raise TypeError("Input type is not a torch.Tensor. Got {}".format( type(points))) if len(points.shape) < 2: raise ValueError("Input must be at least a 2D tensor. Got {}".format( points.shape)) return F.pad(points, (0, 1), "constant", 1.0) if rotation_matrix.shape[1:] == (3, 3): rotation_matrix = convert_points_to_homogeneous(rotation_matrix) quaternion = mat2quat(rotation_matrix) aa = quat2aa(quaternion) aa[torch.isnan(aa)] = 0.0 return aa class mano_regHead(nn.Module): def __init__(self, mano_layer=mano.layer, feature_size=1024, mano_neurons=[1024, 512]): super(mano_regHead, self).__init__() # 6D representation of rotation matrix self.pose6d_size = 16 * 6 self.mano_pose_size = 16 * 3 # Base Regression Layers mano_base_neurons = [feature_size] + mano_neurons base_layers = [] for layer_idx, (inp_neurons, out_neurons) in enumerate( zip(mano_base_neurons[:-1], mano_base_neurons[1:])): base_layers.append(nn.Linear(inp_neurons, out_neurons)) base_layers.append(nn.LeakyReLU(inplace=True)) self.mano_base_layer = nn.Sequential(*base_layers) # Pose layers self.pose_reg = nn.Linear(mano_base_neurons[-1], self.pose6d_size) # Shape layers self.shape_reg = nn.Linear(mano_base_neurons[-1], 10) self.mano_layer = mano_layer def forward(self, features, gt_mano_params=None): mano_features = self.mano_base_layer(features) pred_mano_pose_6d = self.pose_reg(mano_features) pred_mano_pose_rotmat = rot6d2mat(pred_mano_pose_6d.view(-1, 6)).view(-1, 16, 3, 3).contiguous() pred_mano_shape = self.shape_reg(mano_features) pred_mano_pose = mat2aa(pred_mano_pose_rotmat.view(-1, 3, 3)).contiguous().view(-1, self.mano_pose_size) pred_verts, pred_joints, pred_manojoints2cam = self.mano_layer(th_pose_coeffs=pred_mano_pose, th_betas=pred_mano_shape) pred_verts /= 1000 pred_joints /= 1000 pred_mano_results = { "verts3d": pred_verts, "joints3d": pred_joints, "mano_shape": pred_mano_shape, "mano_pose": pred_mano_pose_rotmat, "mano_pose_aa": pred_mano_pose, "manojoints2cam": pred_manojoints2cam } if gt_mano_params is not None: gt_mano_shape = gt_mano_params[:, self.mano_pose_size:] gt_mano_pose = gt_mano_params[:, :self.mano_pose_size].contiguous() gt_mano_pose_rotmat = batch_rodrigues(gt_mano_pose.view(-1, 3)).view(-1, 16, 3, 3) gt_verts, gt_joints = self.mano_layer(th_pose_coeffs=gt_mano_pose, th_betas=gt_mano_shape) gt_verts /= 1000 gt_joints /= 1000 gt_mano_results = { "verts3d": gt_verts, "joints3d": gt_joints, "mano_shape": gt_mano_shape, "mano_pose": gt_mano_pose_rotmat} else: gt_mano_results = None return pred_mano_results, gt_mano_results ================================================ FILE: common/nets/regressor.py ================================================ import torch import torch.nn as nn from torch.nn import functional as F from utils.mano import MANO from nets.hand_head import hand_regHead, hand_Encoder from nets.mano_head import mano_regHead class Regressor(nn.Module): def __init__(self): super(Regressor, self).__init__() self.hand_regHead = hand_regHead() self.hand_Encoder = hand_Encoder() self.mano_regHead = mano_regHead() def forward(self, feats, gt_mano_params=None): out_hm, encoding, preds_joints_img = self.hand_regHead(feats) mano_encoding = self.hand_Encoder(out_hm, encoding) pred_mano_results, gt_mano_results = self.mano_regHead(mano_encoding, gt_mano_params) return pred_mano_results, gt_mano_results, preds_joints_img ================================================ FILE: common/nets/transformer.py ================================================ import torch import torch.nn as nn import torch.nn.functional as F from einops import repeat class Transformer(nn.Module): def __init__(self, inp_res=32, dim=256, depth=2, num_heads=4, mlp_ratio=4., injection=True): super().__init__() self.injection=injection self.layers = nn.ModuleList([]) for _ in range(depth): self.layers.append(Block(dim=dim, num_heads=num_heads, mlp_ratio=mlp_ratio, injection=injection)) if self.injection: self.conv1 = nn.Sequential( nn.Conv2d(dim*2, dim, 3, padding=1), nn.ReLU(), nn.Conv2d(dim, dim, 3, padding=1), ) self.conv2 = nn.Sequential( nn.Conv2d(dim*2, dim, 1, padding=0), ) def forward(self, query, key): output = query for i, layer in enumerate(self.layers): output = layer(query=output, key=key) if self.injection: output = torch.cat([key, output], dim=1) output = self.conv1(output) + self.conv2(output) return output class Mlp(nn.Module): def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.): super().__init__() out_features = out_features or in_features hidden_features = hidden_features or in_features self.fc1 = nn.Linear(in_features, hidden_features) self.act = act_layer() self.fc2 = nn.Linear(hidden_features, out_features) self.drop = nn.Dropout(drop) self._init_weights() def forward(self, x): x = self.fc1(x) x = self.act(x) x = self.drop(x) x = self.fc2(x) x = self.drop(x) return x def _init_weights(self): nn.init.xavier_uniform_(self.fc1.weight) nn.init.xavier_uniform_(self.fc2.weight) nn.init.normal_(self.fc1.bias, std=1e-6) nn.init.normal_(self.fc2.bias, std=1e-6) class Attention(nn.Module): def __init__(self, dim, num_heads=1): super().__init__() self.num_heads = num_heads head_dim = dim // num_heads self.scale = head_dim ** -0.5 self.sigmoid = nn.Sigmoid() def forward(self, query, key, value, query2, key2, use_sigmoid): B, N, C = query.shape query = query.reshape(B, N, self.num_heads, C // self.num_heads).permute(0, 2, 1, 3) key = key.reshape(B, N, self.num_heads, C // self.num_heads).permute(0, 2, 1, 3) value = value.reshape(B, N, self.num_heads, C // self.num_heads).permute(0, 2, 1, 3) attn = torch.matmul(query, key.transpose(-2, -1)) * self.scale attn = attn.softmax(dim=-1) if use_sigmoid: query2 = query2.reshape(B, N, self.num_heads, C // self.num_heads).permute(0, 2, 1, 3) key2 = key2.reshape(B, N, self.num_heads, C // self.num_heads).permute(0, 2, 1, 3) attn2 = torch.matmul(query2, key2.transpose(-2, -1)) * self.scale attn2 = torch.sum(attn2, dim=-1) attn2 = self.sigmoid(attn2) attn = attn * attn2.unsqueeze(3) x = torch.matmul(attn, value).transpose(1, 2).reshape(B, N, C) return x class Block(nn.Module): def __init__(self, dim, num_heads, mlp_ratio=4., act_layer=nn.GELU, norm_layer=nn.LayerNorm, injection=True): super().__init__() self.injection = injection self.channels = dim self.encode_value = nn.Conv2d(in_channels=dim, out_channels=dim, kernel_size=1, stride=1, padding=0) self.encode_query = nn.Conv2d(in_channels=dim, out_channels=dim, kernel_size=1, stride=1, padding=0) self.encode_key = nn.Conv2d(in_channels=dim, out_channels=dim, kernel_size=1, stride=1, padding=0) if self.injection: self.encode_query2 = nn.Conv2d(in_channels=dim, out_channels=dim, kernel_size=1, stride=1, padding=0) self.encode_key2 = nn.Conv2d(in_channels=dim, out_channels=dim, kernel_size=1, stride=1, padding=0) self.attn = Attention(dim, num_heads=num_heads) self.norm2 = norm_layer(dim) mlp_hidden_dim = int(dim * mlp_ratio) self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer) self.q_embedding = nn.Parameter(torch.randn(1, 256, 32, 32)) self.k_embedding = nn.Parameter(torch.randn(1, 256, 32, 32)) def with_pos_embed(self, tensor, pos): return tensor if pos is None else tensor + pos def forward(self, query, key, query_embed=None, key_embed=None): b, c, h, w = query.shape query_embed = repeat(self.q_embedding, '() n c d -> b n c d', b = b) key_embed = repeat(self.k_embedding, '() n c d -> b n c d', b = b) q_embed = self.with_pos_embed(query, query_embed) k_embed = self.with_pos_embed(key, key_embed) v = self.encode_value(key).view(b, self.channels, -1) v = v.permute(0, 2, 1) q = self.encode_query(q_embed).view(b, self.channels, -1) q = q.permute(0, 2, 1) k = self.encode_key(k_embed).view(b, self.channels, -1) k = k.permute(0, 2, 1) query = query.view(b, self.channels, -1).permute(0, 2, 1) if self.injection: q2 = self.encode_query2(q_embed).view(b, self.channels, -1) q2 = q2.permute(0, 2, 1) k2 = self.encode_key2(k_embed).view(b, self.channels, -1) k2 = k2.permute(0, 2, 1) query = self.attn(query=q, key=k, value=v,query2 = q2, key2 = k2, use_sigmoid=True) else: q2 = None k2 = None query = query + self.attn(query=q, key=k, value=v, query2 = q2, key2 = k2, use_sigmoid=False) query = query + self.mlp(self.norm2(query)) query = query.permute(0, 2, 1).contiguous().view(b, self.channels, h, w) return query ================================================ FILE: common/timer.py ================================================ # -------------------------------------------------------- # Fast R-CNN # Copyright (c) 2015 Microsoft # Licensed under The MIT License [see LICENSE for details] # Written by Ross Girshick # -------------------------------------------------------- import time class Timer(object): """A simple timer.""" def __init__(self): self.total_time = 0. self.calls = 0 self.start_time = 0. self.diff = 0. self.average_time = 0. self.warm_up = 0 def tic(self): # using time.time instead of time.clock because time time.clock # does not normalize for multithreading self.start_time = time.time() def toc(self, average=True): self.diff = time.time() - self.start_time if self.warm_up < 10: self.warm_up += 1 return self.diff else: self.total_time += self.diff self.calls += 1 self.average_time = self.total_time / self.calls if average: return self.average_time else: return self.diff ================================================ FILE: common/utils/__init__.py ================================================ ================================================ FILE: common/utils/camera.py ================================================ # -*- coding: utf-8 -*- # Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is # holder of all proprietary rights on this computer program. # You can only use this computer program if you have closed # a license agreement with MPG or you get the right to use the computer # program from someone who is authorized to grant you that right. # Any use of the computer program without a valid license is prohibited and # liable to prosecution. # # Copyright©2019 Max-Planck-Gesellschaft zur Förderung # der Wissenschaften e.V. (MPG). acting on behalf of its Max Planck Institute # for Intelligent Systems and the Max Planck Institute for Biological # Cybernetics. All rights reserved. # # Contact: ps-license@tuebingen.mpg.de from __future__ import absolute_import from __future__ import print_function from __future__ import division from collections import namedtuple import torch import torch.nn as nn import torch.nn.functional as F PerspParams = namedtuple('ModelOutput', ['rotation', 'translation', 'center', 'focal_length']) def transform_mat(R: torch.tensor, t: torch.tensor) -> torch.Tensor: ''' Creates a batch of transformation matrices Args: - R: Bx3x3 array of a batch of rotation matrices - t: Bx3x1 array of a batch of translation vectors Returns: - T: Bx4x4 Transformation matrix ''' # No padding left or right, only add an extra row return torch.cat([F.pad(R, [0, 0, 0, 1]), F.pad(t, [0, 0, 0, 1], value=1)], dim=2) def create_camera(camera_type='persp', **kwargs): if camera_type.lower() == 'persp': return PerspectiveCamera(**kwargs) else: raise ValueError('Uknown camera type: {}'.format(camera_type)) class PerspectiveCamera(nn.Module): FOCAL_LENGTH = 500 def __init__(self, rotation=None, translation=None, focal_length_x=None, focal_length_y=None, batch_size=1, center=None, dtype=torch.float32, **kwargs): super(PerspectiveCamera, self).__init__() self.name = '' self.batch_size = batch_size self.dtype = dtype # Make a buffer so that PyTorch does not complain when creating # the camera matrix self.register_buffer('zero', torch.zeros([batch_size], dtype=dtype)) if focal_length_x is None or type(focal_length_x) == float: focal_length_x = torch.full( [batch_size], self.FOCAL_LENGTH if focal_length_x is None else focal_length_x, dtype=dtype) if focal_length_y is None or type(focal_length_y) == float: focal_length_y = torch.full( [batch_size], self.FOCAL_LENGTH if focal_length_y is None else focal_length_y, dtype=dtype) self.register_buffer('focal_length_x', focal_length_x) self.register_buffer('focal_length_y', focal_length_y) if center is None: center = torch.zeros([batch_size, 2], dtype=dtype) self.register_buffer('center', center) if rotation is None: rotation = torch.eye( 3, dtype=dtype).unsqueeze(dim=0).repeat(batch_size, 1, 1) rotation = nn.Parameter(rotation, requires_grad=True) self.register_parameter('rotation', rotation) if translation is None: translation = torch.zeros([batch_size, 3], dtype=dtype) translation = nn.Parameter(translation, requires_grad=True) self.register_parameter('translation', translation) def forward(self, points): device = points.device with torch.no_grad(): camera_mat = torch.zeros([self.batch_size, 2, 2], dtype=self.dtype, device=points.device) camera_mat[:, 0, 0] = self.focal_length_x camera_mat[:, 1, 1] = self.focal_length_y camera_transform = transform_mat(self.rotation, self.translation.unsqueeze(dim=-1)) homog_coord = torch.ones(list(points.shape)[:-1] + [1], dtype=points.dtype, device=device) # Convert the points to homogeneous coordinates points_h = torch.cat([points, homog_coord], dim=-1) projected_points = torch.einsum('bki,bji->bjk', [camera_transform, points_h]) img_points = torch.div(projected_points[:, :, :2], projected_points[:, :, 2].unsqueeze(dim=-1)) img_points = torch.einsum('bki,bji->bjk', [camera_mat, img_points]) \ + self.center.unsqueeze(dim=1) return img_points ================================================ FILE: common/utils/dir.py ================================================ import os import sys def make_folder(folder_name): if not os.path.exists(folder_name): os.makedirs(folder_name) def add_pypath(path): if path not in sys.path: sys.path.insert(0, path) ================================================ FILE: common/utils/fitting.py ================================================ import numpy as np import torch import torch.nn as nn def to_tensor(tensor, dtype=torch.float32): if torch.Tensor == type(tensor): return tensor.clone().detach() else: return torch.tensor(tensor, dtype=dtype) def rel_change(prev_val, curr_val): return (prev_val - curr_val) / max([np.abs(prev_val), np.abs(curr_val), 1]) class FittingMonitor(object): def __init__(self, summary_steps=1, visualize=False, maxiters=300, ftol=1e-10, gtol=1e-09, body_color=(1.0, 1.0, 0.9, 1.0), model_type='mano', **kwargs): super(FittingMonitor, self).__init__() self.maxiters = maxiters self.ftol = ftol self.gtol = gtol self.visualize = visualize self.summary_steps = summary_steps self.body_color = body_color self.model_type = model_type def __enter__(self): self.steps = 0 return self def __exit__(self, exception_type, exception_value, traceback): pass def set_colors(self, vertex_color): batch_size = self.colors.shape[0] self.colors = np.tile( np.array(vertex_color).reshape(1, 3), [batch_size, 1]) def run_fitting(self, optimizer, closure, params, **kwargs): ''' Helper function for running an optimization process Parameters ---------- optimizer: torch.optim.Optimizer The PyTorch optimizer object closure: function The function used to calculate the gradients params: list List containing the parameters that will be optimized Returns ------- loss: float The final loss value ''' prev_loss = None for n in range(self.maxiters): loss = optimizer.step(closure) if torch.isnan(loss).sum() > 0: print('NaN loss value, stopping!') break if torch.isinf(loss).sum() > 0: print('Infinite loss value, stopping!') break if n > 0 and prev_loss is not None and self.ftol > 0: loss_rel_change = rel_change(prev_loss, loss.item()) if loss_rel_change <= self.ftol: break if all([torch.abs(var.grad.view(-1).max()).item() < self.gtol for var in params if var.grad is not None]): break prev_loss = loss.item() return prev_loss def create_fitting_closure(self, optimizer, camera=None, joint_cam=None, joint_img=None, hand_translation=None, hand_scale=None, loss=None, joints_conf=None, joint_weights=None, create_graph=False, **kwargs): def fitting_func(backward=True): if backward: optimizer.zero_grad() total_loss = loss(camera=camera, joint_cam=joint_cam, joint_img=joint_img, hand_translation=hand_translation, hand_scale =hand_scale, **kwargs) if backward: total_loss.backward(create_graph=create_graph) self.steps += 1 return total_loss return fitting_func class ScaleTranslationLoss(nn.Module): def __init__(self, init_joints_idxs, trans_estimation=None, reduction='sum', data_weight=1.0, depth_loss_weight=1e3, dtype=torch.float32, **kwargs): super(ScaleTranslationLoss, self).__init__() self.dtype = dtype if trans_estimation is not None: self.register_buffer( 'trans_estimation', to_tensor(trans_estimation, dtype=dtype)) else: self.trans_estimation = trans_estimation self.register_buffer('data_weight', torch.tensor(data_weight, dtype=dtype)) self.register_buffer( 'init_joints_idxs', to_tensor(init_joints_idxs, dtype=torch.long)) self.register_buffer('depth_loss_weight', torch.tensor(depth_loss_weight, dtype=dtype)) def reset_loss_weights(self, loss_weight_dict): for key in loss_weight_dict: if hasattr(self, key): weight_tensor = getattr(self, key) weight_tensor = torch.tensor(loss_weight_dict[key], dtype=weight_tensor.dtype, device=weight_tensor.device) setattr(self, key, weight_tensor) def forward(self, camera, joint_cam, joint_img, hand_translation, hand_scale, **kwargs): projected_joints = camera( hand_scale * joint_cam + hand_translation) joint_error = \ torch.index_select(joint_img, 1, self.init_joints_idxs) - \ torch.index_select(projected_joints, 1, self.init_joints_idxs) joint_loss = torch.sum(joint_error.abs()) * self.data_weight ** 2 depth_loss = 0.0 if (self.depth_loss_weight.item() > 0 and self.trans_estimation is not None): depth_loss = self.depth_loss_weight * torch.sum(( hand_translation[2] - self.trans_estimation[2]).abs() ** 2) return joint_loss + depth_loss ================================================ FILE: common/utils/mano.py ================================================ import numpy as np import torch import os.path as osp import json from config import cfg import sys sys.path.insert(0, cfg.mano_path) import manopth from manopth.manolayer import ManoLayer class MANO(object): def __init__(self): # TEMP self.left_layer = ManoLayer(mano_root=osp.join(cfg.mano_path, 'mano', 'models'), flat_hand_mean=False, use_pca=False, side='left') # load right hand MANO model self.layer = self.get_layer() self.vertex_num = 778 self.face = self.layer.th_faces.numpy() self.joint_regressor = self.layer.th_J_regressor.numpy() self.joint_num = 21 self.joints_name = ('Wrist', 'Thumb_1', 'Thumb_2', 'Thumb_3', 'Thumb_4', 'Index_1', 'Index_2', 'Index_3', 'Index_4', 'Middle_1', 'Middle_2', 'Middle_3', 'Middle_4', 'Ring_1', 'Ring_2', 'Ring_3', 'Ring_4', 'Pinky_1', 'Pinky_2', 'Pinky_3', 'Pinly_4') self.skeleton = ( (0,1), (0,5), (0,9), (0,13), (0,17), (1,2), (2,3), (3,4), (5,6), (6,7), (7,8), (9,10), (10,11), (11,12), (13,14), (14,15), (15,16), (17,18), (18,19), (19,20) ) self.root_joint_idx = self.joints_name.index('Wrist') # add fingertips to joint_regressor self.fingertip_vertex_idx = [728, 353, 442, 576, 694] # mesh vertex idx thumbtip_onehot = np.array([1 if i == 728 else 0 for i in range(self.joint_regressor.shape[1])], dtype=np.float32).reshape(1,-1) indextip_onehot = np.array([1 if i == 353 else 0 for i in range(self.joint_regressor.shape[1])], dtype=np.float32).reshape(1,-1) middletip_onehot = np.array([1 if i == 442 else 0 for i in range(self.joint_regressor.shape[1])], dtype=np.float32).reshape(1,-1) ringtip_onehot = np.array([1 if i == 576 else 0 for i in range(self.joint_regressor.shape[1])], dtype=np.float32).reshape(1,-1) pinkytip_onehot = np.array([1 if i == 694 else 0 for i in range(self.joint_regressor.shape[1])], dtype=np.float32).reshape(1,-1) self.joint_regressor = np.concatenate((self.joint_regressor, thumbtip_onehot, indextip_onehot, middletip_onehot, ringtip_onehot, pinkytip_onehot)) self.joint_regressor = self.joint_regressor[[0, 13, 14, 15, 16, 1, 2, 3, 17, 4, 5, 6, 18, 10, 11, 12, 19, 7, 8, 9, 20],:] def get_layer(self): return ManoLayer(mano_root=osp.join(cfg.mano_path, 'mano', 'models'), flat_hand_mean=False, use_pca=False, side='right') # load right hand MANO model ================================================ FILE: common/utils/manopth/.gitignore ================================================ *.sw* *.bak *_bak.py .cache/ __pycache__/ build/ dist/ manopth_hassony2.egg-info/ mano/models assets/mano_layer.svg ================================================ FILE: common/utils/manopth/LICENSE ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: common/utils/manopth/README.md ================================================ Manopth ======= [MANO](http://mano.is.tue.mpg.de) layer for [PyTorch](https://pytorch.org/) (tested with v0.4 and v1.x) ManoLayer is a differentiable PyTorch layer that deterministically maps from pose and shape parameters to hand joints and vertices. It can be integrated into any architecture as a differentiable layer to predict hand meshes. ![image](assets/mano_layer.png) ManoLayer takes **batched** hand pose and shape vectors and outputs corresponding hand joints and vertices. The code is mostly a PyTorch port of the original [MANO](http://mano.is.tue.mpg.de) model from [chumpy](https://github.com/mattloper/chumpy) to [PyTorch](https://pytorch.org/). It therefore builds directly upon the work of Javier Romero, Dimitrios Tzionas and Michael J. Black. This layer was developped and used for the paper *Learning joint reconstruction of hands and manipulated objects* for CVPR19. See [project page](https://github.com/hassony2/obman) and [demo+training code](https://github.com/hassony2/obman_train). It [reuses](https://github.com/hassony2/manopth/blob/master/manopth/rodrigues_layer.py) [part of the great code](https://github.com/MandyMo/pytorch_HMR/blob/master/src/util.py) from the [Pytorch layer for the SMPL body model](https://github.com/MandyMo/pytorch_HMR/blob/master/README.md) by Zhang Xiong ([MandyMo](https://github.com/MandyMo)) to compute the rotation utilities ! It also includes in `mano/webuser` partial content of files from the original [MANO](http://mano.is.tue.mpg.de) code ([posemapper.py](mano/webuser/posemapper.py), [serialization.py](mano/webuser/serialization.py), [lbs.py](mano/webuser/lbs.py), [verts.py](mano/webuser/verts.py), [smpl_handpca_wrapper_HAND_only.py](mano/webuser/smpl_handpca_wrapper_HAND_only.py)). If you find this code useful for your research, consider citing: - the original [MANO](http://mano.is.tue.mpg.de) publication: ``` @article{MANO:SIGGRAPHASIA:2017, title = {Embodied Hands: Modeling and Capturing Hands and Bodies Together}, author = {Romero, Javier and Tzionas, Dimitrios and Black, Michael J.}, journal = {ACM Transactions on Graphics, (Proc. SIGGRAPH Asia)}, publisher = {ACM}, month = nov, year = {2017}, url = {http://doi.acm.org/10.1145/3130800.3130883}, month_numeric = {11} } ``` - the publication this PyTorch port was developped for: ``` @INPROCEEDINGS{hasson19_obman, title = {Learning joint reconstruction of hands and manipulated objects}, author = {Hasson, Yana and Varol, G{\"u}l and Tzionas, Dimitris and Kalevatykh, Igor and Black, Michael J. and Laptev, Ivan and Schmid, Cordelia}, booktitle = {CVPR}, year = {2019} } ``` The training code associated with this paper, compatible with manopth can be found [here](https://github.com/hassony2/obman_train). The release includes a model trained on a variety of hand datasets. # Installation ## Get code and dependencies - `git clone https://github.com/hassony2/manopth` - `cd manopth` - Install the dependencies listed in [environment.yml](environment.yml) - In an existing conda environment, `conda env update -f environment.yml` - In a new environment, `conda env create -f environment.yml`, will create a conda environment named `manopth` ## Download MANO pickle data-structures - Go to [MANO website](http://mano.is.tue.mpg.de/) - Create an account by clicking *Sign Up* and provide your information - Download Models and Code (the downloaded file should have the format `mano_v*_*.zip`). Note that all code and data from this download falls under the [MANO license](http://mano.is.tue.mpg.de/license). - unzip and copy the `models` folder into the `manopth/mano` folder - Your folder structure should look like this: ``` manopth/ mano/ models/ MANO_LEFT.pkl MANO_RIGHT.pkl ... manopth/ __init__.py ... ``` To check that everything is going well, run `python examples/manopth_mindemo.py`, which should generate from a random hand using the MANO layer ! ## Install `manopth` package To be able to import and use `ManoLayer` in another project, go to your `manopth` folder and run `pip install .` `cd /path/to/other/project` You can now use `from manopth import ManoLayer` in this other project! # Usage ## Minimal usage script See [examples/manopth_mindemo.py](examples/manopth_mindemo.py) Simple forward pass with random pose and shape parameters through MANO layer ```python import torch from manopth.manolayer import ManoLayer from manopth import demo batch_size = 10 # Select number of principal components for pose space ncomps = 6 # Initialize MANO layer mano_layer = ManoLayer(mano_root='mano/models', use_pca=True, ncomps=ncomps) # Generate random shape parameters random_shape = torch.rand(batch_size, 10) # Generate random pose parameters, including 3 values for global axis-angle rotation random_pose = torch.rand(batch_size, ncomps + 3) # Forward pass through MANO layer hand_verts, hand_joints = mano_layer(random_pose, random_shape) demo.display_hand({'verts': hand_verts, 'joints': hand_joints}, mano_faces=mano_layer.th_faces) ``` Result : ![random hand](assets/random_hand.png) ## Demo With more options, forward and backward pass, and a loop for quick profiling, look at [examples/manopth_demo.py](examples/manopth_demo.py). You can run it locally with: `python examples/manopth_demo.py` ================================================ FILE: common/utils/manopth/environment.yml ================================================ name: manopth dependencies: - opencv - python=3.7 - matplotlib - numpy - pytorch - tqdm - git - pip: - git+https://github.com/hassony2/chumpy.git ================================================ FILE: common/utils/manopth/examples/manopth_demo.py ================================================ import argparse from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D import torch from tqdm import tqdm from manopth import argutils from manopth.manolayer import ManoLayer from manopth.demo import display_hand if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--batch_size', default=1, type=int) parser.add_argument('--cuda', action='store_true') parser.add_argument( '--no_display', action='store_true', help="Disable display output of ManoLayer given random inputs") parser.add_argument('--side', default='left', choices=['left', 'right']) parser.add_argument('--random_shape', action='store_true', help="Random hand shape") parser.add_argument('--rand_mag', type=float, default=1, help="Controls pose variability") parser.add_argument( '--flat_hand_mean', action='store_true', help="Use flat hand as mean instead of average hand pose") parser.add_argument( '--iters', type=int, default=1, help= "Use for quick profiling of forward and backward pass accross ManoLayer" ) parser.add_argument('--mano_root', default='mano/models') parser.add_argument('--root_rot_mode', default='axisang', choices=['rot6d', 'axisang']) parser.add_argument('--no_pca', action='store_true', help="Give axis-angle or rotation matrix as inputs instead of PCA coefficients") parser.add_argument('--joint_rot_mode', default='axisang', choices=['rotmat', 'axisang'], help="Joint rotation inputs") parser.add_argument( '--mano_ncomps', default=6, type=int, help="Number of PCA components") args = parser.parse_args() argutils.print_args(args) layer = ManoLayer( flat_hand_mean=args.flat_hand_mean, side=args.side, mano_root=args.mano_root, ncomps=args.mano_ncomps, use_pca=not args.no_pca, root_rot_mode=args.root_rot_mode, joint_rot_mode=args.joint_rot_mode) if args.root_rot_mode == 'axisang': rot = 3 else: rot = 6 print(rot) if args.no_pca: args.mano_ncomps = 45 # Generate random pose coefficients pose_params = args.rand_mag * torch.rand(args.batch_size, args.mano_ncomps + rot) pose_params.requires_grad = True if args.random_shape: shape = torch.rand(args.batch_size, 10) else: shape = torch.zeros(1) # Hack to act like None for PyTorch JIT if args.cuda: pose_params = pose_params.cuda() shape = shape.cuda() layer.cuda() # Loop for forward/backward quick profiling for idx in tqdm(range(args.iters)): # Forward pass verts, Jtr = layer(pose_params, th_betas=shape) # Backward pass loss = torch.norm(verts) loss.backward() if not args.no_display: verts, Jtr = layer(pose_params, th_betas=shape) joints = Jtr.cpu().detach() verts = verts.cpu().detach() # Draw obtained vertices and joints display_hand({ 'verts': verts, 'joints': joints }, mano_faces=layer.th_faces) ================================================ FILE: common/utils/manopth/examples/manopth_mindemo.py ================================================ import torch from manopth.manolayer import ManoLayer from manopth import demo batch_size = 10 # Select number of principal components for pose space ncomps = 6 # Initialize MANO layer mano_layer = ManoLayer( mano_root='mano/models', use_pca=True, ncomps=ncomps, flat_hand_mean=False) # Generate random shape parameters random_shape = torch.rand(batch_size, 10) # Generate random pose parameters, including 3 values for global axis-angle rotation random_pose = torch.rand(batch_size, ncomps + 3) # Forward pass through MANO layer hand_verts, hand_joints = mano_layer(random_pose, random_shape) demo.display_hand({ 'verts': hand_verts, 'joints': hand_joints }, mano_faces=mano_layer.th_faces) ================================================ FILE: common/utils/manopth/mano/__init__.py ================================================ ================================================ FILE: common/utils/manopth/mano/webuser/__init__.py ================================================ ================================================ FILE: common/utils/manopth/mano/webuser/lbs.py ================================================ ''' Copyright 2017 Javier Romero, Dimitrios Tzionas, Michael J Black and the Max Planck Gesellschaft. All rights reserved. This software is provided for research purposes only. By using this software you agree to the terms of the MANO/SMPL+H Model license here http://mano.is.tue.mpg.de/license More information about MANO/SMPL+H is available at http://mano.is.tue.mpg.de. For comments or questions, please email us at: mano@tue.mpg.de About this file: ================ This file defines a wrapper for the loading functions of the MANO model. Modules included: - load_model: loads the MANO model from a given file location (i.e. a .pkl file location), or a dictionary object. ''' from mano.webuser.posemapper import posemap import chumpy import numpy as np def global_rigid_transformation(pose, J, kintree_table, xp): results = {} pose = pose.reshape((-1, 3)) id_to_col = {kintree_table[1, i]: i for i in range(kintree_table.shape[1])} parent = { i: id_to_col[kintree_table[0, i]] for i in range(1, kintree_table.shape[1]) } if xp == chumpy: from mano.webuser.posemapper import Rodrigues rodrigues = lambda x: Rodrigues(x) else: import cv2 rodrigues = lambda x: cv2.Rodrigues(x)[0] with_zeros = lambda x: xp.vstack((x, xp.array([[0.0, 0.0, 0.0, 1.0]]))) results[0] = with_zeros( xp.hstack((rodrigues(pose[0, :]), J[0, :].reshape((3, 1))))) for i in range(1, kintree_table.shape[1]): results[i] = results[parent[i]].dot( with_zeros( xp.hstack((rodrigues(pose[i, :]), ((J[i, :] - J[parent[i], :] ).reshape((3, 1))))))) pack = lambda x: xp.hstack([np.zeros((4, 3)), x.reshape((4, 1))]) results = [results[i] for i in sorted(results.keys())] results_global = results if True: results2 = [ results[i] - (pack(results[i].dot(xp.concatenate(((J[i, :]), 0))))) for i in range(len(results)) ] results = results2 result = xp.dstack(results) return result, results_global def verts_core(pose, v, J, weights, kintree_table, want_Jtr=False, xp=chumpy): A, A_global = global_rigid_transformation(pose, J, kintree_table, xp) T = A.dot(weights.T) rest_shape_h = xp.vstack((v.T, np.ones((1, v.shape[0])))) v = (T[:, 0, :] * rest_shape_h[0, :].reshape( (1, -1)) + T[:, 1, :] * rest_shape_h[1, :].reshape( (1, -1)) + T[:, 2, :] * rest_shape_h[2, :].reshape( (1, -1)) + T[:, 3, :] * rest_shape_h[3, :].reshape((1, -1))).T v = v[:, :3] if not want_Jtr: return v Jtr = xp.vstack([g[:3, 3] for g in A_global]) return (v, Jtr) ================================================ FILE: common/utils/manopth/mano/webuser/posemapper.py ================================================ ''' Copyright 2017 Javier Romero, Dimitrios Tzionas, Michael J Black and the Max Planck Gesellschaft. All rights reserved. This software is provided for research purposes only. By using this software you agree to the terms of the MANO/SMPL+H Model license here http://mano.is.tue.mpg.de/license More information about MANO/SMPL+H is available at http://mano.is.tue.mpg.de. For comments or questions, please email us at: mano@tue.mpg.de About this file: ================ This file defines a wrapper for the loading functions of the MANO model. Modules included: - load_model: loads the MANO model from a given file location (i.e. a .pkl file location), or a dictionary object. ''' import chumpy as ch import numpy as np import cv2 class Rodrigues(ch.Ch): dterms = 'rt' def compute_r(self): return cv2.Rodrigues(self.rt.r)[0] def compute_dr_wrt(self, wrt): if wrt is self.rt: return cv2.Rodrigues(self.rt.r)[1].T def lrotmin(p): if isinstance(p, np.ndarray): p = p.ravel()[3:] return np.concatenate( [(cv2.Rodrigues(np.array(pp))[0] - np.eye(3)).ravel() for pp in p.reshape((-1, 3))]).ravel() if p.ndim != 2 or p.shape[1] != 3: p = p.reshape((-1, 3)) p = p[1:] return ch.concatenate([(Rodrigues(pp) - ch.eye(3)).ravel() for pp in p]).ravel() def posemap(s): if s == 'lrotmin': return lrotmin else: raise Exception('Unknown posemapping: %s' % (str(s), )) ================================================ FILE: common/utils/manopth/mano/webuser/serialization.py ================================================ ''' Copyright 2017 Javier Romero, Dimitrios Tzionas, Michael J Black and the Max Planck Gesellschaft. All rights reserved. This software is provided for research purposes only. By using this software you agree to the terms of the MANO/SMPL+H Model license here http://mano.is.tue.mpg.de/license More information about MANO/SMPL+H is available at http://mano.is.tue.mpg.de. For comments or questions, please email us at: mano@tue.mpg.de About this file: ================ This file defines a wrapper for the loading functions of the MANO model. Modules included: - load_model: loads the MANO model from a given file location (i.e. a .pkl file location), or a dictionary object. ''' __all__ = ['load_model', 'save_model'] import numpy as np import pickle import chumpy as ch from chumpy.ch import MatVecMult from mano.webuser.posemapper import posemap from mano.webuser.verts import verts_core def ready_arguments(fname_or_dict): if not isinstance(fname_or_dict, dict): dd = pickle.load(open(fname_or_dict, 'rb'), encoding='latin1') else: dd = fname_or_dict backwards_compatibility_replacements(dd) want_shapemodel = 'shapedirs' in dd nposeparms = dd['kintree_table'].shape[1] * 3 if 'trans' not in dd: dd['trans'] = np.zeros(3) if 'pose' not in dd: dd['pose'] = np.zeros(nposeparms) if 'shapedirs' in dd and 'betas' not in dd: dd['betas'] = np.zeros(dd['shapedirs'].shape[-1]) for s in [ 'v_template', 'weights', 'posedirs', 'pose', 'trans', 'shapedirs', 'betas', 'J' ]: if (s in dd) and not hasattr(dd[s], 'dterms'): dd[s] = ch.array(dd[s]) if want_shapemodel: dd['v_shaped'] = dd['shapedirs'].dot(dd['betas']) + dd['v_template'] v_shaped = dd['v_shaped'] J_tmpx = MatVecMult(dd['J_regressor'], v_shaped[:, 0]) J_tmpy = MatVecMult(dd['J_regressor'], v_shaped[:, 1]) J_tmpz = MatVecMult(dd['J_regressor'], v_shaped[:, 2]) dd['J'] = ch.vstack((J_tmpx, J_tmpy, J_tmpz)).T dd['v_posed'] = v_shaped + dd['posedirs'].dot( posemap(dd['bs_type'])(dd['pose'])) else: dd['v_posed'] = dd['v_template'] + dd['posedirs'].dot( posemap(dd['bs_type'])(dd['pose'])) return dd def load_model(fname_or_dict): dd = ready_arguments(fname_or_dict) args = { 'pose': dd['pose'], 'v': dd['v_posed'], 'J': dd['J'], 'weights': dd['weights'], 'kintree_table': dd['kintree_table'], 'xp': ch, 'want_Jtr': True, 'bs_style': dd['bs_style'] } result, Jtr = verts_core(**args) result = result + dd['trans'].reshape((1, 3)) result.J_transformed = Jtr + dd['trans'].reshape((1, 3)) for k, v in dd.items(): setattr(result, k, v) return result ================================================ FILE: common/utils/manopth/mano/webuser/smpl_handpca_wrapper_HAND_only.py ================================================ ''' Copyright 2017 Javier Romero, Dimitrios Tzionas, Michael J Black and the Max Planck Gesellschaft. All rights reserved. This software is provided for research purposes only. By using this software you agree to the terms of the MANO/SMPL+H Model license here http://mano.is.tue.mpg.de/license More information about MANO/SMPL+H is available at http://mano.is.tue.mpg.de. For comments or questions, please email us at: mano@tue.mpg.de About this file: ================ This file defines a wrapper for the loading functions of the MANO model. Modules included: - load_model: loads the MANO model from a given file location (i.e. a .pkl file location), or a dictionary object. ''' def ready_arguments(fname_or_dict, posekey4vposed='pose'): import numpy as np import pickle import chumpy as ch from chumpy.ch import MatVecMult from mano.webuser.posemapper import posemap if not isinstance(fname_or_dict, dict): dd = pickle.load(open(fname_or_dict, 'rb'), encoding='latin1') # dd = pickle.load(open(fname_or_dict, 'rb')) else: dd = fname_or_dict want_shapemodel = 'shapedirs' in dd nposeparms = dd['kintree_table'].shape[1] * 3 if 'trans' not in dd: dd['trans'] = np.zeros(3) if 'pose' not in dd: dd['pose'] = np.zeros(nposeparms) if 'shapedirs' in dd and 'betas' not in dd: dd['betas'] = np.zeros(dd['shapedirs'].shape[-1]) for s in [ 'v_template', 'weights', 'posedirs', 'pose', 'trans', 'shapedirs', 'betas', 'J' ]: if (s in dd) and not hasattr(dd[s], 'dterms'): dd[s] = ch.array(dd[s]) assert (posekey4vposed in dd) if want_shapemodel: dd['v_shaped'] = dd['shapedirs'].dot(dd['betas']) + dd['v_template'] v_shaped = dd['v_shaped'] J_tmpx = MatVecMult(dd['J_regressor'], v_shaped[:, 0]) J_tmpy = MatVecMult(dd['J_regressor'], v_shaped[:, 1]) J_tmpz = MatVecMult(dd['J_regressor'], v_shaped[:, 2]) dd['J'] = ch.vstack((J_tmpx, J_tmpy, J_tmpz)).T pose_map_res = posemap(dd['bs_type'])(dd[posekey4vposed]) dd['v_posed'] = v_shaped + dd['posedirs'].dot(pose_map_res) else: pose_map_res = posemap(dd['bs_type'])(dd[posekey4vposed]) dd_add = dd['posedirs'].dot(pose_map_res) dd['v_posed'] = dd['v_template'] + dd_add return dd def load_model(fname_or_dict, ncomps=6, flat_hand_mean=False, v_template=None): ''' This model loads the fully articulable HAND SMPL model, and replaces the pose DOFS by ncomps from PCA''' from mano.webuser.verts import verts_core import numpy as np import chumpy as ch import pickle import scipy.sparse as sp np.random.seed(1) if not isinstance(fname_or_dict, dict): smpl_data = pickle.load(open(fname_or_dict, 'rb'), encoding='latin1') # smpl_data = pickle.load(open(fname_or_dict, 'rb')) else: smpl_data = fname_or_dict rot = 3 # for global orientation!!! hands_components = smpl_data['hands_components'] hands_mean = np.zeros(hands_components.shape[ 1]) if flat_hand_mean else smpl_data['hands_mean'] hands_coeffs = smpl_data['hands_coeffs'][:, :ncomps] selected_components = np.vstack((hands_components[:ncomps])) hands_mean = hands_mean.copy() pose_coeffs = ch.zeros(rot + selected_components.shape[0]) full_hand_pose = pose_coeffs[rot:(rot + ncomps)].dot(selected_components) smpl_data['fullpose'] = ch.concatenate((pose_coeffs[:rot], hands_mean + full_hand_pose)) smpl_data['pose'] = pose_coeffs Jreg = smpl_data['J_regressor'] if not sp.issparse(Jreg): smpl_data['J_regressor'] = (sp.csc_matrix( (Jreg.data, (Jreg.row, Jreg.col)), shape=Jreg.shape)) # slightly modify ready_arguments to make sure that it uses the fullpose # (which will NOT be pose) for the computation of posedirs dd = ready_arguments(smpl_data, posekey4vposed='fullpose') # create the smpl formula with the fullpose, # but expose the PCA coefficients as smpl.pose for compatibility args = { 'pose': dd['fullpose'], 'v': dd['v_posed'], 'J': dd['J'], 'weights': dd['weights'], 'kintree_table': dd['kintree_table'], 'xp': ch, 'want_Jtr': True, 'bs_style': dd['bs_style'], } result_previous, meta = verts_core(**args) result = result_previous + dd['trans'].reshape((1, 3)) result.no_translation = result_previous if meta is not None: for field in ['Jtr', 'A', 'A_global', 'A_weighted']: if (hasattr(meta, field)): setattr(result, field, getattr(meta, field)) setattr(result, 'Jtr', meta) if hasattr(result, 'Jtr'): result.J_transformed = result.Jtr + dd['trans'].reshape((1, 3)) for k, v in dd.items(): setattr(result, k, v) if v_template is not None: result.v_template[:] = v_template return result if __name__ == '__main__': load_model() ================================================ FILE: common/utils/manopth/mano/webuser/verts.py ================================================ ''' Copyright 2017 Javier Romero, Dimitrios Tzionas, Michael J Black and the Max Planck Gesellschaft. All rights reserved. This software is provided for research purposes only. By using this software you agree to the terms of the MANO/SMPL+H Model license here http://mano.is.tue.mpg.de/license More information about MANO/SMPL+H is available at http://mano.is.tue.mpg.de. For comments or questions, please email us at: mano@tue.mpg.de About this file: ================ This file defines a wrapper for the loading functions of the MANO model. Modules included: - load_model: loads the MANO model from a given file location (i.e. a .pkl file location), or a dictionary object. ''' import chumpy import mano.webuser.lbs as lbs from mano.webuser.posemapper import posemap import scipy.sparse as sp from chumpy.ch import MatVecMult def ischumpy(x): return hasattr(x, 'dterms') def verts_decorated(trans, pose, v_template, J_regressor, weights, kintree_table, bs_style, f, bs_type=None, posedirs=None, betas=None, shapedirs=None, want_Jtr=False): for which in [ trans, pose, v_template, weights, posedirs, betas, shapedirs ]: if which is not None: assert ischumpy(which) v = v_template if shapedirs is not None: if betas is None: betas = chumpy.zeros(shapedirs.shape[-1]) v_shaped = v + shapedirs.dot(betas) else: v_shaped = v if posedirs is not None: v_posed = v_shaped + posedirs.dot(posemap(bs_type)(pose)) else: v_posed = v_shaped v = v_posed if sp.issparse(J_regressor): J_tmpx = MatVecMult(J_regressor, v_shaped[:, 0]) J_tmpy = MatVecMult(J_regressor, v_shaped[:, 1]) J_tmpz = MatVecMult(J_regressor, v_shaped[:, 2]) J = chumpy.vstack((J_tmpx, J_tmpy, J_tmpz)).T else: assert (ischumpy(J)) assert (bs_style == 'lbs') result, Jtr = lbs.verts_core( pose, v, J, weights, kintree_table, want_Jtr=True, xp=chumpy) tr = trans.reshape((1, 3)) result = result + tr Jtr = Jtr + tr result.trans = trans result.f = f result.pose = pose result.v_template = v_template result.J = J result.J_regressor = J_regressor result.weights = weights result.kintree_table = kintree_table result.bs_style = bs_style result.bs_type = bs_type if posedirs is not None: result.posedirs = posedirs result.v_posed = v_posed if shapedirs is not None: result.shapedirs = shapedirs result.betas = betas result.v_shaped = v_shaped if want_Jtr: result.J_transformed = Jtr return result def verts_core(pose, v, J, weights, kintree_table, bs_style, want_Jtr=False, xp=chumpy): if xp == chumpy: assert (hasattr(pose, 'dterms')) assert (hasattr(v, 'dterms')) assert (hasattr(J, 'dterms')) assert (hasattr(weights, 'dterms')) assert (bs_style == 'lbs') result = lbs.verts_core(pose, v, J, weights, kintree_table, want_Jtr, xp) return result ================================================ FILE: common/utils/manopth/manopth/__init__.py ================================================ name = 'manopth' ================================================ FILE: common/utils/manopth/manopth/argutils.py ================================================ import datetime import os import pickle import subprocess import sys def print_args(args): opts = vars(args) print('======= Options ========') for k, v in sorted(opts.items()): print('{}: {}'.format(k, v)) print('========================') def save_args(args, save_folder, opt_prefix='opt', verbose=True): opts = vars(args) # Create checkpoint folder if not os.path.exists(save_folder): os.makedirs(save_folder, exist_ok=True) # Save options opt_filename = '{}.txt'.format(opt_prefix) opt_path = os.path.join(save_folder, opt_filename) with open(opt_path, 'a') as opt_file: opt_file.write('====== Options ======\n') for k, v in sorted(opts.items()): opt_file.write( '{option}: {value}\n'.format(option=str(k), value=str(v))) opt_file.write('=====================\n') opt_file.write('launched {} at {}\n'.format( str(sys.argv[0]), str(datetime.datetime.now()))) # Add git info label = subprocess.check_output(["git", "describe", "--always"]).strip() if subprocess.call( ["git", "branch"], stderr=subprocess.STDOUT, stdout=open(os.devnull, 'w')) == 0: opt_file.write('=== Git info ====\n') opt_file.write('{}\n'.format(label)) commit = subprocess.check_output(['git', 'rev-parse', 'HEAD']) opt_file.write('commit : {}\n'.format(commit.strip())) opt_picklename = '{}.pkl'.format(opt_prefix) opt_picklepath = os.path.join(save_folder, opt_picklename) with open(opt_picklepath, 'wb') as opt_file: pickle.dump(opts, opt_file) if verbose: print('Saved options to {}'.format(opt_path)) ================================================ FILE: common/utils/manopth/manopth/demo.py ================================================ from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d.art3d import Poly3DCollection import numpy as np import torch from manopth.manolayer import ManoLayer def generate_random_hand(batch_size=1, ncomps=6, mano_root='mano/models'): nfull_comps = ncomps + 3 # Add global orientation dims to PCA random_pcapose = torch.rand(batch_size, nfull_comps) mano_layer = ManoLayer(mano_root=mano_root) verts, joints = mano_layer(random_pcapose) return {'verts': verts, 'joints': joints, 'faces': mano_layer.th_faces} def display_hand(hand_info, mano_faces=None, ax=None, alpha=0.2, batch_idx=0, show=True): """ Displays hand batch_idx in batch of hand_info, hand_info as returned by generate_random_hand """ if ax is None: fig = plt.figure() ax = fig.add_subplot(111, projection='3d') verts, joints = hand_info['verts'][batch_idx], hand_info['joints'][ batch_idx] if mano_faces is None: ax.scatter(verts[:, 0], verts[:, 1], verts[:, 2], alpha=0.1) else: mesh = Poly3DCollection(verts[mano_faces], alpha=alpha) face_color = (141 / 255, 184 / 255, 226 / 255) edge_color = (50 / 255, 50 / 255, 50 / 255) mesh.set_edgecolor(edge_color) mesh.set_facecolor(face_color) ax.add_collection3d(mesh) ax.scatter(joints[:, 0], joints[:, 1], joints[:, 2], color='r') cam_equal_aspect_3d(ax, verts.numpy()) if show: plt.show() def cam_equal_aspect_3d(ax, verts, flip_x=False): """ Centers view on cuboid containing hand and flips y and z axis and fixes azimuth """ extents = np.stack([verts.min(0), verts.max(0)], axis=1) sz = extents[:, 1] - extents[:, 0] centers = np.mean(extents, axis=1) maxsize = max(abs(sz)) r = maxsize / 2 if flip_x: ax.set_xlim(centers[0] + r, centers[0] - r) else: ax.set_xlim(centers[0] - r, centers[0] + r) # Invert y and z axis ax.set_ylim(centers[1] + r, centers[1] - r) ax.set_zlim(centers[2] + r, centers[2] - r) ================================================ FILE: common/utils/manopth/manopth/manolayer.py ================================================ import os import numpy as np import torch from torch.nn import Module from mano.webuser.smpl_handpca_wrapper_HAND_only import ready_arguments from manopth import rodrigues_layer, rotproj, rot6d from manopth.tensutils import (th_posemap_axisang, th_with_zeros, th_pack, subtract_flat_id, make_list) class ManoLayer(Module): __constants__ = [ 'use_pca', 'rot', 'ncomps', 'ncomps', 'kintree_parents', 'check', 'side', 'center_idx', 'joint_rot_mode' ] def __init__(self, center_idx=None, flat_hand_mean=True, ncomps=6, side='right', mano_root='mano/models', use_pca=True, root_rot_mode='axisang', joint_rot_mode='axisang', robust_rot=False): """ Args: center_idx: index of center joint in our computations, if -1 centers on estimate of palm as middle of base of middle finger and wrist flat_hand_mean: if True, (0, 0, 0, ...) pose coefficients match flat hand, else match average hand pose mano_root: path to MANO pkl files for left and right hand ncomps: number of PCA components form pose space (<45) side: 'right' or 'left' use_pca: Use PCA decomposition for pose space. joint_rot_mode: 'axisang' or 'rotmat', ignored if use_pca """ super().__init__() self.center_idx = center_idx self.robust_rot = robust_rot if root_rot_mode == 'axisang': self.rot = 3 else: self.rot = 6 self.flat_hand_mean = flat_hand_mean self.side = side self.use_pca = use_pca self.joint_rot_mode = joint_rot_mode self.root_rot_mode = root_rot_mode if use_pca: self.ncomps = ncomps else: self.ncomps = 45 if side == 'right': self.mano_path = os.path.join(mano_root, 'MANO_RIGHT.pkl') elif side == 'left': self.mano_path = os.path.join(mano_root, 'MANO_LEFT.pkl') smpl_data = ready_arguments(self.mano_path) hands_components = smpl_data['hands_components'] self.smpl_data = smpl_data self.register_buffer('th_betas', torch.Tensor(smpl_data['betas'].r).unsqueeze(0)) self.register_buffer('th_shapedirs', torch.Tensor(smpl_data['shapedirs'].r)) self.register_buffer('th_posedirs', torch.Tensor(smpl_data['posedirs'].r)) self.register_buffer( 'th_v_template', torch.Tensor(smpl_data['v_template'].r).unsqueeze(0)) self.register_buffer( 'th_J_regressor', torch.Tensor(np.array(smpl_data['J_regressor'].toarray()))) self.register_buffer('th_weights', torch.Tensor(smpl_data['weights'].r)) self.register_buffer('th_faces', torch.Tensor(smpl_data['f'].astype(np.int32)).long()) # Get hand mean hands_mean = np.zeros(hands_components.shape[1] ) if flat_hand_mean else smpl_data['hands_mean'] hands_mean = hands_mean.copy() th_hands_mean = torch.Tensor(hands_mean).unsqueeze(0) if self.use_pca or self.joint_rot_mode == 'axisang': # Save as axis-angle self.register_buffer('th_hands_mean', th_hands_mean) selected_components = hands_components[:ncomps] self.register_buffer('th_selected_comps', torch.Tensor(selected_components)) else: th_hands_mean_rotmat = rodrigues_layer.batch_rodrigues( th_hands_mean.view(15, 3)).reshape(15, 3, 3) self.register_buffer('th_hands_mean_rotmat', th_hands_mean_rotmat) # Kinematic chain params self.kintree_table = smpl_data['kintree_table'] parents = list(self.kintree_table[0].tolist()) self.kintree_parents = parents def forward(self, th_pose_coeffs, th_betas=torch.zeros(1), th_trans=torch.zeros(1), root_palm=torch.Tensor([0]), share_betas=torch.Tensor([0]), ): """ Args: th_trans (Tensor (batch_size x ncomps)): if provided, applies trans to joints and vertices th_betas (Tensor (batch_size x 10)): if provided, uses given shape parameters for hand shape else centers on root joint (9th joint) root_palm: return palm as hand root instead of wrist """ # if len(th_pose_coeffs) == 0: # return th_pose_coeffs.new_empty(0), th_pose_coeffs.new_empty(0) batch_size = th_pose_coeffs.shape[0] # Get axis angle from PCA components and coefficients if self.use_pca or self.joint_rot_mode == 'axisang': # Remove global rot coeffs th_hand_pose_coeffs = th_pose_coeffs[:, self.rot:self.rot + self.ncomps] if self.use_pca: # PCA components --> axis angles th_full_hand_pose = th_hand_pose_coeffs.mm(self.th_selected_comps) else: th_full_hand_pose = th_hand_pose_coeffs # Concatenate back global rot th_full_pose = torch.cat([ th_pose_coeffs[:, :self.rot], self.th_hands_mean + th_full_hand_pose ], 1) if self.root_rot_mode == 'axisang': # compute rotation matrixes from axis-angle while skipping global rotation th_pose_map, th_rot_map = th_posemap_axisang(th_full_pose) root_rot = th_rot_map[:, :9].view(batch_size, 3, 3) th_rot_map = th_rot_map[:, 9:] th_pose_map = th_pose_map[:, 9:] else: # th_posemap offsets by 3, so add offset or 3 to get to self.rot=6 th_pose_map, th_rot_map = th_posemap_axisang(th_full_pose[:, 6:]) if self.robust_rot: root_rot = rot6d.robust_compute_rotation_matrix_from_ortho6d(th_full_pose[:, :6]) else: root_rot = rot6d.compute_rotation_matrix_from_ortho6d(th_full_pose[:, :6]) else: assert th_pose_coeffs.dim() == 4, ( 'When not self.use_pca, ' 'th_pose_coeffs should have 4 dims, got {}'.format( th_pose_coeffs.dim())) assert th_pose_coeffs.shape[2:4] == (3, 3), ( 'When not self.use_pca, th_pose_coeffs have 3x3 matrix for two' 'last dims, got {}'.format(th_pose_coeffs.shape[2:4])) th_pose_rots = rotproj.batch_rotprojs(th_pose_coeffs) th_rot_map = th_pose_rots[:, 1:].view(batch_size, -1) th_pose_map = subtract_flat_id(th_rot_map) root_rot = th_pose_rots[:, 0] # Full axis angle representation with root joint if th_betas is None or th_betas.numel() == 1: th_v_shaped = torch.matmul(self.th_shapedirs, self.th_betas.transpose(1, 0)).permute( 2, 0, 1) + self.th_v_template th_j = torch.matmul(self.th_J_regressor, th_v_shaped).repeat( batch_size, 1, 1) else: if share_betas: th_betas = th_betas.mean(0, keepdim=True).expand(th_betas.shape[0], 10) th_v_shaped = torch.matmul(self.th_shapedirs, th_betas.transpose(1, 0)).permute( 2, 0, 1) + self.th_v_template th_j = torch.matmul(self.th_J_regressor, th_v_shaped) # th_pose_map should have shape 20x135 th_v_posed = th_v_shaped + torch.matmul( self.th_posedirs, th_pose_map.transpose(0, 1)).permute(2, 0, 1) # Final T pose with transformation done ! # Global rigid transformation root_j = th_j[:, 0, :].contiguous().view(batch_size, 3, 1) root_trans = th_with_zeros(torch.cat([root_rot, root_j], 2)) all_rots = th_rot_map.view(th_rot_map.shape[0], 15, 3, 3) lev1_idxs = [1, 4, 7, 10, 13] lev2_idxs = [2, 5, 8, 11, 14] lev3_idxs = [3, 6, 9, 12, 15] lev1_rots = all_rots[:, [idx - 1 for idx in lev1_idxs]] lev2_rots = all_rots[:, [idx - 1 for idx in lev2_idxs]] lev3_rots = all_rots[:, [idx - 1 for idx in lev3_idxs]] lev1_j = th_j[:, lev1_idxs] lev2_j = th_j[:, lev2_idxs] lev3_j = th_j[:, lev3_idxs] # From base to tips # Get lev1 results all_transforms = [root_trans.unsqueeze(1)] lev1_j_rel = lev1_j - root_j.transpose(1, 2) lev1_rel_transform_flt = th_with_zeros(torch.cat([lev1_rots, lev1_j_rel.unsqueeze(3)], 3).view(-1, 3, 4)) root_trans_flt = root_trans.unsqueeze(1).repeat(1, 5, 1, 1).view(root_trans.shape[0] * 5, 4, 4) lev1_flt = torch.matmul(root_trans_flt, lev1_rel_transform_flt) all_transforms.append(lev1_flt.view(all_rots.shape[0], 5, 4, 4)) # Get lev2 results lev2_j_rel = lev2_j - lev1_j lev2_rel_transform_flt = th_with_zeros(torch.cat([lev2_rots, lev2_j_rel.unsqueeze(3)], 3).view(-1, 3, 4)) lev2_flt = torch.matmul(lev1_flt, lev2_rel_transform_flt) all_transforms.append(lev2_flt.view(all_rots.shape[0], 5, 4, 4)) # Get lev3 results lev3_j_rel = lev3_j - lev2_j lev3_rel_transform_flt = th_with_zeros(torch.cat([lev3_rots, lev3_j_rel.unsqueeze(3)], 3).view(-1, 3, 4)) lev3_flt = torch.matmul(lev2_flt, lev3_rel_transform_flt) all_transforms.append(lev3_flt.view(all_rots.shape[0], 5, 4, 4)) reorder_idxs = [0, 1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 5, 10, 15] th_results = torch.cat(all_transforms, 1)[:, reorder_idxs] th_results_global = th_results joint_js = torch.cat([th_j, th_j.new_zeros(th_j.shape[0], 16, 1)], 2) tmp2 = torch.matmul(th_results, joint_js.unsqueeze(3)) th_results2 = (th_results - torch.cat([tmp2.new_zeros(*tmp2.shape[:2], 4, 3), tmp2], 3)).permute(0, 2, 3, 1) th_T = torch.matmul(th_results2, self.th_weights.transpose(0, 1)) th_rest_shape_h = torch.cat([ th_v_posed.transpose(2, 1), torch.ones((batch_size, 1, th_v_posed.shape[1]), dtype=th_T.dtype, device=th_T.device), ], 1) th_verts = (th_T * th_rest_shape_h.unsqueeze(1)).sum(2).transpose(2, 1) th_verts = th_verts[:, :, :3] th_jtr = th_results_global[:, :, :3, 3] # In addition to MANO reference joints we sample vertices on each finger # to serve as finger tips if self.side == 'right': tips = th_verts[:, [745, 317, 444, 556, 673]] else: tips = th_verts[:, [745, 317, 445, 556, 673]] if bool(root_palm): palm = (th_verts[:, 95] + th_verts[:, 22]).unsqueeze(1) / 2 th_jtr = torch.cat([palm, th_jtr[:, 1:]], 1) th_jtr = torch.cat([th_jtr, tips], 1) # Reorder joints to match visualization utilities th_jtr = th_jtr[:, [0, 13, 14, 15, 16, 1, 2, 3, 17, 4, 5, 6, 18, 10, 11, 12, 19, 7, 8, 9, 20]] if th_trans is None or bool(torch.norm(th_trans) == 0): if self.center_idx is not None: center_joint = th_jtr[:, self.center_idx].unsqueeze(1) th_jtr = th_jtr - center_joint th_verts = th_verts - center_joint else: th_jtr = th_jtr + th_trans.unsqueeze(1) th_verts = th_verts + th_trans.unsqueeze(1) # Scale to milimeters th_verts = th_verts * 1000 th_jtr = th_jtr * 1000 return th_verts, th_jtr, th_results_global ================================================ FILE: common/utils/manopth/manopth/rodrigues_layer.py ================================================ """ This part reuses code from https://github.com/MandyMo/pytorch_HMR/blob/master/src/util.py which is part of a PyTorch port of SMPL. Thanks to Zhang Xiong (MandyMo) for making this great code available on github ! """ import argparse from torch.autograd import gradcheck import torch from torch.autograd import Variable from manopth import argutils def quat2mat(quat): """Convert quaternion coefficients to rotation matrix. Args: quat: size = [batch_size, 4] 4 <===>(w, x, y, z) Returns: Rotation matrix corresponding to the quaternion -- size = [batch_size, 3, 3] """ norm_quat = quat norm_quat = norm_quat / norm_quat.norm(p=2, dim=1, keepdim=True) w, x, y, z = norm_quat[:, 0], norm_quat[:, 1], norm_quat[:, 2], norm_quat[:, 3] batch_size = quat.size(0) w2, x2, y2, z2 = w.pow(2), x.pow(2), y.pow(2), z.pow(2) wx, wy, wz = w * x, w * y, w * z xy, xz, yz = x * y, x * z, y * z rotMat = torch.stack([ w2 + x2 - y2 - z2, 2 * xy - 2 * wz, 2 * wy + 2 * xz, 2 * wz + 2 * xy, w2 - x2 + y2 - z2, 2 * yz - 2 * wx, 2 * xz - 2 * wy, 2 * wx + 2 * yz, w2 - x2 - y2 + z2 ], dim=1).view(batch_size, 3, 3) return rotMat def batch_rodrigues(axisang): #axisang N x 3 axisang_norm = torch.norm(axisang + 1e-8, p=2, dim=1) angle = torch.unsqueeze(axisang_norm, -1) axisang_normalized = torch.div(axisang, angle) angle = angle * 0.5 v_cos = torch.cos(angle) v_sin = torch.sin(angle) quat = torch.cat([v_cos, v_sin * axisang_normalized], dim=1) rot_mat = quat2mat(quat) rot_mat = rot_mat.view(rot_mat.shape[0], 9) return rot_mat def th_get_axis_angle(vector): angle = torch.norm(vector, 2, 1) axes = vector / angle.unsqueeze(1) return axes, angle if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--batch_size', default=1, type=int) parser.add_argument('--cuda', action='store_true') args = parser.parse_args() argutils.print_args(args) n_components = 6 rot = 3 inputs = torch.rand(args.batch_size, rot) inputs_var = Variable(inputs.double(), requires_grad=True) if args.cuda: inputs = inputs.cuda() # outputs = batch_rodrigues(inputs) test_function = gradcheck(batch_rodrigues, (inputs_var, )) print('batch test passed !') inputs = torch.rand(rot) inputs_var = Variable(inputs.double(), requires_grad=True) test_function = gradcheck(th_cv2_rod_sub_id.apply, (inputs_var, )) print('th_cv2_rod test passed') inputs = torch.rand(rot) inputs_var = Variable(inputs.double(), requires_grad=True) test_th = gradcheck(th_cv2_rod.apply, (inputs_var, )) print('th_cv2_rod_id test passed !') ================================================ FILE: common/utils/manopth/manopth/rot6d.py ================================================ import torch def compute_rotation_matrix_from_ortho6d(poses): """ Code from https://github.com/papagina/RotationContinuity On the Continuity of Rotation Representations in Neural Networks Zhou et al. CVPR19 https://zhouyisjtu.github.io/project_rotation/rotation.html """ x_raw = poses[:, 0:3] # batch*3 y_raw = poses[:, 3:6] # batch*3 x = normalize_vector(x_raw) # batch*3 z = cross_product(x, y_raw) # batch*3 z = normalize_vector(z) # batch*3 y = cross_product(z, x) # batch*3 x = x.view(-1, 3, 1) y = y.view(-1, 3, 1) z = z.view(-1, 3, 1) matrix = torch.cat((x, y, z), 2) # batch*3*3 return matrix def robust_compute_rotation_matrix_from_ortho6d(poses): """ Instead of making 2nd vector orthogonal to first create a base that takes into account the two predicted directions equally """ x_raw = poses[:, 0:3] # batch*3 y_raw = poses[:, 3:6] # batch*3 x = normalize_vector(x_raw) # batch*3 y = normalize_vector(y_raw) # batch*3 middle = normalize_vector(x + y) orthmid = normalize_vector(x - y) x = normalize_vector(middle + orthmid) y = normalize_vector(middle - orthmid) # Their scalar product should be small ! # assert torch.einsum("ij,ij->i", [x, y]).abs().max() < 0.00001 z = normalize_vector(cross_product(x, y)) x = x.view(-1, 3, 1) y = y.view(-1, 3, 1) z = z.view(-1, 3, 1) matrix = torch.cat((x, y, z), 2) # batch*3*3 # Check for reflection in matrix ! If found, flip last vector TODO assert (torch.stack([torch.det(mat) for mat in matrix ])< 0).sum() == 0 return matrix def normalize_vector(v): batch = v.shape[0] v_mag = torch.sqrt(v.pow(2).sum(1)) # batch v_mag = torch.max(v_mag, v.new([1e-8])) v_mag = v_mag.view(batch, 1).expand(batch, v.shape[1]) v = v/v_mag return v def cross_product(u, v): batch = u.shape[0] i = u[:, 1] * v[:, 2] - u[:, 2] * v[:, 1] j = u[:, 2] * v[:, 0] - u[:, 0] * v[:, 2] k = u[:, 0] * v[:, 1] - u[:, 1] * v[:, 0] out = torch.cat((i.view(batch, 1), j.view(batch, 1), k.view(batch, 1)), 1) return out ================================================ FILE: common/utils/manopth/manopth/rotproj.py ================================================ import torch def batch_rotprojs(batches_rotmats): proj_rotmats = [] for batch_idx, batch_rotmats in enumerate(batches_rotmats): proj_batch_rotmats = [] for rot_idx, rotmat in enumerate(batch_rotmats): # GPU implementation of svd is VERY slow # ~ 2 10^-3 per hit vs 5 10^-5 on cpu U, S, V = rotmat.cpu().svd() rotmat = torch.matmul(U, V.transpose(0, 1)) orth_det = rotmat.det() # Remove reflection if orth_det < 0: rotmat[:, 2] = -1 * rotmat[:, 2] rotmat = rotmat.cuda() proj_batch_rotmats.append(rotmat) proj_rotmats.append(torch.stack(proj_batch_rotmats)) return torch.stack(proj_rotmats) ================================================ FILE: common/utils/manopth/manopth/tensutils.py ================================================ import torch from manopth import rodrigues_layer def th_posemap_axisang(pose_vectors): rot_nb = int(pose_vectors.shape[1] / 3) pose_vec_reshaped = pose_vectors.contiguous().view(-1, 3) rot_mats = rodrigues_layer.batch_rodrigues(pose_vec_reshaped) rot_mats = rot_mats.view(pose_vectors.shape[0], rot_nb * 9) pose_maps = subtract_flat_id(rot_mats) return pose_maps, rot_mats def th_with_zeros(tensor): batch_size = tensor.shape[0] padding = tensor.new([0.0, 0.0, 0.0, 1.0]) padding.requires_grad = False concat_list = [tensor, padding.view(1, 1, 4).repeat(batch_size, 1, 1)] cat_res = torch.cat(concat_list, 1) return cat_res def th_pack(tensor): batch_size = tensor.shape[0] padding = tensor.new_zeros((batch_size, 4, 3)) padding.requires_grad = False pack_list = [padding, tensor] pack_res = torch.cat(pack_list, 2) return pack_res def subtract_flat_id(rot_mats): # Subtracts identity as a flattened tensor rot_nb = int(rot_mats.shape[1] / 9) id_flat = torch.eye( 3, dtype=rot_mats.dtype, device=rot_mats.device).view(1, 9).repeat( rot_mats.shape[0], rot_nb) # id_flat.requires_grad = False results = rot_mats - id_flat return results def make_list(tensor): # type: (List[int]) -> List[int] return tensor ================================================ FILE: common/utils/manopth/setup.py ================================================ from setuptools import find_packages, setup import warnings DEPENDENCY_PACKAGE_NAMES = ["matplotlib", "torch", "tqdm", "numpy", "cv2", "chumpy"] def check_dependencies(): missing_dependencies = [] for package_name in DEPENDENCY_PACKAGE_NAMES: try: __import__(package_name) except ImportError: missing_dependencies.append(package_name) if missing_dependencies: warnings.warn( 'Missing dependencies: {}. We recommend you follow ' 'the installation instructions at ' 'https://github.com/hassony2/manopth#installation'.format( missing_dependencies)) with open("README.md", "r") as fh: long_description = fh.read() check_dependencies() setup( name="manopth", version="0.0.1", author="Yana Hasson", author_email="yana.hasson.inria@gmail.com", packages=find_packages(exclude=('tests',)), python_requires=">=3.5.0", description="PyTorch mano layer", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/hassony2/manopth", classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: GNU GENERAL PUBLIC LICENSE", "Operating System :: OS Independent", ], ) ================================================ FILE: common/utils/manopth/test/test_demo.py ================================================ import torch from manopth.demo import generate_random_hand def test_generate_random_hand(): batch_size = 3 hand_info = generate_random_hand(batch_size=batch_size, ncomps=6) verts = hand_info['verts'] joints = hand_info['joints'] assert verts.shape == (batch_size, 778, 3) assert joints.shape == (batch_size, 21, 3) ================================================ FILE: common/utils/optimizers/__init__.py ================================================ # -*- coding: utf-8 -*- # Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is # holder of all proprietary rights on this computer program. # You can only use this computer program if you have closed # a license agreement with MPG or you get the right to use the computer # program from someone who is authorized to grant you that right. # Any use of the computer program without a valid license is prohibited and # liable to prosecution. # # Copyright©2019 Max-Planck-Gesellschaft zur Förderung # der Wissenschaften e.V. (MPG). acting on behalf of its Max Planck Institute # for Intelligent Systems and the Max Planck Institute for Biological # Cybernetics. All rights reserved. # # Contact: ps-license@tuebingen.mpg.de ================================================ FILE: common/utils/optimizers/lbfgs_ls.py ================================================ # PyTorch implementation of L-BFGS with Strong Wolfe line search # Will be removed once https://github.com/pytorch/pytorch/pull/8824 # is merged import torch from functools import reduce from torch.optim import Optimizer def _cubic_interpolate(x1, f1, g1, x2, f2, g2, bounds=None): # ported from https://github.com/torch/optim/blob/master/polyinterp.lua # Compute bounds of interpolation area if bounds is not None: xmin_bound, xmax_bound = bounds else: xmin_bound, xmax_bound = (x1, x2) if x1 <= x2 else (x2, x1) # Code for most common case: cubic interpolation of 2 points # w/ function and derivative values for both # Solution in this case (where x2 is the farthest point): # d1 = g1 + g2 - 3*(f1-f2)/(x1-x2); # d2 = sqrt(d1^2 - g1*g2); # min_pos = x2 - (x2 - x1)*((g2 + d2 - d1)/(g2 - g1 + 2*d2)); # t_new = min(max(min_pos,xmin_bound),xmax_bound); d1 = g1 + g2 - 3 * (f1 - f2) / (x1 - x2) d2_square = d1 ** 2 - g1 * g2 if d2_square >= 0: d2 = d2_square.sqrt() if x1 <= x2: min_pos = x2 - (x2 - x1) * ((g2 + d2 - d1) / (g2 - g1 + 2 * d2)) else: min_pos = x1 - (x1 - x2) * ((g1 + d2 - d1) / (g1 - g2 + 2 * d2)) return min(max(min_pos, xmin_bound), xmax_bound) else: return (xmin_bound + xmax_bound) / 2. def _strong_Wolfe(obj_func, x, t, d, f, g, gtd, c1=1e-4, c2=0.9, tolerance_change=1e-9, max_iter=20, max_ls=25): # ported from https://github.com/torch/optim/blob/master/lswolfe.lua d_norm = d.abs().max() g = g.clone() # evaluate objective and gradient using initial step f_new, g_new = obj_func(x, t, d) ls_func_evals = 1 gtd_new = g_new.dot(d) # bracket an interval containing a point satisfying the Wolfe criteria t_prev, f_prev, g_prev, gtd_prev = 0, f, g, gtd done = False ls_iter = 0 while ls_iter < max_ls: # check conditions if f_new > (f + c1 * t * gtd) or (ls_iter > 1 and f_new >= f_prev): bracket = [t_prev, t] bracket_f = [f_prev, f_new] bracket_g = [g_prev, g_new.clone()] bracket_gtd = [gtd_prev, gtd_new] break if abs(gtd_new) <= -c2 * gtd: bracket = [t] bracket_f = [f_new] bracket_g = [g_new] bracket_gtd = [gtd_new] done = True break if gtd_new >= 0: bracket = [t_prev, t] bracket_f = [f_prev, f_new] bracket_g = [g_prev, g_new.clone()] bracket_gtd = [gtd_prev, gtd_new] break # interpolate min_step = t + 0.01 * (t - t_prev) max_step = t * 10 tmp = t t = _cubic_interpolate(t_prev, f_prev, gtd_prev, t, f_new, gtd_new, bounds=(min_step, max_step)) # next step t_prev = tmp f_prev = f_new g_prev = g_new.clone() gtd_prev = gtd_new f_new, g_new = obj_func(x, t, d) ls_func_evals += 1 gtd_new = g_new.dot(d) ls_iter += 1 # reached max number of iterations? if ls_iter == max_ls: bracket = [0, t] bracket_f = [f, f_new] bracket_g = [g, g_new] bracket_gtd = [gtd, gtd_new] # zoom phase: we now have a point satisfying the criteria, or # a bracket around it. We refine the bracket until we find the # exact point satisfying the criteria insuf_progress = False # find high and low points in bracket low_pos, high_pos = (0, 1) if bracket_f[0] <= bracket_f[-1] else (1, 0) while not done and ls_iter < max_iter: # compute new trial value t = _cubic_interpolate(bracket[0], bracket_f[0], bracket_gtd[0], bracket[1], bracket_f[1], bracket_gtd[1]) # test what we are making sufficient progress eps = 0.1 * (max(bracket) - min(bracket)) if min(max(bracket) - t, t - min(bracket)) < eps: # interpolation close to boundary if insuf_progress or t >= max(bracket) or t <= min(bracket): # evaluate at 0.1 away from boundary if abs(t - max(bracket)) < abs(t - min(bracket)): t = max(bracket) - eps else: t = min(bracket) + eps insuf_progress = False else: insuf_progress = True else: insuf_progress = False # Evaluate new point f_new, g_new = obj_func(x, t, d) ls_func_evals += 1 gtd_new = g_new.dot(d) ls_iter += 1 if f_new > (f + c1 * t * gtd) or f_new >= bracket_f[low_pos]: # Armijo condition not satisfied or not lower than lowest point bracket[high_pos] = t bracket_f[high_pos] = f_new bracket_g[high_pos] = g_new.clone() bracket_gtd[high_pos] = gtd_new low_pos, high_pos = (0, 1) if bracket_f[0] <= bracket_f[1] else (1, 0) else: if abs(gtd_new) <= -c2 * gtd: # Wolfe conditions satisfied done = True elif gtd_new * (bracket[high_pos] - bracket[low_pos]) >= 0: # old high becomes new low bracket[high_pos] = bracket[low_pos] bracket_f[high_pos] = bracket_f[low_pos] bracket_g[high_pos] = bracket_g[low_pos] bracket_gtd[high_pos] = bracket_gtd[low_pos] # new point becomes new low bracket[low_pos] = t bracket_f[low_pos] = f_new bracket_g[low_pos] = g_new.clone() bracket_gtd[low_pos] = gtd_new # line-search bracket is so small if abs(bracket[1] - bracket[0]) * d_norm < tolerance_change: break # return stuff t = bracket[low_pos] f_new = bracket_f[low_pos] g_new = bracket_g[low_pos] return f_new, g_new, t, ls_func_evals # LBFGS with strong Wolfe line search introduces in PR #8824 # Will be removed once merged with master class LBFGS(Optimizer): """Implements L-BFGS algorithm, heavily inspired by `minFunc `. .. warning:: This optimizer doesn't support per-parameter options and parameter groups (there can be only one). .. warning:: Right now all parameters have to be on a single device. This will be improved in the future. .. note:: This is a very memory intensive optimizer (it requires additional ``param_bytes * (history_size + 1)`` bytes). If it doesn't fit in memory try reducing the history size, or use a different algorithm. Arguments: lr (float): learning rate (default: 1) max_iter (int): maximal number of iterations per optimization step (default: 20) max_eval (int): maximal number of function evaluations per optimization step (default: max_iter * 1.25). tolerance_grad (float): termination tolerance on first order optimality (default: 1e-5). tolerance_change (float): termination tolerance on function value/parameter changes (default: 1e-9). history_size (int): update history size (default: 100). line_search_fn (str): either 'strong_Wolfe' or None (default: None). """ def __init__(self, params, lr=1, max_iter=20, max_eval=None, tolerance_grad=1e-5, tolerance_change=1e-9, history_size=100, line_search_fn=None): if max_eval is None: max_eval = max_iter * 5 // 4 defaults = dict(lr=lr, max_iter=max_iter, max_eval=max_eval, tolerance_grad=tolerance_grad, tolerance_change=tolerance_change, history_size=history_size, line_search_fn=line_search_fn) super(LBFGS, self).__init__(params, defaults) if len(self.param_groups) != 1: raise ValueError("LBFGS doesn't support per-parameter options " "(parameter groups)") self._params = self.param_groups[0]['params'] self._numel_cache = None def _numel(self): if self._numel_cache is None: self._numel_cache = reduce(lambda total, p: total + p.numel(), self._params, 0) return self._numel_cache def _gather_flat_grad(self): views = [] for p in self._params: if p.grad is None: view = p.new(p.numel()).zero_() elif p.grad.is_sparse: view = p.grad.to_dense().view(-1) else: view = p.grad.view(-1) views.append(view) return torch.cat(views, 0) def _add_grad(self, step_size, update): offset = 0 for p in self._params: numel = p.numel() # view as to avoid deprecated pointwise semantics p.data.add_(step_size, update[offset:offset + numel].view_as(p.data)) offset += numel assert offset == self._numel() def _clone_param(self): return [p.clone() for p in self._params] def _set_param(self, params_data): for p, pdata in zip(self._params, params_data): p.data.copy_(pdata) def _directional_evaluate(self, closure, x, t, d): self._add_grad(t, d) loss = float(closure()) flat_grad = self._gather_flat_grad() self._set_param(x) return loss, flat_grad def step(self, closure): """Performs a single optimization step. Arguments: closure (callable): A closure that reevaluates the model and returns the loss. """ assert len(self.param_groups) == 1 group = self.param_groups[0] lr = group['lr'] max_iter = group['max_iter'] max_eval = group['max_eval'] tolerance_grad = group['tolerance_grad'] tolerance_change = group['tolerance_change'] line_search_fn = group['line_search_fn'] history_size = group['history_size'] # NOTE: LBFGS has only global state, but we register it as state for # the first param, because this helps with casting in load_state_dict state = self.state[self._params[0]] state.setdefault('func_evals', 0) state.setdefault('n_iter', 0) # evaluate initial f(x) and df/dx orig_loss = closure() loss = float(orig_loss) current_evals = 1 state['func_evals'] += 1 flat_grad = self._gather_flat_grad() opt_cond = flat_grad.abs().max() <= tolerance_grad # optimal condition if opt_cond: return orig_loss # tensors cached in state (for tracing) d = state.get('d') t = state.get('t') old_dirs = state.get('old_dirs') old_stps = state.get('old_stps') ro = state.get('ro') H_diag = state.get('H_diag') prev_flat_grad = state.get('prev_flat_grad') prev_loss = state.get('prev_loss') n_iter = 0 # optimize for a max of max_iter iterations while n_iter < max_iter: # keep track of nb of iterations n_iter += 1 state['n_iter'] += 1 ############################################################ # compute gradient descent direction ############################################################ if state['n_iter'] == 1: d = flat_grad.neg() old_dirs = [] old_stps = [] ro = [] H_diag = 1 else: # do lbfgs update (update memory) y = flat_grad.sub(prev_flat_grad) s = d.mul(t) ys = y.dot(s) # y*s if ys > 1e-10: # updating memory if len(old_dirs) == history_size: # shift history by one (limited-memory) old_dirs.pop(0) old_stps.pop(0) ro.pop(0) # store new direction/step old_dirs.append(y) old_stps.append(s) ro.append(1. / ys) # update scale of initial Hessian approximation H_diag = ys / y.dot(y) # (y*y) # compute the approximate (L-BFGS) inverse Hessian # multiplied by the gradient num_old = len(old_dirs) if 'al' not in state: state['al'] = [None] * history_size al = state['al'] # iteration in L-BFGS loop collapsed to use just one buffer q = flat_grad.neg() for i in range(num_old - 1, -1, -1): al[i] = old_stps[i].dot(q) * ro[i] q.add_(-al[i], old_dirs[i]) # multiply by initial Hessian # r/d is the final direction d = r = torch.mul(q, H_diag) for i in range(num_old): be_i = old_dirs[i].dot(r) * ro[i] r.add_(al[i] - be_i, old_stps[i]) if prev_flat_grad is None: prev_flat_grad = flat_grad.clone() else: prev_flat_grad.copy_(flat_grad) prev_loss = loss ############################################################ # compute step length ############################################################ # reset initial guess for step size if state['n_iter'] == 1: t = min(1., 1. / flat_grad.abs().sum()) * lr else: t = lr # directional derivative gtd = flat_grad.dot(d) # g * d # directional derivative is below tolerance if gtd > -tolerance_change: break # optional line search: user function ls_func_evals = 0 if line_search_fn is not None: # perform line search, using user function if line_search_fn != "strong_Wolfe": raise RuntimeError("only 'strong_Wolfe' is supported") else: x_init = self._clone_param() def obj_func(x, t, d): return self._directional_evaluate(closure, x, t, d) loss, flat_grad, t, ls_func_evals = _strong_Wolfe(obj_func, x_init, t, d, loss, flat_grad, gtd, max_iter=max_iter) self._add_grad(t, d) opt_cond = flat_grad.abs().max() <= tolerance_grad else: # no line search, simply move with fixed-step self._add_grad(t, d) if n_iter != max_iter: # re-evaluate function only if not in last iteration # the reason we do this: in a stochastic setting, # no use to re-evaluate that function here loss = float(closure()) flat_grad = self._gather_flat_grad() opt_cond = flat_grad.abs().max() <= tolerance_grad ls_func_evals = 1 # update func eval current_evals += ls_func_evals state['func_evals'] += ls_func_evals ############################################################ # check conditions ############################################################ if n_iter == max_iter: break if current_evals >= max_eval: break # optimal condition if opt_cond: break # lack of progress if d.mul(t).abs().max() <= tolerance_change: break if abs(loss - prev_loss) < tolerance_change: break state['d'] = d state['t'] = t state['old_dirs'] = old_dirs state['old_stps'] = old_stps state['ro'] = ro state['H_diag'] = H_diag state['prev_flat_grad'] = prev_flat_grad state['prev_loss'] = prev_loss return orig_loss ================================================ FILE: common/utils/optimizers/optim_factory.py ================================================ # -*- coding: utf-8 -*- # Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (MPG) is # holder of all proprietary rights on this computer program. # You can only use this computer program if you have closed # a license agreement with MPG or you get the right to use the computer # program from someone who is authorized to grant you that right. # Any use of the computer program without a valid license is prohibited and # liable to prosecution. # # Copyright©2019 Max-Planck-Gesellschaft zur Förderung # der Wissenschaften e.V. (MPG). acting on behalf of its Max Planck Institute # for Intelligent Systems and the Max Planck Institute for Biological # Cybernetics. All rights reserved. # # Contact: ps-license@tuebingen.mpg.de from __future__ import absolute_import from __future__ import print_function from __future__ import division import torch.optim as optim from .lbfgs_ls import LBFGS as LBFGSLs def create_optimizer(parameters, optim_type='lbfgs', lr=1e-3, momentum=0.9, use_nesterov=True, beta1=0.9, beta2=0.999, epsilon=1e-8, use_locking=False, weight_decay=0.0, centered=False, rmsprop_alpha=0.99, maxiters=20, gtol=1e-6, ftol=1e-9, **kwargs): ''' Creates the optimizer ''' if optim_type == 'adam': return (optim.Adam(parameters, lr=lr, betas=(beta1, beta2), weight_decay=weight_decay), False) elif optim_type == 'lbfgs': return (optim.LBFGS(parameters, lr=lr, max_iter=maxiters), False) elif optim_type == 'lbfgsls': return LBFGSLs(parameters, lr=lr, max_iter=maxiters, line_search_fn='strong_Wolfe'), False elif optim_type == 'rmsprop': return (optim.RMSprop(parameters, lr=lr, epsilon=epsilon, alpha=rmsprop_alpha, weight_decay=weight_decay, momentum=momentum, centered=centered), False) elif optim_type == 'sgd': return (optim.SGD(parameters, lr=lr, momentum=momentum, weight_decay=weight_decay, nesterov=use_nesterov), False) else: raise ValueError('Optimizer {} not supported!'.format(optim_type)) ================================================ FILE: common/utils/preprocessing.py ================================================ import numpy as np import cv2 import random from config import cfg import math import torchvision def load_img(path, order='RGB'): img = cv2.imread(path, cv2.IMREAD_COLOR | cv2.IMREAD_IGNORE_ORIENTATION) if not isinstance(img, np.ndarray): raise IOError("Fail to read %s" % path) if order=='RGB': img = img[:,:,::-1].copy() img = img.astype(np.float32) return img def get_bbox(joint_img, joint_valid, expansion_factor=1.0): x_img, y_img = joint_img[:,0], joint_img[:,1] x_img = x_img[joint_valid==1]; y_img = y_img[joint_valid==1]; xmin = min(x_img); ymin = min(y_img); xmax = max(x_img); ymax = max(y_img); x_center = (xmin+xmax)/2.; width = (xmax-xmin)*expansion_factor; xmin = x_center - 0.5*width xmax = x_center + 0.5*width y_center = (ymin+ymax)/2.; height = (ymax-ymin)*expansion_factor; ymin = y_center - 0.5*height ymax = y_center + 0.5*height bbox = np.array([xmin, ymin, xmax - xmin, ymax - ymin]).astype(np.float32) return bbox def process_bbox(bbox, img_width, img_height, expansion_factor=1.25): # sanitize bboxes x, y, w, h = bbox x1 = np.max((0, x)) y1 = np.max((0, y)) x2 = np.min((img_width - 1, x1 + np.max((0, w - 1)))) y2 = np.min((img_height - 1, y1 + np.max((0, h - 1)))) if w*h > 0 and x2 >= x1 and y2 >= y1: bbox = np.array([x1, y1, x2-x1, y2-y1]) else: return None # aspect ratio preserving bbox w = bbox[2] h = bbox[3] c_x = bbox[0] + w/2. c_y = bbox[1] + h/2. aspect_ratio = cfg.input_img_shape[1]/cfg.input_img_shape[0] if w > aspect_ratio * h: h = w / aspect_ratio elif w < aspect_ratio * h: w = h * aspect_ratio bbox[2] = w*expansion_factor bbox[3] = h*expansion_factor bbox[0] = c_x - bbox[2]/2. bbox[1] = c_y - bbox[3]/2. return bbox def get_aug_config(): scale_factor = 0.25 rot_factor = 30 color_factor = 0.2 scale = np.clip(np.random.randn(), -1.0, 1.0) * scale_factor + 1.0 rot = np.clip(np.random.randn(), -2.0, 2.0) * rot_factor if random.random() <= 0.6 else 0 c_up = 1.0 + color_factor c_low = 1.0 - color_factor color_scale = np.array([random.uniform(c_low, c_up), random.uniform(c_low, c_up), random.uniform(c_low, c_up)]) return scale, rot, color_scale def augmentation(img, bbox, data_split, do_flip=False): if data_split == 'train': scale, rot, color_scale = get_aug_config() else: scale, rot, color_scale = 1.0, 0.0, np.array([1,1,1]) img, trans, inv_trans = generate_patch_image(img, bbox, scale, rot, do_flip, cfg.input_img_shape) img = np.clip(img * color_scale[None,None,:], 0, 255) return img, trans, inv_trans, rot, scale def generate_patch_image(cvimg, bbox, scale, rot, do_flip, out_shape): img = cvimg.copy() img_height, img_width, img_channels = img.shape bb_c_x = float(bbox[0] + 0.5*bbox[2]) bb_c_y = float(bbox[1] + 0.5*bbox[3]) bb_width = float(bbox[2]) bb_height = float(bbox[3]) if do_flip: img = img[:, ::-1, :] bb_c_x = img_width - bb_c_x - 1 trans = gen_trans_from_patch_cv(bb_c_x, bb_c_y, bb_width, bb_height, out_shape[1], out_shape[0], scale, rot) img_patch = cv2.warpAffine(img, trans, (int(out_shape[1]), int(out_shape[0])), flags=cv2.INTER_LINEAR) img_patch = img_patch.astype(np.float32) inv_trans = gen_trans_from_patch_cv(bb_c_x, bb_c_y, bb_width, bb_height, out_shape[1], out_shape[0], scale, rot, inv=True) return img_patch, trans, inv_trans def rotate_2d(pt_2d, rot_rad): x = pt_2d[0] y = pt_2d[1] sn, cs = np.sin(rot_rad), np.cos(rot_rad) xx = x * cs - y * sn yy = x * sn + y * cs return np.array([xx, yy], dtype=np.float32) def gen_trans_from_patch_cv(c_x, c_y, src_width, src_height, dst_width, dst_height, scale, rot, inv=False): # augment size with scale src_w = src_width * scale src_h = src_height * scale src_center = np.array([c_x, c_y], dtype=np.float32) # augment rotation rot_rad = np.pi * rot / 180 src_downdir = rotate_2d(np.array([0, src_h * 0.5], dtype=np.float32), rot_rad) src_rightdir = rotate_2d(np.array([src_w * 0.5, 0], dtype=np.float32), rot_rad) dst_w = dst_width dst_h = dst_height dst_center = np.array([dst_w * 0.5, dst_h * 0.5], dtype=np.float32) dst_downdir = np.array([0, dst_h * 0.5], dtype=np.float32) dst_rightdir = np.array([dst_w * 0.5, 0], dtype=np.float32) src = np.zeros((3, 2), dtype=np.float32) src[0, :] = src_center src[1, :] = src_center + src_downdir src[2, :] = src_center + src_rightdir dst = np.zeros((3, 2), dtype=np.float32) dst[0, :] = dst_center dst[1, :] = dst_center + dst_downdir dst[2, :] = dst_center + dst_rightdir if inv: trans = cv2.getAffineTransform(np.float32(dst), np.float32(src)) else: trans = cv2.getAffineTransform(np.float32(src), np.float32(dst)) trans = trans.astype(np.float32) return trans ================================================ FILE: common/utils/transforms.py ================================================ import torch import numpy as np from config import cfg def cam2pixel(cam_coord, f, c): x = cam_coord[:,0] / cam_coord[:,2] * f[0] + c[0] y = cam_coord[:,1] / cam_coord[:,2] * f[1] + c[1] z = cam_coord[:,2] return np.stack((x,y,z),1) def pixel2cam(pixel_coord, f, c): x = (pixel_coord[:,0] - c[0]) / f[0] * pixel_coord[:,2] y = (pixel_coord[:,1] - c[1]) / f[1] * pixel_coord[:,2] z = pixel_coord[:,2] return np.stack((x,y,z),1) def world2cam(world_coord, R, t): cam_coord = np.dot(R, world_coord.transpose(1,0)).transpose(1,0) + t.reshape(1,3) return cam_coord def cam2world(cam_coord, R, t): world_coord = np.dot(np.linalg.inv(R), (cam_coord - t.reshape(1,3)).transpose(1,0)).transpose(1,0) return world_coord def rigid_transform_3D(A, B): n, dim = A.shape centroid_A = np.mean(A, axis = 0) centroid_B = np.mean(B, axis = 0) H = np.dot(np.transpose(A - centroid_A), B - centroid_B) / n U, s, V = np.linalg.svd(H) R = np.dot(np.transpose(V), np.transpose(U)) if np.linalg.det(R) < 0: s[-1] = -s[-1] V[2] = -V[2] R = np.dot(np.transpose(V), np.transpose(U)) varP = np.var(A, axis=0).sum() c = 1/varP * np.sum(s) t = -np.dot(c*R, np.transpose(centroid_A)) + np.transpose(centroid_B) return c, R, t def rigid_align(A, B): c, R, t = rigid_transform_3D(A, B) A2 = np.transpose(np.dot(c*R, np.transpose(A))) + t return A2 def transform_joint_to_other_db(src_joint, src_name, dst_name): src_joint_num = len(src_name) dst_joint_num = len(dst_name) new_joint = np.zeros(((dst_joint_num,) + src_joint.shape[1:]), dtype=np.float32) for src_idx in range(len(src_name)): name = src_name[src_idx] if name in dst_name: dst_idx = dst_name.index(name) new_joint[dst_idx] = src_joint[src_idx] return new_joint ================================================ FILE: common/utils/vis.py ================================================ import os import cv2 import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import matplotlib as mpl os.environ["PYOPENGL_PLATFORM"] = "egl" import pyrender import trimesh def vis_keypoints_with_skeleton(img, kps, kps_lines, kp_thresh=0.4, alpha=1): # Convert from plt 0-1 RGBA colors to 0-255 BGR colors for opencv. cmap = plt.get_cmap('rainbow') colors = [cmap(i) for i in np.linspace(0, 1, len(kps_lines) + 2)] colors = [(c[2] * 255, c[1] * 255, c[0] * 255) for c in colors] # Perform the drawing on a copy of the image, to allow for blending. kp_mask = np.copy(img) # Draw the keypoints. for l in range(len(kps_lines)): i1 = kps_lines[l][0] i2 = kps_lines[l][1] p1 = kps[0, i1].astype(np.int32), kps[1, i1].astype(np.int32) p2 = kps[0, i2].astype(np.int32), kps[1, i2].astype(np.int32) if kps[2, i1] > kp_thresh and kps[2, i2] > kp_thresh: cv2.line( kp_mask, p1, p2, color=colors[l], thickness=2, lineType=cv2.LINE_AA) if kps[2, i1] > kp_thresh: cv2.circle( kp_mask, p1, radius=3, color=colors[l], thickness=-1, lineType=cv2.LINE_AA) if kps[2, i2] > kp_thresh: cv2.circle( kp_mask, p2, radius=3, color=colors[l], thickness=-1, lineType=cv2.LINE_AA) # Blend the keypoints. return cv2.addWeighted(img, 1.0 - alpha, kp_mask, alpha, 0) def vis_keypoints(img, kps, alpha=1): # Convert from plt 0-1 RGBA colors to 0-255 BGR colors for opencv. cmap = plt.get_cmap('rainbow') colors = [cmap(i) for i in np.linspace(0, 1, len(kps) + 2)] colors = [(c[2] * 255, c[1] * 255, c[0] * 255) for c in colors] # Perform the drawing on a copy of the image, to allow for blending. kp_mask = np.copy(img) # Draw the keypoints. for i in range(len(kps)): p = kps[i][0].astype(np.int32), kps[i][1].astype(np.int32) cv2.circle(kp_mask, p, radius=3, color=colors[i], thickness=-1, lineType=cv2.LINE_AA) # Blend the keypoints. return cv2.addWeighted(img, 1.0 - alpha, kp_mask, alpha, 0) def vis_mesh(img, mesh_vertex, alpha=0.5): # Convert from plt 0-1 RGBA colors to 0-255 BGR colors for opencv. cmap = plt.get_cmap('rainbow') colors = [cmap(i) for i in np.linspace(0, 1, len(mesh_vertex))] colors = [(c[2] * 255, c[1] * 255, c[0] * 255) for c in colors] # Perform the drawing on a copy of the image, to allow for blending. mask = np.copy(img) # Draw the mesh for i in range(len(mesh_vertex)): p = mesh_vertex[i][0].astype(np.int32), mesh_vertex[i][1].astype(np.int32) cv2.circle(mask, p, radius=1, color=colors[i], thickness=-1, lineType=cv2.LINE_AA) # Blend the keypoints. return cv2.addWeighted(img, 1.0 - alpha, mask, alpha, 0) def vis_3d_skeleton(kpt_3d, kpt_3d_vis, kps_lines, filename=None): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Convert from plt 0-1 RGBA colors to 0-255 BGR colors for opencv. cmap = plt.get_cmap('rainbow') colors = [cmap(i) for i in np.linspace(0, 1, len(kps_lines) + 2)] colors = [np.array((c[2], c[1], c[0])) for c in colors] for l in range(len(kps_lines)): i1 = kps_lines[l][0] i2 = kps_lines[l][1] x = np.array([kpt_3d[i1,0], kpt_3d[i2,0]]) y = np.array([kpt_3d[i1,1], kpt_3d[i2,1]]) z = np.array([kpt_3d[i1,2], kpt_3d[i2,2]]) if kpt_3d_vis[i1,0] > 0 and kpt_3d_vis[i2,0] > 0: ax.plot(x, z, -y, c=colors[l], linewidth=2) if kpt_3d_vis[i1,0] > 0: ax.scatter(kpt_3d[i1,0], kpt_3d[i1,2], -kpt_3d[i1,1], c=colors[l], marker='o') if kpt_3d_vis[i2,0] > 0: ax.scatter(kpt_3d[i2,0], kpt_3d[i2,2], -kpt_3d[i2,1], c=colors[l], marker='o') if filename is None: ax.set_title('3D vis') else: ax.set_title(filename) ax.set_xlabel('X Label') ax.set_ylabel('Z Label') ax.set_zlabel('Y Label') ax.legend() #plt.show() #cv2.waitKey(0) plt.savefig(filename) def save_obj(v, f, file_name='output.obj'): obj_file = open(file_name, 'w') for i in range(len(v)): obj_file.write('v ' + str(v[i][0]) + ' ' + str(v[i][1]) + ' ' + str(v[i][2]) + '\n') for i in range(len(f)): obj_file.write('f ' + str(f[i][0]+1) + '/' + str(f[i][0]+1) + ' ' + str(f[i][1]+1) + '/' + str(f[i][1]+1) + ' ' + str(f[i][2]+1) + '/' + str(f[i][2]+1) + '\n') obj_file.close() def render_mesh(img, mesh, face, cam_param): # mesh mesh = trimesh.Trimesh(mesh, face) rot = trimesh.transformations.rotation_matrix( np.radians(180), [1, 0, 0]) mesh.apply_transform(rot) material = pyrender.MetallicRoughnessMaterial(metallicFactor=0.0, alphaMode='OPAQUE', baseColorFactor=(1.0, 1.0, 0.9, 1.0)) mesh = pyrender.Mesh.from_trimesh(mesh, material=material, smooth=False) scene = pyrender.Scene(ambient_light=(0.3, 0.3, 0.3)) scene.add(mesh, 'mesh') focal, princpt = cam_param['focal'], cam_param['princpt'] camera = pyrender.IntrinsicsCamera(fx=focal[0], fy=focal[1], cx=princpt[0], cy=princpt[1]) scene.add(camera) # renderer renderer = pyrender.OffscreenRenderer(viewport_width=img.shape[1], viewport_height=img.shape[0], point_size=1.0) # light light = pyrender.DirectionalLight(color=[1.0, 1.0, 1.0], intensity=0.8) light_pose = np.eye(4) light_pose[:3, 3] = np.array([0, -1, 1]) scene.add(light, pose=light_pose) light_pose[:3, 3] = np.array([0, 1, 1]) scene.add(light, pose=light_pose) light_pose[:3, 3] = np.array([1, 1, 2]) scene.add(light, pose=light_pose) # render rgb, depth = renderer.render(scene, flags=pyrender.RenderFlags.RGBA) rgb = rgb[:,:,:3].astype(np.float32) valid_mask = (depth > 0)[:,:,None] # save to image img = rgb * valid_mask*0.5 + img #* (1-valid_mask) return img ================================================ FILE: data/DEX_YCB/DEX_YCB.py ================================================ import os import os.path as osp import numpy as np import torch import cv2 import random import json import math import copy from pycocotools.coco import COCO from config import cfg from utils.preprocessing import load_img, get_bbox, process_bbox, generate_patch_image, augmentation from utils.transforms import world2cam, cam2pixel, pixel2cam, rigid_align, transform_joint_to_other_db from utils.vis import vis_keypoints, vis_mesh, save_obj, vis_keypoints_with_skeleton, render_mesh, vis_3d_skeleton from utils.mano import MANO mano = MANO() # # TEMP; test set # target_img_list = { # 1: ['20200820-subject-03/20200820_135508/836212060125/color_000030.jpg', '20200820-subject-03/20200820_135508/836212060125/color_000060.jpg', '20200903-subject-04/20200903_103828/836212060125/color_000030.jpg', '20200903-subject-04/20200903_103828/836212060125/color_000060.jpg', '20200908-subject-05/20200908_143535/836212060125/color_000060.jpg', '20200908-subject-05/20200908_143535/932122060857/color_000030.jpg', '20200918-subject-06/20200918_113137/836212060125/color_000030.jpg', '20200918-subject-06/20200918_113137/836212060125/color_000060.jpg', # '20200928-subject-07/20200928_143500/836212060125/color_000060.jpg', '20200928-subject-07/20200928_143500/932122060857/color_000030.jpg', '20201002-subject-08/20201002_104827/836212060125/color_000060.jpg', '20201002-subject-08/20201002_104827/932122060861/color_000030.jpg', '20201015-subject-09/20201015_142844/836212060125/color_000030.jpg', '20201015-subject-09/20201015_142844/836212060125/color_000060.jpg', '20201015-subject-09/20201015_142844/841412060263/color_000000.jpg', '20201022-subject-10/20201022_110947/840412060917/color_000060.jpg', '20201022-subject-10/20201022_110947/932122060857/color_000030.jpg'], # 2: ['20200820-subject-03/20200820_135810/836212060125/color_000060.jpg', '20200820-subject-03/20200820_135810/839512060362/color_000030.jpg', '20200903-subject-04/20200903_104115/836212060125/color_000030.jpg', '20200903-subject-04/20200903_104115/839512060362/color_000060.jpg', '20200908-subject-05/20200908_143832/836212060125/color_000030.jpg', '20200908-subject-05/20200908_143832/836212060125/color_000060.jpg', '20200918-subject-06/20200918_113405/839512060362/color_000060.jpg', '20200918-subject-06/20200918_113405/840412060917/color_000030.jpg', '20200928-subject-07/20200928_143727/839512060362/color_000060.jpg', '20200928-subject-07/20200928_143727/840412060917/color_000030.jpg', '20201002-subject-08/20201002_105058/836212060125/color_000060.jpg', '20201002-subject-08/20201002_105058/840412060917/color_000030.jpg', '20201015-subject-09/20201015_143113/836212060125/color_000030.jpg', '20201015-subject-09/20201015_143113/836212060125/color_000060.jpg', '20201015-subject-09/20201015_143113/840412060917/color_000000.jpg', '20201022-subject-10/20201022_111144/840412060917/color_000030.jpg', '20201022-subject-10/20201022_111144/840412060917/color_000060.jpg'], # 10: ['20200820-subject-03/20200820_142158/932122060861/color_000030.jpg', '20200820-subject-03/20200820_142158/932122060861/color_000060.jpg', '20200903-subject-04/20200903_110342/836212060125/color_000060.jpg', '20200908-subject-05/20200908_145938/836212060125/color_000060.jpg', '20200908-subject-05/20200908_145938/839512060362/color_000030.jpg', '20200918-subject-06/20200918_115139/839512060362/color_000060.jpg', '20200918-subject-06/20200918_115139/840412060917/color_000030.jpg', '20200928-subject-07/20200928_153732/836212060125/color_000030.jpg', '20200928-subject-07/20200928_153732/932122060857/color_000060.jpg', '20201002-subject-08/20201002_110854/836212060125/color_000060.jpg', '20201015-subject-09/20201015_145212/836212060125/color_000030.jpg', '20201015-subject-09/20201015_145212/839512060362/color_000060.jpg'], # 15: ['20200820-subject-03/20200820_143802/836212060125/color_000060.jpg', '20200820-subject-03/20200820_143802/840412060917/color_000030.jpg', '20200903-subject-04/20200903_112724/836212060125/color_000060.jpg', '20200903-subject-04/20200903_112724/841412060263/color_000030.jpg', '20200908-subject-05/20200908_151328/836212060125/color_000060.jpg', '20200908-subject-05/20200908_151328/840412060917/color_000030.jpg', '20200918-subject-06/20200918_120310/836212060125/color_000030.jpg', '20200918-subject-06/20200918_120310/836212060125/color_000060.jpg', '20200928-subject-07/20200928_154943/836212060125/color_000030.jpg', '20200928-subject-07/20200928_154943/836212060125/color_000060.jpg', '20201002-subject-08/20201002_112045/836212060125/color_000030.jpg', '20201002-subject-08/20201002_112045/836212060125/color_000060.jpg', '20201015-subject-09/20201015_150413/836212060125/color_000030.jpg', '20201015-subject-09/20201015_150413/836212060125/color_000060.jpg', '20201022-subject-10/20201022_113909/836212060125/color_000060.jpg'] # } # # TEMP; val set # # target_img_list = { # # 1: ['20200709-subject-01/20200709_142123/836212060125/color_000030.jpg', '20200709-subject-01/20200709_142123/836212060125/color_000060.jpg', '20200813-subject-02/20200813_145612/836212060125/color_000030.jpg', '20200813-subject-02/20200813_145612/836212060125/color_000060.jpg'], # # 2: ['20200709-subject-01/20200709_142446/840412060917/color_000030.jpg', '20200709-subject-01/20200709_142446/840412060917/color_000060.jpg', '20200813-subject-02/20200813_145920/836212060125/color_000030.jpg', '20200813-subject-02/20200813_145920/836212060125/color_000060.jpg'], # # 10: ['20200709-subject-01/20200709_145743/839512060362/color_000060.jpg', '20200709-subject-01/20200709_145743/932122061900/color_000030.jpg', '20200813-subject-02/20200813_152842/836212060125/color_000060.jpg', '20200813-subject-02/20200813_152842/841412060263/color_000030.jpg'], # # 15: ['20200709-subject-01/20200709_151632/836212060125/color_000060.jpg', '20200709-subject-01/20200709_151632/840412060917/color_000030.jpg', '20200813-subject-02/20200813_154408/836212060125/color_000030.jpg', '20200813-subject-02/20200813_154408/836212060125/color_000060.jpg'], # # } # target_img_list_sum = [] # for key, val in target_img_list.items(): # target_img_list_sum.extend(val) #with open('/home/hongsuk.c/Projects/HandOccNet/main/novel_object_test_list.json', 'r') as f: # target_img_list_sum = json.load(f) #print("TARGET LENGTH: ", len(target_img_list_sum)) class DEX_YCB(torch.utils.data.Dataset): def __init__(self, transform, data_split): self.transform = transform self.data_split = data_split if data_split == 'train' else 'val' self.root_dir = osp.join('..', 'data', 'DEX_YCB', 'data') self.annot_path = osp.join(self.root_dir, 'annotations') self.root_joint_idx = 0 self.datalist = self.load_data() if self.data_split != 'train': self.eval_result = [[],[]] #[mpjpe_list, pa-mpjpe_list] print("TEST DATA LEN: ", len(self.datalist)) def load_data(self): db = COCO(osp.join(self.annot_path, "DEX_YCB_s0_{}_data.json".format(self.data_split))) datalist = [] for aid in db.anns.keys(): ann = db.anns[aid] image_id = ann['image_id'] img = db.loadImgs(image_id)[0] img_path = osp.join(self.root_dir, img['file_name']) img_shape = (img['height'], img['width']) if self.data_split == 'train': joints_coord_cam = np.array(ann['joints_coord_cam'], dtype=np.float32) # meter cam_param = {k:np.array(v, dtype=np.float32) for k,v in ann['cam_param'].items()} joints_coord_img = np.array(ann['joints_img'], dtype=np.float32) hand_type = ann['hand_type'] bbox = get_bbox(joints_coord_img[:,:2], np.ones_like(joints_coord_img[:,0]), expansion_factor=1.5) bbox = process_bbox(bbox, img['width'], img['height'], expansion_factor=1.0) if bbox is None: continue mano_pose = np.array(ann['mano_param']['pose'], dtype=np.float32) mano_shape = np.array(ann['mano_param']['shape'], dtype=np.float32) data = {"img_path": img_path, "img_shape": img_shape, "joints_coord_cam": joints_coord_cam, "joints_coord_img": joints_coord_img, "bbox": bbox, "cam_param": cam_param, "mano_pose": mano_pose, "mano_shape": mano_shape, "hand_type": hand_type} else: # if '/'.join(img_path.split('/')[-4:]) not in target_img_list_sum: # continue joints_coord_cam = np.array(ann['joints_coord_cam'], dtype=np.float32) root_joint_cam = copy.deepcopy(joints_coord_cam[0]) joints_coord_img = np.array(ann['joints_img'], dtype=np.float32) hand_type = ann['hand_type'] if False and hand_type == 'left': # mano_pose = np.array(ann['mano_param']['pose'], dtype=np.float32) # mano_shape = np.array(ann['mano_param']['shape'], dtype=np.float32) # vertices, joints, manojoints2cam = mano.left_layer(torch.from_numpy(mano_pose)[None, :], torch.from_numpy(mano_shape)[None, :]) # vertices = vertices[0].numpy() # # save_obj(vertices, mano.left_layer.th_faces.numpy(), 'org_left.obj') # joints = joints[0].numpy() # joints /= 1000 # joints = joints - joints[0:1] + root_joint_cam[None, :] # focal, princpt = ann['cam_param']['focal'], ann['cam_param']['princpt'] # proj_joints = cam2pixel(joints, focal, princpt) # img = cv2.imread(img_path) # vis_img = vis_keypoints(img, proj_joints) # cv2.imshow('check cam', vis_img) # cv2.waitKey(0) # import pdb; pdb.set_trace() # mano_pose = mano_pose.reshape(-1,3) # mano_pose[:,1:] *= -1 # mano_pose = mano_pose.reshape(-1) # vertices, joints, _ = mano.layer(torch.from_numpy(mano_pose)[None, :], torch.from_numpy(mano_shape)[None, :]) # joints = joints[0].numpy() # joints /= 1000 # joints = joints - joints[0:1] # joints[:, 0] *= -1 # joints = joints + root_joint_cam[None, :] # focal, princpt = ann['cam_param']['focal'], ann['cam_param']['princpt'] # proj_joints = cam2pixel(joints, focal, princpt) # img = cv2.imread(img_path) # vis_img = vis_keypoints(img, proj_joints) # cv2.imshow('check flip', vis_img) # cv2.waitKey(0) # import pdb; pdb.set_trace() import pdb; pdb.set_trace() bbox = get_bbox(joints_coord_img[:,:2], np.ones_like(joints_coord_img[:,0]), expansion_factor=1.5) bbox = process_bbox(bbox, img['width'], img['height'], expansion_factor=1.0) if bbox is None: bbox = np.array([0,0,img['width']-1, img['height']-1], dtype=np.float32) cam_param = {k:np.array(v, dtype=np.float32) for k,v in ann['cam_param'].items()} data = {"img_path": img_path, "img_shape": img_shape, "joints_coord_cam": joints_coord_cam, "root_joint_cam": root_joint_cam, "bbox": bbox, "cam_param": cam_param, "image_id": image_id, 'hand_type': hand_type} datalist.append(data) return datalist def __len__(self): return len(self.datalist) def __getitem__(self, idx): data = copy.deepcopy(self.datalist[idx]) img_path, img_shape, bbox = data['img_path'], data['img_shape'], data['bbox'] hand_type = data['hand_type'] do_flip = (hand_type == 'left') # img img = load_img(img_path) orig_img = copy.deepcopy(img)[:,:,::-1] img, img2bb_trans, bb2img_trans, rot, scale = augmentation(img, bbox, self.data_split, do_flip=do_flip) img = self.transform(img.astype(np.float32))/255. if self.data_split == 'train': ## 2D joint coordinate joints_img = data['joints_coord_img'] if do_flip: joints_img[:,0] = img_shape[1] - joints_img[:,0] - 1 joints_img_xy1 = np.concatenate((joints_img[:,:2], np.ones_like(joints_img[:,:1])),1) joints_img = np.dot(img2bb_trans, joints_img_xy1.transpose(1,0)).transpose(1,0)[:,:2] # normalize to [0,1] joints_img[:,0] /= cfg.input_img_shape[1] joints_img[:,1] /= cfg.input_img_shape[0] ## 3D joint camera coordinate joints_coord_cam = data['joints_coord_cam'] root_joint_cam = copy.deepcopy(joints_coord_cam[self.root_joint_idx]) joints_coord_cam -= joints_coord_cam[self.root_joint_idx,None,:] # root-relative if do_flip: joints_coord_cam[:,0] *= -1 # 3D data rotation augmentation rot_aug_mat = np.array([[np.cos(np.deg2rad(-rot)), -np.sin(np.deg2rad(-rot)), 0], [np.sin(np.deg2rad(-rot)), np.cos(np.deg2rad(-rot)), 0], [0, 0, 1]], dtype=np.float32) joints_coord_cam = np.dot(rot_aug_mat, joints_coord_cam.transpose(1,0)).transpose(1,0) ## mano parameter mano_pose, mano_shape = data['mano_pose'], data['mano_shape'] # 3D data rotation augmentation mano_pose = mano_pose.reshape(-1,3) if do_flip: mano_pose[:,1:] *= -1 root_pose = mano_pose[self.root_joint_idx,:] root_pose, _ = cv2.Rodrigues(root_pose) root_pose, _ = cv2.Rodrigues(np.dot(rot_aug_mat,root_pose)) mano_pose[self.root_joint_idx] = root_pose.reshape(3) mano_pose = mano_pose.reshape(-1) inputs = {'img': img} targets = {'joints_img': joints_img, 'joints_coord_cam': joints_coord_cam, 'mano_pose': mano_pose, 'mano_shape': mano_shape} meta_info = {'root_joint_cam': root_joint_cam} else: root_joint_cam = data['root_joint_cam'] inputs = {'img': img} targets = {} meta_info = {'root_joint_cam': root_joint_cam, 'img_path': img_path} return inputs, targets, meta_info def evaluate(self, outs, cur_sample_idx): annots = self.datalist sample_num = len(outs) for n in range(sample_num): annot = annots[cur_sample_idx + n] out = outs[n] joints_out = out['joints_coord_cam'] # root centered joints_out -= joints_out[self.root_joint_idx] # flip back to left hand if annot['hand_type'] == 'left': joints_out[:,0] *= -1 # root align gt_root_joint_cam = annot['root_joint_cam'] joints_out += gt_root_joint_cam # GT and rigid align joints_gt = annot['joints_coord_cam'] joints_out_aligned = rigid_align(joints_out, joints_gt) # m to mm joints_out *= 1000 joints_out_aligned *= 1000 joints_gt *= 1000 self.eval_result[0].append(np.sqrt(np.sum((joints_out - joints_gt)**2,1)).mean()) self.eval_result[1].append(np.sqrt(np.sum((joints_out_aligned - joints_gt)**2,1)).mean()) def print_eval_result(self, test_epoch): print('MPJPE : %.2f mm' % np.mean(self.eval_result[0])) print('PA MPJPE : %.2f mm' % np.mean(self.eval_result[1])) """ def evaluate(self, outs, cur_sample_idx): annots = self.datalist sample_num = len(outs) for n in range(sample_num): annot = annots[cur_sample_idx + n] out = outs[n] verts_out = out['mesh_coord_cam'] joints_out = out['joints_coord_cam'] # root centered verts_out -= joints_out[self.root_joint_idx] joints_out -= joints_out[self.root_joint_idx] # flip back to left hand if annot['hand_type'] == 'left': verts_out[:,0] *= -1 joints_out[:,0] *= -1 # root align gt_root_joint_cam = annot['root_joint_cam'] verts_out += gt_root_joint_cam joints_out += gt_root_joint_cam # m to mm verts_out *= 1000 joints_out *= 1000 self.eval_result[0].append(joints_out) self.eval_result[1].append(verts_out) def print_eval_result(self, test_epoch): output_file_path = osp.join(cfg.result_dir, "DEX_RESULTS_EPOCH{}.txt".format(test_epoch)) with open(output_file_path, 'w') as output_file: for i, pred_joints in enumerate(self.eval_result[0]): image_id = self.datalist[i]['image_id'] output_file.write(str(image_id) + ',' + ','.join(pred_joints.ravel().astype(str).tolist()) + '\n') """ ================================================ FILE: data/HO3D/HO3D.py ================================================ import os import os.path as osp import numpy as np import torch import cv2 import random import json import math import copy from pycocotools.coco import COCO from config import cfg from utils.preprocessing import load_img, get_bbox, process_bbox, generate_patch_image, augmentation from utils.transforms import world2cam, cam2pixel, pixel2cam, rigid_align, transform_joint_to_other_db from utils.vis import vis_keypoints, vis_mesh, save_obj, vis_keypoints_with_skeleton from utils.mano import MANO mano = MANO() class HO3D(torch.utils.data.Dataset): def __init__(self, transform, data_split): self.transform = transform self.data_split = data_split if data_split == 'train' else 'evaluation' self.root_dir = osp.join('..', 'data', 'HO3D', 'data') self.annot_path = osp.join(self.root_dir, 'annotations') self.root_joint_idx = 0 self.datalist = self.load_data() if self.data_split != 'train': self.eval_result = [[],[]] #[pred_joints_list, pred_verts_list] self.joints_name = ('Wrist', 'Index_1', 'Index_2', 'Index_3', 'Middle_1', 'Middle_2', 'Middle_3', 'Pinky_1', 'Pinky_2', 'Pinky_3', 'Ring_1', 'Ring_2', 'Ring_3', 'Thumb_1', 'Thumb_2', 'Thumb_3', 'Thumb_4', 'Index_4', 'Middle_4', 'Ring_4', 'Pinly_4') def load_data(self): db = COCO(osp.join(self.annot_path, "HO3D_{}_data.json".format(self.data_split))) # db = COCO(osp.join(self.annot_path, 'HO3Dv3_partial_test_multiseq_coco.json')) datalist = [] for aid in db.anns.keys(): ann = db.anns[aid] image_id = ann['image_id'] img = db.loadImgs(image_id)[0] img_path = osp.join(self.root_dir, self.data_split, img['file_name']) # TEMP # img_path = osp.join(self.root_dir, 'train', img['sequence_name'], 'rgb', img['file_name']) img_shape = (img['height'], img['width']) if self.data_split == 'train': joints_coord_cam = np.array(ann['joints_coord_cam'], dtype=np.float32) # meter cam_param = {k:np.array(v, dtype=np.float32) for k,v in ann['cam_param'].items()} joints_coord_img = cam2pixel(joints_coord_cam, cam_param['focal'], cam_param['princpt']) bbox = get_bbox(joints_coord_img[:,:2], np.ones_like(joints_coord_img[:,0]), expansion_factor=1.5) bbox = process_bbox(bbox, img['width'], img['height'], expansion_factor=1.0) if bbox is None: continue mano_pose = np.array(ann['mano_param']['pose'], dtype=np.float32) mano_shape = np.array(ann['mano_param']['shape'], dtype=np.float32) data = {"img_path": img_path, "img_shape": img_shape, "joints_coord_cam": joints_coord_cam, "joints_coord_img": joints_coord_img, "bbox": bbox, "cam_param": cam_param, "mano_pose": mano_pose, "mano_shape": mano_shape} else: root_joint_cam = np.array(ann['root_joint_cam'], dtype=np.float32) cam_param = {k:np.array(v, dtype=np.float32) for k,v in ann['cam_param'].items()} # TEMP # root_joint_cam = np.zeros(0) # cam_param = np.zeros(0) bbox = np.array(ann['bbox'], dtype=np.float32) bbox = process_bbox(bbox, img['width'], img['height'], expansion_factor=1.5) data = {"img_path": img_path, "img_shape": img_shape, "root_joint_cam": root_joint_cam, "bbox": bbox, "cam_param": cam_param} datalist.append(data) return datalist def __len__(self): return len(self.datalist) def __getitem__(self, idx): data = copy.deepcopy(self.datalist[idx]) img_path, img_shape, bbox = data['img_path'], data['img_shape'], data['bbox'] # img img = load_img(img_path) img, img2bb_trans, bb2img_trans, rot, scale = augmentation(img, bbox, self.data_split, do_flip=False) img = self.transform(img.astype(np.float32))/255. if self.data_split == 'train': ## 2D joint coordinate joints_img = data['joints_coord_img'] joints_img_xy1 = np.concatenate((joints_img[:,:2], np.ones_like(joints_img[:,:1])),1) joints_img = np.dot(img2bb_trans, joints_img_xy1.transpose(1,0)).transpose(1,0)[:,:2] # normalize to [0,1] joints_img[:,0] /= cfg.input_img_shape[1] joints_img[:,1] /= cfg.input_img_shape[0] ## 3D joint camera coordinate joints_coord_cam = data['joints_coord_cam'] root_joint_cam = copy.deepcopy(joints_coord_cam[self.root_joint_idx]) joints_coord_cam -= joints_coord_cam[self.root_joint_idx,None,:] # root-relative # 3D data rotation augmentation rot_aug_mat = np.array([[np.cos(np.deg2rad(-rot)), -np.sin(np.deg2rad(-rot)), 0], [np.sin(np.deg2rad(-rot)), np.cos(np.deg2rad(-rot)), 0], [0, 0, 1]], dtype=np.float32) joints_coord_cam = np.dot(rot_aug_mat, joints_coord_cam.transpose(1,0)).transpose(1,0) ## mano parameter mano_pose, mano_shape = data['mano_pose'], data['mano_shape'] # 3D data rotation augmentation mano_pose = mano_pose.reshape(-1,3) root_pose = mano_pose[self.root_joint_idx,:] root_pose, _ = cv2.Rodrigues(root_pose) root_pose, _ = cv2.Rodrigues(np.dot(rot_aug_mat,root_pose)) mano_pose[self.root_joint_idx] = root_pose.reshape(3) mano_pose = mano_pose.reshape(-1) inputs = {'img': img} targets = {'joints_img': joints_img, 'joints_coord_cam': joints_coord_cam, 'mano_pose': mano_pose, 'mano_shape': mano_shape} meta_info = {'root_joint_cam': root_joint_cam} else: root_joint_cam = data['root_joint_cam'] inputs = {'img': img} targets = {} meta_info = {'root_joint_cam': root_joint_cam, 'img_path': img_path} return inputs, targets, meta_info def evaluate(self, outs, cur_sample_idx): annots = self.datalist sample_num = len(outs) for n in range(sample_num): annot = annots[cur_sample_idx + n] out = outs[n] verts_out = out['mesh_coord_cam'] joints_out = out['joints_coord_cam'] # root align gt_root_joint_cam = annot['root_joint_cam'] verts_out = verts_out - joints_out[self.root_joint_idx] + gt_root_joint_cam joints_out = joints_out - joints_out[self.root_joint_idx] + gt_root_joint_cam # convert to openGL coordinate system. verts_out *= np.array([1, -1, -1]) joints_out *= np.array([1, -1, -1]) # convert joint ordering from MANO to HO3D. joints_out = transform_joint_to_other_db(joints_out, mano.joints_name, self.joints_name) self.eval_result[0].append(joints_out.tolist()) self.eval_result[1].append(verts_out.tolist()) def print_eval_result(self, test_epoch): output_json_file = osp.join(cfg.result_dir, 'pred{}.json'.format(test_epoch)) output_zip_file = osp.join(cfg.result_dir, 'pred{}.zip'.format(test_epoch)) with open(output_json_file, 'w') as f: json.dump(self.eval_result, f) print('Dumped %d joints and %d verts predictions to %s' % (len(self.eval_result[0]), len(self.eval_result[1]), output_json_file)) cmd = 'zip -j ' + output_zip_file + ' ' + output_json_file print(cmd) os.system(cmd) ================================================ FILE: demo/demo.py ================================================ import sys import os import os.path as osp import argparse import numpy as np import cv2 import torch import torchvision.transforms as transforms from torch.nn.parallel.data_parallel import DataParallel import torch.backends.cudnn as cudnn sys.path.insert(0, osp.join('..', 'main')) sys.path.insert(0, osp.join('..', 'common')) from config import cfg from model import get_model from utils.preprocessing import load_img, process_bbox, generate_patch_image from utils.vis import save_obj from utils.mano import MANO mano = MANO() def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('--gpu', type=str, dest='gpu_ids') args = parser.parse_args() # test gpus if not args.gpu_ids: assert 0, print("Please set proper gpu ids") if '-' in args.gpu_ids: gpus = args.gpu_ids.split('-') gpus[0] = int(gpus[0]) gpus[1] = int(gpus[1]) + 1 args.gpu_ids = ','.join(map(lambda x: str(x), list(range(*gpus)))) return args # argument parsing args = parse_args() cfg.set_args(args.gpu_ids) cudnn.benchmark = True # snapshot load model_path = './snapshot_demo.pth.tar' assert osp.exists(model_path), 'Cannot find model at ' + model_path print('Load checkpoint from {}'.format(model_path)) model = get_model('test') model = DataParallel(model).cuda() ckpt = torch.load(model_path) model.load_state_dict(ckpt['network'], strict=False) model.eval() # prepare input image transform = transforms.ToTensor() img_path = 'input.png' original_img = load_img(img_path) original_img_height, original_img_width = original_img.shape[:2] # prepare bbox bbox = [340.8, 232.0, 20.7, 20.7] # xmin, ymin, width, height bbox = process_bbox(bbox, original_img_width, original_img_height) img, img2bb_trans, bb2img_trans = generate_patch_image(original_img, bbox, 1.0, 0.0, False, cfg.input_img_shape) img = transform(img.astype(np.float32))/255 img = img.cuda()[None,:,:,:] # forward inputs = {'img': img} targets = {} meta_info = {} with torch.no_grad(): out = model(inputs, targets, meta_info, 'test') img = (img[0].cpu().numpy().transpose(1,2,0)*255).astype(np.uint8) # cfg.input_img_shape[1], cfg.input_img_shape[0], 3 verts_out = out['mesh_coord_cam'][0].cpu().numpy() # bbox for input hand image bbox_vis = np.array(bbox, int) bbox_vis[2:] += bbox_vis[:2] cvimg = cv2.rectangle(original_img.copy(), bbox_vis[:2], bbox_vis[2:], (255,0,0), 3) cv2.imwrite('hand_bbox.png', cvimg[:,:,::-1]) ## input hand image cv2.imwrite('hand_image.png', img[:,:,::-1]) # save mesh (obj) save_obj(verts_out*np.array([1,-1,-1]), mano.face, 'output.obj') ================================================ FILE: demo/demo_fitting.py ================================================ import sys import glob import os import os.path as osp import argparse import json import numpy as np import cv2 import torch from PIL import Image import torchvision.transforms as transforms from torch.nn.parallel.data_parallel import DataParallel import torch.backends.cudnn as cudnn from tqdm import tqdm sys.path.insert(0, osp.join('..', 'main')) sys.path.insert(0, osp.join('..', 'common')) from config import cfg from model import get_model from utils.preprocessing import load_img, process_bbox, generate_patch_image from utils.vis import save_obj, vis_keypoints_with_skeleton from utils.mano import MANO from utils.camera import PerspectiveCamera mano = MANO() def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('--gpu', type=str, dest='gpu_ids') parser.add_argument('--depth', type=float, default='0.5') args = parser.parse_args() # test gpus if not args.gpu_ids: assert 0, print("Please set proper gpu ids") if '-' in args.gpu_ids: gpus = args.gpu_ids.split('-') gpus[0] = int(gpus[0]) gpus[1] = int(gpus[1]) + 1 args.gpu_ids = ','.join(map(lambda x: str(x), list(range(*gpus)))) return args def load_camera(cam_path, cam_idx='0'): with open(cam_path, 'r') as f: cam_data = json.load(f) camera = PerspectiveCamera() camera.focal_length_x = torch.full([1], cam_data[cam_idx]['fx']) camera.focal_length_y = torch.full([1], cam_data[cam_idx]['fy']) camera.center = torch.tensor( [cam_data[cam_idx]['cx'], cam_data[cam_idx]['cy']]).unsqueeze(0) # only intrinsics # rotation, _ = cv2.Rodrigues( # np.array(cam_data[cam_idx]['rvec'], dtype=np.float32)) # camera.rotation.data = torch.from_numpy(rotation).unsqueeze(0) # camera.translation.data = torch.tensor( # cam_data[cam_idx]['tvec']).unsqueeze(0) / 1000. camera.rotation.requires_grad = False camera.translation.requires_grad = False camera.name = str(cam_idx) return camera if __name__ == '__main__': # argument parsing args = parse_args() cfg.set_args(args.gpu_ids) cudnn.benchmark = True transform = transforms.ToTensor() # hard coding save_dir = './' init_depth = args.depth img_path = 'fitting_input.jpg' bbox = [300, 330, 90, 50]#[340.8, 232.0, 20.7, 20.7] # xmin, ymin, width, height # model snapshot load model_path = './snapshot_demo.pth.tar' assert osp.exists(model_path), 'Cannot find model at ' + model_path print('Load checkpoint from {}'.format(model_path)) model = get_model('test') model = DataParallel(model).cuda() ckpt = torch.load(model_path) model.load_state_dict(ckpt['network'], strict=False) model.eval() # prepare input image transform = transforms.ToTensor() original_img = load_img(img_path) original_img_height, original_img_width = original_img.shape[:2] # prepare bbox bbox = process_bbox(bbox, original_img_width, original_img_height) img, img2bb_trans, bb2img_trans = generate_patch_image(original_img, bbox, 1.0, 0.0, False, cfg.input_img_shape) img = transform(img.astype(np.float32))/255 img = img.cuda()[None,:,:,:] # get camera for projection camera = PerspectiveCamera() camera.rotation.requires_grad = False camera.translation.requires_grad = False camera.center[0, 0] = original_img.shape[1] / 2 camera.center[0, 1] = original_img.shape[0] / 2 camera.cuda() # forward pass to the model inputs = {'img': img} # cfg.input_img_shape[1], cfg.input_img_shape[0], 3 targets = {} meta_info = {} with torch.no_grad(): out = model(inputs, targets, meta_info, 'test') img = (img[0].cpu().numpy().transpose(1, 2, 0)*255).astype(np.uint8) # verts_out = out['mesh_coord_cam'][0].cpu().numpy() # get hand mesh's scale and translation by fitting joint cam to joint img joint_img, joint_cam = out['joints_coord_img'], out['joints_coord_cam'] # denormalize joint_img from 0 ~ 1 to actual 0 ~ original height and width H, W = img.shape[:2] joint_img[:, :, 0] *= W joint_img[:, :, 1] *= H torch_bb2img_trans = torch.tensor(bb2img_trans).to(joint_img) homo_joint_img = torch.cat([joint_img, torch.ones_like(joint_img[:, :, :1])], dim=2) org_res_joint_img = homo_joint_img @ torch_bb2img_trans.transpose(0, 1) # depth initialization depth_map = None #np.asarray(Image.open(depth_path)) hand_scale, hand_translation = model.module.get_mesh_scale_trans( org_res_joint_img, joint_cam, init_scale=1., init_depth=init_depth, camera=camera, depth_map=depth_map) np_joint_img = org_res_joint_img[0].cpu().numpy() np_joint_img = np.concatenate([np_joint_img, np.ones_like(np_joint_img[:, :1])], axis=1) vis_img = original_img.astype(np.uint8)[:, :, ::-1] pred_joint_img_overlay = vis_keypoints_with_skeleton(vis_img, np_joint_img.T, mano.skeleton) # cv2.imshow('2d prediction', pred_joint_img_overlay) save_path = osp.join( save_dir, f'{osp.basename(img_path)[:-4]}_2d_prediction.png') cv2.imwrite(save_path, pred_joint_img_overlay) projected_joints = camera( hand_scale * joint_cam + hand_translation) np_joint_img = projected_joints[0].detach().cpu().numpy() np_joint_img = np.concatenate([np_joint_img, np.ones_like(np_joint_img[:, :1])], axis=1) vis_img = original_img.astype(np.uint8)[:, :, ::-1] pred_joint_img_overlay = vis_keypoints_with_skeleton(vis_img, np_joint_img.T, mano.skeleton) # cv2.imshow('projection', pred_joint_img_overlay) # cv2.waitKey(0) save_path = osp.join(save_dir, f'{osp.basename(img_path)[:-4]}_projection.png') cv2.imwrite(save_path, pred_joint_img_overlay) # data to save data_to_save = { 'hand_scale': hand_scale.detach().cpu().numpy().tolist(), # 1 'hand_translation': hand_translation.detach().cpu().numpy().tolist(), # 3 'mano_pose': out['mano_pose'][0].detach().cpu().numpy().tolist(), # 48 'mano_shape': out['mano_shape'][0].detach().cpu().numpy().tolist(), # 10 } save_path = osp.join( save_dir, f'{osp.basename(img_path)[:-4]}_3dmesh.json') with open(save_path, 'w') as f: json.dump(data_to_save, f) # # bbox for input hand image # bbox_vis = np.array(bbox, int) # bbox_vis[2:] += bbox_vis[:2] # cvimg = cv2.rectangle(original_img.copy(), # bbox_vis[:2], bbox_vis[2:], (255, 0, 0), 3) # cv2.imwrite(f'{osp.basename(img_path)[:-4]}_hand_bbox.png', cvimg[:, :, ::-1]) # ## input hand image # cv2.imwrite(f'{osp.basename(img_path)[:-4]}_hand_image.png', img[:, :, ::-1]) # save mesh (obj) save_path = osp.join( save_dir, f'{osp.basename(img_path)[:-4]}_3dmesh.obj') save_obj(verts_out*np.array([1, -1, -1]), mano.face, save_path) ================================================ FILE: demo/output.obj ================================================ v 0.09704167395830154 0.0123032471165061 0.039412785321474075 v 0.09976062923669815 0.010310064069926739 0.029586462303996086 v 0.10385143011808395 0.014365013688802719 0.03625381737947464 v 0.09955313056707382 0.017543060705065727 0.04449660703539848 v 0.11498267948627472 0.016574472188949585 0.020893722772598267 v 0.11550682783126831 0.02474113740026951 0.014739320613443851 v 0.11841963976621628 0.028651203960180283 0.029420627281069756 v 0.1187518835067749 0.020955543965101242 0.03313694894313812 v 0.10000406950712204 0.02170594595372677 0.04935751110315323 v 0.10712949186563492 0.017804410308599472 0.043026067316532135 v 0.09772946685552597 0.023356322199106216 0.050800975412130356 v 0.08702512085437775 0.027183635160326958 0.05566640943288803 v 0.09220578521490097 0.024990126490592957 0.05519742891192436 v 0.0820174366235733 0.02769414521753788 0.06143525615334511 v 0.08001333475112915 0.02764720283448696 0.04892248660326004 v 0.07448913156986237 0.023760424926877022 0.060431305319070816 v 0.06879005581140518 0.006574998609721661 0.0407930389046669 v 0.06904236972332001 -0.005039920099079609 0.038309454917907715 v 0.06741352379322052 -0.006001491565257311 0.05440099164843559 v 0.06813132017850876 0.00622991006821394 0.0552951879799366 v 0.07286028563976288 -0.021629616618156433 0.046827297657728195 v 0.06995420902967453 -0.012919521890580654 0.05173160508275032 v 0.07021812349557877 -0.012072782032191753 0.035572897642850876 v 0.07322045415639877 -0.019798777997493744 0.031946342438459396 v 0.09612422436475754 0.000507109856698662 0.0327720120549202 v 0.0982327088713646 -0.0007277392433024943 0.023071376606822014 v 0.09740523248910904 0.003534032730385661 0.024903787299990654 v 0.09577703475952148 0.004897149745374918 0.034299276769161224 v 0.099307581782341 0.030571212992072105 0.04903818666934967 v 0.09175309538841248 0.03211066126823425 0.04123810678720474 v 0.09266895055770874 0.027560750022530556 0.04706060513854027 v 0.10247763991355896 0.027115963399410248 0.051462795585393906 v 0.10852036625146866 -0.00967042800039053 0.0010749474167823792 v 0.1044674888253212 -0.009041075594723225 -0.010376684367656708 v 0.10359753668308258 -0.0038258449640125036 -0.01053894404321909 v 0.10706440359354019 -0.005605116952210665 -0.00010789186490001157 v 0.10655821114778519 0.015718799084424973 -0.0038651900831609964 v 0.10114449262619019 0.012555424124002457 -0.011676214635372162 v 0.09330809116363525 0.019990479573607445 -0.01726539433002472 v 0.09610037505626678 0.02422197535634041 -0.008547515608370304 v 0.11166828125715256 0.020764684304594994 0.005238473881036043 v 0.10379082709550858 0.028549164533615112 0.00103653222322464 v 0.10910049080848694 0.03203720599412918 0.011868038214743137 v 0.11276104301214218 0.03460574895143509 0.026923196390271187 v 0.1037481427192688 -0.020462632179260254 -0.010825783014297485 v 0.10694169253110886 -0.022308088839054108 -0.002532459795475006 v 0.09702412784099579 0.021299252286553383 0.09731592983007431 v 0.09826341271400452 0.016166748479008675 0.09627735614776611 v 0.09706933796405792 0.01635078713297844 0.09417114406824112 v 0.09600481390953064 0.02130129560828209 0.09562767297029495 v 0.09107829630374908 -0.03202741593122482 -0.005628600716590881 v 0.08212634921073914 -0.03188098967075348 -0.00568735646083951 v 0.08398226648569107 -0.03263990953564644 -0.012086243368685246 v 0.09229756146669388 -0.031173406168818474 -0.012397877871990204 v 0.08960714936256409 -0.032796479761600494 0.003477819263935089 v 0.08015740662813187 -0.030353110283613205 0.0033182355109602213 v 0.09060245007276535 0.02204286865890026 0.10700210183858871 v 0.09335938096046448 0.024315452203154564 0.1039421334862709 v 0.08984217792749405 0.02442437969148159 0.10220398753881454 v 0.0864965170621872 0.021755777299404144 0.10453414171934128 v 0.0952310562133789 0.020760783925652504 0.05235325172543526 v 0.09612379223108292 0.013916807249188423 0.04842321202158928 v 0.09275881201028824 0.019942499697208405 0.06846490502357483 v 0.09354271739721298 0.016712404787540436 0.06071989983320236 v 0.09189996123313904 0.02278514765202999 0.05997182056307793 v 0.09013500064611435 0.024846429005265236 0.06666994094848633 v 0.0940636396408081 -0.0031293872743844986 0.05349469929933548 v 0.09469340741634369 -0.0026052643079310656 0.04270586743950844 v 0.09410218149423599 0.002816879888996482 0.04490778222680092 v 0.09403892606496811 0.0038006349932402372 0.056964416056871414 v 0.09825103729963303 -0.014537331648170948 0.04019445925951004 v 0.09684037417173386 -0.0140069629997015 0.050926629453897476 v 0.09873218834400177 -0.02082197554409504 0.04806012660264969 v 0.10043563693761826 -0.019858956336975098 0.04097581282258034 v 0.09248537570238113 -0.010444425977766514 0.06883682310581207 v 0.09154201298952103 -0.009355786256492138 0.07404470443725586 v 0.09260138124227524 -0.012381582520902157 0.07426491379737854 v 0.09295526146888733 -0.013393072411417961 0.06776127964258194 v 0.0847911611199379 -0.0330488346517086 -0.018598178401589394 v 0.09283468127250671 -0.029433878138661385 -0.018831679597496986 v 0.08127716183662415 -0.037603959441185 0.040029171854257584 v 0.08886391669511795 -0.04075009375810623 0.03510737419128418 v 0.09025923162698746 -0.0435173474252224 0.04641684144735336 v 0.08072876930236816 -0.039703723043203354 0.04932333528995514 v 0.0749884694814682 -0.026462497189641 -0.004455134738236666 v 0.07592447847127914 -0.029161827638745308 -0.01113533228635788 v 0.08868138492107391 0.01678049936890602 0.10864982008934021 v 0.08478643000125885 0.016503214836120605 0.10636698454618454 v 0.09663982689380646 0.035291120409965515 0.010118492878973484 v 0.10477548092603683 0.0380316898226738 0.026483744382858276 v 0.08999285846948624 0.030108794569969177 -0.002212435007095337 v 0.0851031243801117 0.024710390716791153 -0.010170720517635345 v 0.08258376270532608 0.021762587130069733 -0.018127508461475372 v 0.09366891533136368 0.01160071324557066 0.06399420648813248 v 0.09508023411035538 0.0076362332329154015 0.04296451807022095 v 0.09705101698637009 -0.00388349243439734 0.03176907077431679 v 0.10574627667665482 -0.029874518513679504 0.030231954529881477 v 0.1072174534201622 -0.02885815128684044 0.020927833393216133 v 0.10617993772029877 -0.02044968120753765 0.02524772845208645 v 0.10448476672172546 -0.023264355957508087 0.03252417966723442 v 0.09787759184837341 -0.04072023183107376 0.035247232764959335 v 0.10269629210233688 -0.03633294627070427 0.037638574838638306 v 0.10200449079275131 -0.03697844594717026 0.04497504234313965 v 0.09784367680549622 -0.041939008980989456 0.0442439466714859 v 0.0993509367108345 0.03691822290420532 0.04624485969543457 v 0.09221241623163223 0.03617630898952484 0.03594726324081421 v 0.09991807490587234 -0.028782188892364502 -0.005242601037025452 v 0.09977457672357559 -0.026117412373423576 -0.011667192913591862 v 0.0983252227306366 -0.025250444188714027 -0.019326167181134224 v 0.10373659431934357 -0.004046760965138674 0.01158856600522995 v 0.10632442682981491 -0.002683989703655243 -0.0010402277112007141 v 0.10617887228727341 0.0013205824652686715 -0.0002762451767921448 v 0.10243091732263565 -0.0014278828166425228 0.012040451169013977 v 0.10552237927913666 0.008538869209587574 0.01999625377357006 v 0.11025764048099518 0.011296899057924747 0.009791173040866852 v 0.11036954075098038 0.012080628424882889 0.029019424691796303 v 0.10254248231649399 0.00337228924036026 -0.01225954294204712 v 0.10285349190235138 -0.0029982945416122675 -0.019830450415611267 v 0.10075358301401138 0.0047887228429317474 -0.020481610670685768 v 0.10294044762849808 -0.011905921623110771 -0.019881347194314003 v 0.10184606164693832 -0.019946394488215446 -0.01970786787569523 v 0.07410712540149689 -0.03153001144528389 -0.018500978127121925 v 0.09734782576560974 0.011572230607271194 -0.020160282030701637 v 0.1192983090877533 0.024943308904767036 0.041293080896139145 v 0.11934367567300797 0.029254555702209473 0.04782867431640625 v 0.11521545797586441 0.024670789018273354 0.05094749107956886 v 0.11494014412164688 0.020241715013980865 0.045187536627054214 v 0.07898958027362823 0.027264561504125595 0.06948734074831009 v 0.085870660841465 0.0275066290050745 0.06830953061580658 v 0.08816779404878616 0.027377676218748093 0.05996124446392059 v 0.10879211127758026 -0.01456399355083704 0.010258094407618046 v 0.10759785026311874 -0.02512398548424244 0.006774865556508303 v 0.09227554500102997 0.014700433239340782 0.07183413952589035 v 0.08323711156845093 0.02198031358420849 0.10114031285047531 v 0.08718504011631012 0.025041446089744568 0.09874201565980911 v 0.08179915696382523 0.026613231748342514 0.08361773192882538 v 0.07698608934879303 0.02342488244175911 0.08595925569534302 v 0.08710064738988876 0.010135228745639324 0.0794704407453537 v 0.09131284803152084 0.013762109912931919 0.07629778236150742 v 0.09036200493574142 0.012931560166180134 0.07877384126186371 v 0.08829855918884277 0.008487006649374962 0.08210074156522751 v 0.09455457329750061 -0.018902059644460678 0.0692327693104744 v 0.09495323151350021 -0.019648753106594086 0.06373544782400131 v 0.0700426921248436 0.005297053139656782 0.06998594105243683 v 0.06758403778076172 0.016597703099250793 0.06780336052179337 v 0.06917118281126022 0.015945417806506157 0.05677381530404091 v 0.09529761224985123 -0.009283529594540596 0.05125439539551735 v 0.09456868469715118 -0.010417206212878227 0.06084778532385826 v 0.09512004256248474 -0.013825497590005398 0.059904929250478745 v 0.09272909164428711 0.008574625477194786 0.06723345071077347 v 0.09071554243564606 0.009755033999681473 0.07368878275156021 v 0.09069853276014328 0.0059261927381157875 0.07144072651863098 v 0.09285608679056168 0.004113199654966593 0.06521569937467575 v 0.08840681612491608 -0.03841841593384743 0.023314980790019035 v 0.09859631955623627 -0.038903333246707916 0.023828836157917976 v 0.09550290554761887 0.024148257449269295 0.10024920850992203 v 0.09340698271989822 0.02425946667790413 0.09864538908004761 v 0.09598366916179657 -0.008685051463544369 0.04080434516072273 v 0.07096162438392639 0.01585032045841217 0.043433088809251785 v 0.09816217422485352 -0.008554179221391678 0.03062260150909424 v 0.0815075933933258 -0.029755791649222374 0.06396094709634781 v 0.0892564132809639 -0.03116283193230629 0.0650174468755722 v 0.09104897081851959 -0.029866019263863564 0.06883867084980011 v 0.08587896823883057 -0.029217805713415146 0.07037565857172012 v 0.09131127595901489 0.007197975646704435 0.0943320244550705 v 0.09518592059612274 0.010463752783834934 0.09308510273694992 v 0.09583403915166855 0.010912451893091202 0.09478212147951126 v 0.0926322415471077 0.007368505001068115 0.09736977517604828 v 0.09202869981527328 0.01878918707370758 0.07468339800834656 v 0.09020364284515381 0.024195468053221703 0.0735035389661789 v 0.09103194624185562 0.022528868168592453 0.07921769469976425 v 0.091405488550663 0.017365960404276848 0.07912317663431168 v 0.08558965474367142 0.02679891139268875 0.07541236281394958 v 0.08682217448949814 0.02605549991130829 0.08087122440338135 v 0.08633208274841309 0.0067527759820222855 0.09735039621591568 v 0.08223645389080048 0.010843859985470772 0.10099346190690994 v 0.07649202644824982 0.010881617665290833 0.08659590035676956 v 0.08258166164159775 0.007566985208541155 0.08595532923936844 v 0.0719359740614891 -0.018325546756386757 0.018172213807702065 v 0.07609406858682632 -0.027056368067860603 0.016072019934654236 v 0.07732595503330231 -0.028749490156769753 0.029808150604367256 v 0.07750879973173141 -0.03113008663058281 0.04351899027824402 v 0.07843733578920364 -0.03255752474069595 0.05685797333717346 v 0.07198290526866913 -0.024020137265324593 0.05965801700949669 v 0.0805065929889679 -0.034317996352910995 0.026994476094841957 v 0.08016543835401535 0.006380251608788967 0.07753480970859528 v 0.07334155589342117 0.010266893543303013 0.07657967507839203 v 0.07463667541742325 0.005383501295000315 0.0757342129945755 v 0.10097857564687729 -0.014524447731673717 0.029919208958745003 v 0.09139500558376312 0.024932367727160454 0.09599956125020981 v 0.0688001736998558 0.01105081383138895 -0.009003818966448307 v 0.0662405788898468 -0.0007938496419228613 -0.008673690259456635 v 0.06709571182727814 0.0016311444342136383 -0.0007653982029296458 v 0.07024703919887543 0.014973660930991173 -0.0008233339176513255 v 0.09695196896791458 0.016333624720573425 0.0928298681974411 v 0.09556055814027786 0.021853497251868248 0.09346045553684235 v 0.096980519592762 -0.025056641548871994 0.06320597231388092 v 0.09603075683116913 -0.023865845054388046 0.0682482123374939 v 0.0957508385181427 -0.027027003467082977 0.06858387589454651 v 0.09904640913009644 -0.029259080067276955 0.06490246206521988 v 0.07856962829828262 -0.03079616092145443 0.013906420208513737 v 0.09489047527313232 -0.044211000204086304 0.05243838578462601 v 0.08535346388816833 -0.0411541610956192 0.05556129664182663 v 0.0748315155506134 -0.02534787543118 0.004214860498905182 v 0.07039519399404526 -0.018079280853271484 0.005920753348618746 v 0.06964287161827087 -0.018454141914844513 -0.0030979143921285868 v 0.07183246314525604 -0.013284113258123398 0.0679916962981224 v 0.06955385208129883 -0.011937357485294342 0.021499576047062874 v 0.06870152056217194 -0.012083805166184902 0.00831263605505228 v 0.06776849180459976 -0.012296067550778389 -0.002287887269631028 v 0.06653960794210434 -0.01300827320665121 -0.009996488690376282 v 0.06929195672273636 -0.019739557057619095 -0.010172829031944275 v 0.0818871408700943 0.016388699412345886 0.10195586085319519 v 0.08530055731534958 0.010105051100254059 0.10577193647623062 v 0.06699884682893753 -0.022000275552272797 -0.018073970451951027 v 0.06492932885885239 -0.013940362259745598 -0.01775551773607731 v 0.06795584410429001 -0.004060036037117243 0.010362938046455383 v 0.0673689991235733 0.005898629315197468 0.012802742421627045 v 0.06862117350101471 -0.004629070404917002 0.0230640210211277 v 0.06832101196050644 0.00508287874981761 0.026582997292280197 v 0.06534255295991898 -0.005554682109504938 0.06711199134588242 v 0.10090867429971695 0.0079244589433074 0.11017333716154099 v 0.09242511540651321 0.007050279527902603 0.10493535548448563 v 0.09516659379005432 0.0074552311562001705 0.10032538324594498 v 0.10270119458436966 0.006829131860285997 0.10684879869222641 v 0.08892764151096344 0.006780424155294895 0.1011762022972107 v 0.08952357620000839 0.010397772304713726 0.10790194571018219 v 0.07174763083457947 0.016963528469204903 0.029318014159798622 v 0.0881638377904892 0.00679026311263442 0.07698696106672287 v 0.07325604557991028 0.020678525790572166 0.014157518744468689 v 0.07877837121486664 0.028680259361863136 0.03671887516975403 v 0.0822744369506836 0.03156600520014763 0.02582007274031639 v 0.07717494666576385 0.025038650259375572 -0.0009599552140571177 v 0.08428376168012619 0.03328302875161171 0.01146619115024805 v 0.07378752529621124 0.017521288245916367 -0.016901493072509766 v 0.07480984926223755 0.02029043808579445 -0.008761965669691563 v 0.09288359433412552 0.0375823974609375 0.023677224293351173 v 0.10484781861305237 0.01848609559237957 0.10087480396032333 v 0.10492610186338425 0.013303219340741634 0.10009642690420151 v 0.06771355122327805 0.009220598265528679 -0.01663634181022644 v 0.11331065744161606 0.01634730026125908 0.03815999627113342 v 0.10339796543121338 -0.011985878460109234 0.020528066903352737 v 0.10093193501234055 -0.007741913199424744 0.021396173164248466 v 0.10758031159639359 -0.0275997556746006 0.015313037671148777 v 0.10722756385803223 -0.017614303156733513 0.018705317750573158 v 0.10340719670057297 0.02215547300875187 0.10381390154361725 v 0.08976732194423676 -0.010763966478407383 0.07729636877775192 v 0.08927898854017258 -0.011879827827215195 0.07617679238319397 v 0.11881337314844131 0.031483180820941925 0.03776717558503151 v 0.11903183907270432 0.034737519919872284 0.04357830807566643 v 0.10924222320318222 0.0417158268392086 0.0434027723968029 v 0.11543767154216766 0.039488784968853 0.042573023587465286 v 0.11382784694433212 0.037179965525865555 0.03536113351583481 v 0.10756535083055496 0.03964782506227493 0.035578787326812744 v 0.10484609007835388 -0.006275427062064409 0.011816337704658508 v 0.10618429630994797 -0.009479009546339512 0.011916161514818668 v 0.08927493542432785 -0.03559454157948494 0.012706540524959564 v 0.09936922043561935 -0.03572707250714302 0.013979226350784302 v 0.07982035726308823 0.026377057656645775 0.07672037184238434 v 0.07280942052602768 0.023518485948443413 0.07021381705999374 v 0.07480321824550629 0.022992417216300964 0.07794234901666641 v 0.07436933368444443 0.017655448988080025 0.08536778390407562 v 0.08488689363002777 0.006599490065127611 0.07948897033929825 v 0.08173840492963791 0.008599556982517242 0.07996764034032822 v 0.10777415335178375 0.006025450769811869 0.004545524716377258 v 0.10240230709314346 0.003340059192851186 0.014720656909048557 v 0.10854387283325195 0.020398039370775223 0.04769584909081459 v 0.10885907709598541 0.023624904453754425 0.05239100381731987 v 0.09343933314085007 -0.0023422404192388058 0.06189468130469322 v 0.07709788531064987 -0.01116418931633234 0.0767970159649849 v 0.07133799046278 -0.004780727904289961 0.07600247859954834 v 0.09141908586025238 -0.0018139667809009552 0.06982462853193283 v 0.10060973465442657 0.021158616989850998 0.11087476462125778 v 0.10235165804624557 0.022806329652667046 0.10704373568296432 v 0.07162736356258392 0.017459925264120102 0.07732491940259933 v 0.0975027084350586 -0.02044527977705002 0.05729398876428604 v 0.07793529331684113 -0.015420072712004185 0.07362351566553116 v 0.08385299891233444 -0.013055804185569286 0.07817527651786804 v 0.09956632554531097 -0.04146609827876091 0.04872610419988632 v 0.06542887538671494 -0.0018546223873272538 -0.01682181842625141 v 0.09792914986610413 0.01037816796451807 0.09713037312030792 v 0.10412082076072693 0.009001982398331165 0.10142438858747482 v 0.09897857159376144 0.010719705373048782 0.11212009936571121 v 0.09813834726810455 0.01632429100573063 0.1126479059457779 v 0.10029064863920212 -0.031451739370822906 0.005138911306858063 v 0.09953232854604721 -0.0048093064688146114 0.022288620471954346 v 0.0991264283657074 0.0383237861096859 0.03393479064106941 v 0.10309038311243057 0.040303416550159454 0.04418168589472771 v 0.08988425880670547 -0.0010531917214393616 0.07410041987895966 v 0.0855180099606514 -0.035052668303251266 0.060899294912815094 v 0.07667776942253113 -0.02446478046476841 0.06797457486391068 v 0.08161953836679459 -0.02498033456504345 0.07547588646411896 v 0.08246126025915146 -0.019260095432400703 0.07920373231172562 v 0.08687400072813034 -0.014529784210026264 0.08011724054813385 v 0.10432850569486618 0.010655212216079235 0.11375997960567474 v 0.10344551503658295 0.015914831310510635 0.11433034390211105 v 0.10537561029195786 0.02071419358253479 0.11231676489114761 v 0.10645269602537155 0.022376686334609985 0.10867892950773239 v 0.10674712806940079 0.021315833553671837 0.10477187484502792 v 0.10635119676589966 0.0077679031528532505 0.11180484294891357 v 0.10774705559015274 0.006964271422475576 0.10867329686880112 v 0.10718252509832382 0.008627559058368206 0.10319996625185013 v 0.11115296185016632 0.0075631109066307545 0.11188062280416489 v 0.11258053034543991 0.010803195647895336 0.11535993218421936 v 0.11866654455661774 0.02130640298128128 0.11167270690202713 v 0.1134837344288826 0.020623892545700073 0.11338527500629425 v 0.11559610068798065 0.019361982122063637 0.11443730443716049 v 0.12016274780035019 0.019388625398278236 0.11349023878574371 v 0.12495396286249161 0.01839272864162922 0.11356497555971146 v 0.12400609999895096 0.020803557708859444 0.11144670099020004 v 0.11324738711118698 0.01596684753894806 0.11562197655439377 v 0.11953478306531906 0.015452609397470951 0.11489148437976837 v 0.11936898529529572 0.011614941991865635 0.1146402657032013 v 0.12463051825761795 0.011649989522993565 0.11455485224723816 v 0.1249130591750145 0.014984075911343098 0.11498311907052994 v 0.11513824760913849 0.012224603444337845 0.11546681076288223 v 0.11089231818914413 0.01600341498851776 0.1158091127872467 v 0.12782344222068787 0.018659541383385658 0.11182832717895508 v 0.12759655714035034 0.01750166341662407 0.11384749412536621 v 0.1277681440114975 0.014633995480835438 0.11440641433000565 v 0.12999053299427032 0.01464011613279581 0.11272108554840088 v 0.11078564822673798 0.022292813286185265 0.1089676097035408 v 0.11853587627410889 0.02203471213579178 0.10931064933538437 v 0.12389787286520004 0.020167050883173943 0.10859028249979019 v 0.12770676612854004 0.018079636618494987 0.10924037545919418 v 0.11934894323348999 0.020027881488204002 0.10615507513284683 v 0.12366504967212677 0.018457714468240738 0.10648705065250397 v 0.12675690650939941 0.01627535931766033 0.10692723840475082 v 0.1199372187256813 0.016819141805171967 0.10400138050317764 v 0.12363829463720322 0.01589057967066765 0.10510793328285217 v 0.10959358513355255 0.017923621460795403 0.10293251276016235 v 0.10899408906698227 0.02118832804262638 0.1050114631652832 v 0.12605345249176025 0.015171049162745476 0.10536177456378937 v 0.12999188899993896 0.013907549902796745 0.11072052270174026 v 0.11776057630777359 0.008905084803700447 0.113240547478199 v 0.1243242397904396 0.009664873592555523 0.11240724474191666 v 0.11762671172618866 0.007713876198977232 0.11131990700960159 v 0.124140664935112 0.008152167312800884 0.11079742759466171 v 0.1285427212715149 0.010454194620251656 0.1128614991903305 v 0.12737193703651428 0.012098709121346474 0.11405709385871887 v 0.10669850558042526 0.017645055428147316 0.10186115652322769 v 0.10692640393972397 0.012223990634083748 0.10131432861089706 v 0.10949618369340897 0.012320034205913544 0.10224386304616928 v 0.11984838545322418 0.012494608759880066 0.10334113985300064 v 0.11022981256246567 0.008755449205636978 0.1039520874619484 v 0.11218420416116714 0.006941710598766804 0.10855355113744736 v 0.11868289858102798 0.007404694799333811 0.10873425006866455 v 0.11922138929367065 0.008540659211575985 0.10582385957241058 v 0.12369230389595032 0.008247007615864277 0.10841856896877289 v 0.12342163175344467 0.009588262997567654 0.10652203857898712 v 0.12383442372083664 0.012578068301081657 0.10468832403421402 v 0.12716080248355865 0.010020898655056953 0.1082996353507042 v 0.12811720371246338 0.00990602932870388 0.11090055853128433 v 0.12843549251556396 0.013235095888376236 0.10798825323581696 v 0.12606920301914215 0.010310059413313866 0.10682119429111481 v 0.12647303938865662 0.013021416030824184 0.10641910880804062 v 0.1032899022102356 -2.0626934201573022e-05 0.09740043431520462 v 0.1050267368555069 -0.005203413777053356 0.09550277143716812 v 0.10126051306724548 -0.004923070315271616 0.09563297778367996 v 0.09977009892463684 -0.0006417878903448582 0.09715542942285538 v 0.09856535494327545 -0.0016807205975055695 0.10945349931716919 v 0.10053173452615738 0.0014948835596442223 0.1049874946475029 v 0.09503168612718582 0.0008049957104958594 0.10512449592351913 v 0.0928054079413414 -0.0036064647138118744 0.10891411453485489 v 0.09803896397352219 -0.008300520479679108 0.11053139716386795 v 0.09244404733181 -0.009959197603166103 0.10905933380126953 v 0.08820600062608719 -0.0032606583554297686 0.10528319329023361 v 0.09127867221832275 0.001195215154439211 0.10175878554582596 v 0.08201218396425247 0.004234382417052984 0.08451277762651443 v 0.07790355384349823 0.00033672296558506787 0.0865769311785698 v 0.09278634190559387 -0.0064664846286177635 0.07855230569839478 v 0.09150741249322891 -0.009379466064274311 0.07995625585317612 v 0.10212410986423492 0.0015946170315146446 0.10049751400947571 v 0.09768985956907272 0.0011344728991389275 0.1005544513463974 v 0.099787138402462 -0.012475690804421902 0.09386718273162842 v 0.10124480724334717 -0.00795657280832529 0.0927131250500679 v 0.10239710658788681 -0.009099931456148624 0.09463819116353989 v 0.10157150775194168 -0.013411249034106731 0.09706329554319382 v 0.08842288702726364 0.0037187563721090555 0.08054692298173904 v 0.09056572616100311 -0.00125436345115304 0.07900863885879517 v 0.08564342558383942 0.004632189869880676 0.08239571750164032 v 0.0961705893278122 -0.01589551381766796 0.09749633818864822 v 0.0916682779788971 -0.015716375783085823 0.1016964539885521 v 0.08085650950670242 -0.012673716060817242 0.08571226894855499 v 0.0862443819642067 -0.013846339657902718 0.08371853828430176 v 0.09471669048070908 0.0021382328122854233 0.09848080575466156 v 0.10071486234664917 -0.0028719783294945955 0.09389521926641464 v 0.09847711771726608 0.0008932040655054152 0.09527421742677689 v 0.08791560679674149 -0.00986737571656704 0.1040862500667572 v 0.09652187675237656 -0.015497344546020031 0.10606557875871658 v 0.11529088020324707 -0.012561824172735214 0.10467150807380676 v 0.10487128049135208 -0.015099695883691311 0.10269133001565933 v 0.10607081651687622 -0.013364691287279129 0.09845399111509323 v 0.11656473577022552 -0.011935455724596977 0.1004088819026947 v 0.09964955598115921 -0.01593203842639923 0.10117506980895996 v 0.1020800843834877 -0.013614996336400509 0.10707492381334305 v 0.11608894914388657 0.00036618951708078384 0.09773847460746765 v 0.11727289855480194 -0.004998189862817526 0.09578926861286163 v 0.11524305492639542 0.0027495066169649363 0.10094457864761353 v 0.07697568833827972 -0.006270498037338257 0.08658915758132935 v 0.11171828210353851 0.0001718895509839058 0.10938061773777008 v 0.11371675878763199 0.003038860857486725 0.10445452481508255 v 0.10587313026189804 -0.00992021057754755 0.09524083137512207 v 0.11760731041431427 -0.009385282173752785 0.09695809334516525 v 0.11375200003385544 -0.010911057703197002 0.10806544125080109 v 0.11064231395721436 -0.005629090126603842 0.11073490232229233 v 0.11921840906143188 -0.009072351269423962 0.10858304798603058 v 0.11730834096670151 -0.004213749431073666 0.11071636527776718 v 0.1176086887717247 0.001306089572608471 0.10912740975618362 v 0.1179000586271286 0.0034102164208889008 0.1044076606631279 v 0.11809619516134262 0.002763833850622177 0.10091835260391235 v 0.1205950602889061 -0.010853230953216553 0.10541022568941116 v 0.12123463302850723 -0.01086338795721531 0.101219043135643 v 0.12005504220724106 -0.008505551144480705 0.09752489626407623 v 0.12680362164974213 -0.009110518731176853 0.10272692888975143 v 0.12739567458629608 -0.0068908012472093105 0.1062706783413887 v 0.13393165171146393 0.0074096922762691975 0.10004936903715134 v 0.12925687432289124 0.0059366715140640736 0.10286907851696014 v 0.1307617574930191 0.004409794230014086 0.10404996573925018 v 0.13507777452468872 0.005574576556682587 0.10147656500339508 v 0.12567788362503052 0.0036913270596414804 0.10684794187545776 v 0.1277824342250824 0.002648480236530304 0.10663309693336487 v 0.1278526932001114 -0.0015461203875020146 0.10747625678777695 v 0.132225900888443 0.0003041401505470276 0.10406940430402756 v 0.1324746310710907 -0.004004674032330513 0.10317099094390869 v 0.13722461462020874 -0.0024953915271908045 0.10106129944324493 v 0.13726931810379028 0.0016979874344542623 0.1021835058927536 v 0.12943513691425323 -0.004318654537200928 0.10597266256809235 v 0.13814668357372284 0.00557507062330842 0.09996220469474792 v 0.13872301578521729 0.0065662139095366 0.09791400283575058 v 0.12555423378944397 -0.00215710885822773 0.10932739824056625 v 0.12123175710439682 0.004577899817377329 0.10402701050043106 v 0.12824289500713348 0.006793555337935686 0.1003727912902832 v 0.13350935280323029 0.007682312745600939 0.09715374559164047 v 0.1386195719242096 0.00568285072222352 0.09526537358760834 v 0.12808401882648468 0.005677978042513132 0.09672407805919647 v 0.133301243185997 0.00625336030498147 0.09455254673957825 v 0.13744251430034637 0.004262596368789673 0.09357324987649918 v 0.12819388508796692 0.002913061762228608 0.09343418478965759 v 0.13341882824897766 0.0032896308694034815 0.09212072938680649 v 0.11956632882356644 0.0005384162068367004 0.09720668196678162 v 0.11978227645158768 0.0037454182747751474 0.10009470582008362 v 0.13591329753398895 0.003115421161055565 0.09243221580982208 v 0.1414376050233841 0.003092440078034997 0.0983390212059021 v 0.14092478156089783 0.002636101096868515 0.09526831656694412 v 0.14035162329673767 0.002858113730326295 0.09966044872999191 v 0.13230286538600922 -0.005614439491182566 0.10208465158939362 v 0.13728801906108856 -0.003503291169181466 0.0992383360862732 v 0.13217933475971222 -0.0068447524681687355 0.09972946345806122 v 0.13746462762355804 -0.0040194489993155 0.0970582515001297 v 0.14081242680549622 -0.0011098869144916534 0.0978732705116272 v 0.14050474762916565 -0.00029730238020420074 0.09916521608829498 v 0.11824000626802444 -0.00016960875655058771 0.09832077473402023 v 0.11909108608961105 -0.00497772078961134 0.0967065840959549 v 0.12023139744997025 -0.004343898966908455 0.09581071138381958 v 0.12905673682689667 -0.0017059893580153584 0.09265042096376419 v 0.12187985330820084 -0.008190642111003399 0.0969175174832344 v 0.1253722608089447 -0.009524653665721416 0.09966295957565308 v 0.1312437653541565 -0.007211018819361925 0.09732699394226074 v 0.1304071992635727 -0.005472768563777208 0.09428226202726364 v 0.1370144933462143 -0.004915190860629082 0.09529690444469452 v 0.13478955626487732 -0.004163118079304695 0.09354081004858017 v 0.13370241224765778 -0.0003833081864286214 0.09156336635351181 v 0.14017125964164734 -0.002011124277487397 0.09424833208322525 v 0.1408814638853073 -0.0014756117016077042 0.09626971185207367 v 0.13964951038360596 0.0019788090139627457 0.09377981722354889 v 0.13780616223812103 -0.0022428466472774744 0.09286052733659744 v 0.13729874789714813 0.0010179132223129272 0.09224727749824524 v 0.1095760315656662 -0.016615884378552437 0.08758565783500671 v 0.11052798479795456 -0.020191552117466927 0.08374439179897308 v 0.10841742157936096 -0.020467484369874 0.08345778286457062 v 0.10719405859708786 -0.016919130459427834 0.08691997826099396 v 0.10714749991893768 -0.02206660993397236 0.09729550778865814 v 0.10840951651334763 -0.01814921945333481 0.09541823714971542 v 0.10426029562950134 -0.018168959766626358 0.09496451169252396 v 0.10168274492025375 -0.02199169248342514 0.09680542349815369 v 0.1085871085524559 -0.026991549879312515 0.09650623798370361 v 0.1013767272233963 -0.02784261852502823 0.09610500186681747 v 0.09658120572566986 -0.021498102694749832 0.09444044530391693 v 0.10032101720571518 -0.017769528552889824 0.09298742562532425 v 0.08988618105649948 -0.015648139640688896 0.0828501284122467 v 0.08648160845041275 -0.020051371306180954 0.08460512012243271 v 0.10898952931165695 -0.01650252379477024 0.09169723093509674 v 0.10607379674911499 -0.016543975099921227 0.09093539416790009 v 0.10670298337936401 -0.028388774022459984 0.08115784078836441 v 0.10762277245521545 -0.02452797256410122 0.08082887530326843 v 0.10924586653709412 -0.02500881813466549 0.08211183547973633 v 0.10859870910644531 -0.028557520359754562 0.08299507200717926 v 0.0949457660317421 -0.014483774080872536 0.07502264529466629 v 0.09551487118005753 -0.019120600074529648 0.07209043204784393 v 0.09338255226612091 -0.013986478559672832 0.0792342945933342 v 0.10377586632966995 -0.03176109120249748 0.08473232388496399 v 0.09916339814662933 -0.03209473937749863 0.08951728790998459 v 0.09009502828121185 -0.030594682320952415 0.07833980768918991 v 0.09386198222637177 -0.030068349093198776 0.0744277834892273 v 0.10315927118062973 -0.016214637085795403 0.08959729969501495 v 0.10694342106580734 -0.019693566486239433 0.0818173736333847 v 0.10554244369268417 -0.016409238800406456 0.08531935513019562 v 0.09616407006978989 -0.026851776987314224 0.09265515208244324 v 0.10445668548345566 -0.032046739012002945 0.09190448373556137 v 0.12440983951091766 -0.029536955058574677 0.08964323252439499 v 0.110344298183918 -0.031860072165727615 0.0874260887503624 v 0.11092961579561234 -0.028540683910250664 0.0833253562450409 v 0.12474595755338669 -0.027993855997920036 0.08590269833803177 v 0.10729695856571198 -0.03202817216515541 0.08662267029285431 v 0.10907372832298279 -0.03140468895435333 0.09252336621284485 v 0.12305568158626556 -0.015860363841056824 0.08769822865724564 v 0.12329458445310593 -0.019741596654057503 0.08452440053224564 v 0.12173467129468918 -0.015603824518620968 0.09147083759307861 v 0.08590803295373917 -0.026155725121498108 0.08293206989765167 v 0.09640762954950333 -0.026218993589282036 0.07139524817466736 v 0.12181458622217178 -0.019476499408483505 0.09702539443969727 v 0.12163597345352173 -0.01650325581431389 0.09444383531808853 v 0.11088816821575165 -0.02478843927383423 0.08239825814962387 v 0.12425405532121658 -0.024658771231770515 0.08374037593603134 v 0.12295478582382202 -0.028887292370200157 0.0936700701713562 v 0.12127089500427246 -0.02483643777668476 0.09705769270658493 v 0.12844830751419067 -0.027866505086421967 0.09307372570037842 v 0.12707029283046722 -0.023851947858929634 0.09646270424127579 v 0.12724201381206512 -0.018759028986096382 0.09688860177993774 v 0.12630492448806763 -0.01590782403945923 0.09430805593729019 v 0.1258469820022583 -0.01487682107836008 0.09135432541370392 v 0.12922212481498718 -0.028047451749444008 0.08869515359401703 v 0.1287967562675476 -0.026378409937024117 0.08551767468452454 v 0.12595561146736145 -0.0235277209430933 0.08430075645446777 v 0.13270562887191772 -0.02673397772014141 0.08673324435949326 v 0.13472497463226318 -0.02587597444653511 0.09133416414260864 v 0.14288993179798126 -0.013181854970753193 0.09015388786792755 v 0.1382373720407486 -0.01460975967347622 0.09212429076433182 v 0.1387365758419037 -0.015668341889977455 0.0922546312212944 v 0.1436527669429779 -0.01438334584236145 0.09067200869321823 v 0.13390889763832092 -0.017624683678150177 0.09518097341060638 v 0.1355418860912323 -0.018122971057891846 0.09452484548091888 v 0.13551238179206848 -0.021629348397254944 0.0940568670630455 v 0.14058460295200348 -0.019915694370865822 0.09154394268989563 v 0.13957111537456512 -0.02349298819899559 0.08770479261875153 v 0.14361223578453064 -0.021253276616334915 0.08641652762889862 v 0.14506292343139648 -0.018299361690878868 0.0899755209684372 v 0.1360955834388733 -0.024486901238560677 0.09120263159275055 v 0.14630025625228882 -0.01440724078565836 0.08931579440832138 v 0.1468389481306076 -0.012528783641755581 0.08947775512933731 v 0.1336020976305008 -0.022365108132362366 0.09514329582452774 v 0.13117633759975433 -0.014368116855621338 0.09391950070858002 v 0.13711103796958923 -0.012423975393176079 0.09102172404527664 v 0.14179855585098267 -0.010468833148479462 0.08897820860147476 v 0.14528124034404755 -0.011010020039975643 0.08682664483785629 v 0.13575328886508942 -0.011703581549227238 0.08797794580459595 v 0.14033447206020355 -0.010456173680722713 0.086470827460289 v 0.1435161978006363 -0.010838608257472515 0.08461030572652817 v 0.13496731221675873 -0.012413134798407555 0.08519537001848221 v 0.13919849693775177 -0.011665272526443005 0.08403735607862473 v 0.12714189291000366 -0.015014897100627422 0.08786505460739136 v 0.12882135808467865 -0.01385860051959753 0.09104901552200317 v 0.14203979074954987 -0.011701948009431362 0.08333799242973328 v 0.14851023256778717 -0.015952996909618378 0.087407186627388 v 0.14726553857326508 -0.014612779021263123 0.08392780274152756 v 0.1470978856086731 -0.016681430861353874 0.08811084926128387 v 0.1386866271495819 -0.024363934993743896 0.08652867376804352 v 0.14392071962356567 -0.02192476950585842 0.08441463112831116 v 0.13753776252269745 -0.024160267785191536 0.08415449410676956 v 0.14276373386383057 -0.021789811551570892 0.08221741020679474 v 0.14711010456085205 -0.019594179466366768 0.08487527072429657 v 0.1466628611087799 -0.01945173367857933 0.08584865927696228 v 0.12507112324237823 -0.016138751059770584 0.08801154047250748 v 0.1250620186328888 -0.01945568434894085 0.08499415963888168 v 0.12672342360019684 -0.018030479550361633 0.08485066145658493 v 0.13499262928962708 -0.015015832148492336 0.08198078721761703 v 0.12755253911018372 -0.02201845496892929 0.08362459391355515 v 0.13193221390247345 -0.02468089759349823 0.08402301371097565 v 0.13647852838039398 -0.02216380275785923 0.08217626810073853 v 0.1358475387096405 -0.01896696723997593 0.08109667152166367 v 0.141312375664711 -0.02028404362499714 0.08067960292100906 v 0.13966237008571625 -0.018258867785334587 0.08075018972158432 v 0.13905619084835052 -0.013918456621468067 0.08117491751909256 v 0.14415103197097778 -0.017706168815493584 0.08139318972826004 v 0.14611321687698364 -0.01896422915160656 0.08261416852474213 v 0.14501075446605682 -0.013765060342848301 0.08226287364959717 v 0.1423063427209854 -0.016569796949625015 0.08075698465108871 v 0.14283911883831024 -0.013547507114708424 0.08142600953578949 v 0.09640948474407196 -0.02291903831064701 0.0707865059375763 v 0.11555365473031998 -0.03463287651538849 0.07482092827558517 v 0.11637800931930542 -0.036234669387340546 0.07152833044528961 v 0.1152157261967659 -0.03715549781918526 0.07131767272949219 v 0.11340268701314926 -0.034956205636262894 0.0740366280078888 v 0.11262009292840958 -0.04165138304233551 0.08157122880220413 v 0.11372382193803787 -0.03766936808824539 0.08073669672012329 v 0.10918040573596954 -0.038049448281526566 0.08034078776836395 v 0.1078503280878067 -0.04178611561655998 0.08103957027196884 v 0.1129443496465683 -0.045806992799043655 0.07955830544233322 v 0.10869317501783371 -0.04607894644141197 0.07875346392393112 v 0.10454851388931274 -0.04105950519442558 0.07884945720434189 v 0.10591476410627365 -0.03722427412867546 0.07834935933351517 v 0.09471819549798965 -0.033276867121458054 0.06806597858667374 v 0.09210982173681259 -0.03744085505604744 0.06635653227567673 v 0.10287626832723618 -0.04120049625635147 0.0532560832798481 v 0.1038723811507225 -0.03621189668774605 0.05280766263604164 v 0.10788387805223465 -0.03837212547659874 0.059563782066106796 v 0.10601241141557693 -0.04260322451591492 0.05876469612121582 v 0.11471642553806305 -0.03540494665503502 0.07811713963747025 v 0.11106940358877182 -0.035143524408340454 0.07745856046676636 v 0.11442932486534119 -0.04521026834845543 0.0677284300327301 v 0.11513736099004745 -0.04079146683216095 0.06801683455705643 v 0.11594807356595993 -0.039926741272211075 0.06897318363189697 v 0.11634797602891922 -0.044014230370521545 0.06829552352428436 v 0.1034734845161438 -0.03206121176481247 0.05595438554883003 v 0.10098595917224884 -0.03020869567990303 0.05955047532916069 v 0.10398795455694199 -0.030506044626235962 0.0626780092716217 v 0.1077612042427063 -0.03453320637345314 0.06220429763197899 v 0.10053461045026779 -0.030150016769766808 0.06676967442035675 v 0.11220576614141464 -0.04800565913319588 0.06949389725923538 v 0.10865067690610886 -0.04905819520354271 0.07329204678535461 v 0.09821804612874985 -0.047106582671403885 0.0600256584584713 v 0.10195900499820709 -0.04547635093331337 0.05843530222773552 v 0.10922293365001678 -0.03513436019420624 0.07689525932073593 v 0.11404668539762497 -0.037273213267326355 0.07005821913480759 v 0.11283030360937119 -0.03526827692985535 0.07361394912004471 v 0.10511423647403717 -0.045974042266607285 0.07685314863920212 v 0.11187732219696045 -0.04838947206735611 0.07453969120979309 v 0.12492034584283829 -0.04505646228790283 0.0712180882692337 v 0.11709708720445633 -0.04675217345356941 0.07012289017438889 v 0.11787078529596329 -0.04292157664895058 0.06794553250074387 v 0.12490996718406677 -0.04279274493455887 0.06979856640100479 v 0.11501188576221466 -0.04716724902391434 0.07049418240785599 v 0.11571966111660004 -0.047947902232408524 0.07481832802295685 v 0.12322351336479187 -0.03373130410909653 0.07569180428981781 v 0.12351220846176147 -0.0362832210958004 0.07172036170959473 v 0.12283299118280411 -0.03419327735900879 0.07845614850521088 v 0.0928882583975792 -0.04316134378314018 0.06348787248134613 v 0.1226518452167511 -0.03992471843957901 0.08181563019752502 v 0.12309779971837997 -0.03609746694564819 0.08093160390853882 v 0.11736834049224854 -0.038977235555648804 0.06913308054208755 v 0.12421475350856781 -0.03959062322974205 0.06982284784317017 v 0.12429871410131454 -0.046326544135808945 0.07478681206703186 v 0.12267161160707474 -0.04461805522441864 0.07975012809038162 v 0.12883834540843964 -0.04487496614456177 0.07487255334854126 v 0.12736301124095917 -0.04319288954138756 0.07996422052383423 v 0.127131387591362 -0.03816736862063408 0.08170734345912933 v 0.12603113055229187 -0.035268835723400116 0.08053924888372421 v 0.12550592422485352 -0.033567871898412704 0.0784558579325676 v 0.12866318225860596 -0.04372087121009827 0.07105052471160889 v 0.1279785931110382 -0.04150904342532158 0.06959593296051025 v 0.1264481395483017 -0.03854823485016823 0.06956078857183456 v 0.13232965767383575 -0.04210575297474861 0.07086850702762604 v 0.1340535581111908 -0.04238269105553627 0.07472100853919983 v 0.13880136609077454 -0.03165511414408684 0.07741370052099228 v 0.13542649149894714 -0.033040665090084076 0.07862737029790878 v 0.13594995439052582 -0.03406298905611038 0.0786876231431961 v 0.1393207609653473 -0.0323011688888073 0.07808571308851242 v 0.1319623589515686 -0.036194488406181335 0.08028090000152588 v 0.13332200050354004 -0.03672036528587341 0.07967299222946167 v 0.13308881223201752 -0.03970407694578171 0.07857070863246918 v 0.13734233379364014 -0.03740420192480087 0.0775524377822876 v 0.13829205930233002 -0.03963065892457962 0.07344000786542892 v 0.1414940059185028 -0.037472229450941086 0.07314655929803848 v 0.14053772389888763 -0.035912539809942245 0.07689360529184341 v 0.13516783714294434 -0.04138747975230217 0.07574692368507385 v 0.1418166607618332 -0.032181546092033386 0.07738256454467773 v 0.14238114655017853 -0.031152108684182167 0.07717783749103546 v 0.13185366988182068 -0.04066065698862076 0.07921022176742554 v 0.12944656610488892 -0.033516060560941696 0.07966123521327972 v 0.1350087672472 -0.031009618192911148 0.07789479941129684 v 0.13936485350131989 -0.029799913987517357 0.07662581652402878 v 0.1425800770521164 -0.030233165249228477 0.07537197321653366 v 0.1335320919752121 -0.030230866745114326 0.07623272389173508 v 0.13862499594688416 -0.02862175554037094 0.07496988028287888 v 0.14167673885822296 -0.029169240966439247 0.07361249625682831 v 0.13245542347431183 -0.030128996819257736 0.07342970371246338 v 0.13753098249435425 -0.029064161702990532 0.07282303273677826 v 0.12692132592201233 -0.03242115676403046 0.07430781424045563 v 0.12801849842071533 -0.0323813334107399 0.07733704894781113 v 0.14034420251846313 -0.02949734777212143 0.07257416844367981 v 0.14422136545181274 -0.033513836562633514 0.07553848624229431 v 0.14390791952610016 -0.03197803348302841 0.07348647713661194 v 0.1434841752052307 -0.03441876545548439 0.0759851261973381 v 0.13802334666252136 -0.03986458480358124 0.07232829183340073 v 0.1417936533689499 -0.03731865435838699 0.07187829911708832 v 0.13720126450061798 -0.03933681547641754 0.07021438330411911 v 0.14137981832027435 -0.03622209280729294 0.07032937556505203 v 0.14418812096118927 -0.03538662567734718 0.07289806008338928 v 0.14323025941848755 -0.03588739037513733 0.07411963492631912 v 0.1253904104232788 -0.033083509653806686 0.07484007626771927 v 0.1253831535577774 -0.03543032705783844 0.07170548290014267 v 0.12719188630580902 -0.03469128906726837 0.07112689316272736 v 0.13246840238571167 -0.031955499202013016 0.07035962492227554 v 0.128432959318161 -0.037773650139570236 0.06905286014080048 v 0.1305241584777832 -0.04047928377985954 0.06930394470691681 v 0.13590747117996216 -0.037656571716070175 0.06891538202762604 v 0.13427859544754028 -0.03507319092750549 0.06853337585926056 v 0.140676349401474 -0.03467491269111633 0.06937180459499359 v 0.13886302709579468 -0.032644983381032944 0.06904475390911102 v 0.1375000774860382 -0.030431805178523064 0.07029496133327484 v 0.1427265852689743 -0.03256295621395111 0.07090723514556885 v 0.14379926025867462 -0.03371872007846832 0.07161907106637955 v 0.14277727901935577 -0.03106234036386013 0.07217742502689362 v 0.14133180677890778 -0.03154513239860535 0.07038559764623642 v 0.14087049663066864 -0.030500903725624084 0.0712389424443245 v 0.10087884217500687 -0.043712932616472244 0.055240076035261154 v 0.1051640510559082 0.03852478787302971 0.05778120085597038 v 0.10518199950456619 0.03387000784277916 0.05965564027428627 v 0.11939319968223572 0.03038926236331463 0.059217486530542374 v 0.11351389437913895 0.028928274288773537 0.06133124232292175 v 0.12266989797353745 0.03502143546938896 0.05674109607934952 v 0.11874741315841675 0.04317871853709221 0.052810944616794586 v 0.12178151309490204 0.039296869188547134 0.053744908422231674 v 0.10870464891195297 0.030453111976385117 0.06126449629664421 v 0.10724687576293945 0.04252826049923897 0.055330872535705566 v 0.1129489541053772 0.04502785950899124 0.05280112847685814 v 0.11090394109487534 0.045472461730241776 0.06210560351610184 v 0.1167549192905426 0.04696273431181908 0.05919528380036354 v 0.12272004038095474 0.04462628439068794 0.058877892792224884 v 0.12496976554393768 0.03970523923635483 0.05928201600909233 v 0.12550903856754303 0.03566904738545418 0.060544684529304504 v 0.10817193984985352 0.04020961746573448 0.06370847672224045 v 0.10827053338289261 0.0355290062725544 0.0653655156493187 v 0.11149489134550095 0.030997347086668015 0.06540606170892715 v 0.11117707937955856 0.041315946727991104 0.07133372128009796 v 0.1178535595536232 0.04543782025575638 0.07687834650278091 v 0.13446548581123352 0.04308575391769409 0.0816866010427475 v 0.1325179636478424 0.042190633714199066 0.07598987221717834 v 0.13096405565738678 0.04427921772003174 0.07706297188997269 v 0.13315165042877197 0.04532121121883392 0.08194775879383087 v 0.12979654967784882 0.04374125227332115 0.07222718745470047 v 0.12871159613132477 0.044718723744153976 0.07401075214147568 v 0.1237979307770729 0.0461345873773098 0.07464640587568283 v 0.1260792464017868 0.047007832676172256 0.07924411445856094 v 0.1202850267291069 0.045597318559885025 0.07757969200611115 v 0.12099585682153702 0.04521786794066429 0.081334687769413 v 0.1281311810016632 0.0475325733423233 0.08388058841228485 v 0.1331184357404709 0.04686668887734413 0.08528085052967072 v 0.13000676035881042 0.04762162268161774 0.08771510422229767 v 0.1342526525259018 0.04440072923898697 0.08630099147558212 v 0.12354106456041336 0.048041753470897675 0.07390006631612778 v 0.1297176480293274 0.03986872360110283 0.06704854965209961 v 0.13280314207077026 0.038916293531656265 0.0743185505270958 v 0.1343654841184616 0.039632026106119156 0.08135875314474106 v 0.133956640958786 0.04148607328534126 0.08673477172851562 v 0.13148120045661926 0.0350736603140831 0.07419858872890472 v 0.13217754662036896 0.0360928475856781 0.08089737594127655 v 0.13109169900417328 0.03783329203724861 0.08589178323745728 v 0.128106951713562 0.032354965806007385 0.07522817701101303 v 0.12901556491851807 0.034297164529561996 0.08123848587274551 v 0.12334364652633667 0.03128392994403839 0.06477745622396469 v 0.1278221309185028 0.035046420991420746 0.06458807736635208 v 0.12911275029182434 0.03640327230095863 0.08474811166524887 v 0.13060098886489868 0.04663725942373276 0.0897684320807457 v 0.13004396855831146 0.04319164156913757 0.0903364047408104 v 0.11826733499765396 0.04372299835085869 0.08154419809579849 v 0.12281353026628494 0.046459998935461044 0.08575589954853058 v 0.12122657150030136 0.044250812381505966 0.08639732748270035 v 0.11589593440294266 0.040840473026037216 0.08083096891641617 v 0.12005145847797394 0.04173114895820618 0.08674366772174835 v 0.1251567155122757 0.04564044624567032 0.08962538838386536 v 0.12593677639961243 0.0472341850399971 0.08793806284666061 v 0.12220243364572525 0.031029677018523216 0.061788566410541534 v 0.1163644939661026 0.029354281723499298 0.06348821520805359 v 0.11749694496393204 0.029980121180415154 0.06666118651628494 v 0.12229026108980179 0.03153235837817192 0.07639746367931366 v 0.1129160150885582 0.03190784528851509 0.06962337344884872 v 0.11068496108055115 0.03690909966826439 0.07119645178318024 v 0.11556120961904526 0.0372353233397007 0.08028476685285568 v 0.11757533997297287 0.033564526587724686 0.07849548012018204 v 0.1203417107462883 0.038381341844797134 0.0860460102558136 v 0.12163040786981583 0.03626030683517456 0.08470739424228668 v 0.1253446489572525 0.03419932350516319 0.08295675367116928 v 0.12429992854595184 0.03960695117712021 0.08875499665737152 v 0.12424265593290329 0.04269115626811981 0.08990246802568436 v 0.12830759584903717 0.039398033171892166 0.08876646310091019 v 0.12416199594736099 0.037653349339962006 0.08682838082313538 v 0.12687736749649048 0.037137895822525024 0.08641650527715683 v 0.10233891755342484 -0.03636704757809639 0.0490579791367054 v 0.10220561921596527 -0.03123542293906212 0.0518113374710083 v 0.10244607925415039 -0.03204593062400818 0.046612225472927094 v 0.10412950068712234 -0.03131403028964996 0.03901771828532219 v 0.10383128374814987 -0.03480549156665802 0.030231984332203865 v 0.10297253727912903 -0.025509515777230263 0.04043158143758774 v 0.1010696142911911 -0.02697722800076008 0.04863359406590462 v 0.09973923861980438 -0.026383088901638985 0.05648477375507355 v 0.10157529264688492 -0.018894892185926437 0.03418475762009621 f 2/2 3/3 1/1 f 1/1 3/3 4/4 f 5/5 6/6 8/8 f 8/8 6/6 7/7 f 9/9 4/4 10/10 f 10/10 4/4 3/3 f 12/12 13/13 11/11 f 11/11 13/13 9/9 f 14/14 12/12 16/16 f 16/16 12/12 15/15 f 18/18 19/19 17/17 f 17/17 19/19 20/20 f 22/22 23/23 21/21 f 21/21 23/23 24/24 f 26/26 27/27 25/25 f 25/25 27/27 28/28 f 30/30 31/31 29/29 f 29/29 31/31 32/32 f 33/33 34/34 36/36 f 36/36 34/34 35/35 f 37/37 38/38 40/40 f 40/40 38/38 39/39 f 41/41 42/42 6/6 f 6/6 42/42 43/43 f 6/6 43/43 7/7 f 7/7 43/43 44/44 f 45/45 34/34 46/46 f 46/46 34/34 33/33 f 48/48 49/49 47/47 f 47/47 49/49 50/50 f 52/52 53/53 51/51 f 51/51 53/53 54/54 f 56/56 52/52 55/55 f 55/55 52/52 51/51 f 58/58 59/59 57/57 f 57/57 59/59 60/60 f 61/61 62/62 4/4 f 4/4 62/62 1/1 f 64/64 65/65 63/63 f 63/63 65/65 66/66 f 68/68 69/69 67/67 f 67/67 69/69 70/70 f 72/72 73/73 71/71 f 71/71 73/73 74/74 f 76/76 77/77 75/75 f 75/75 77/77 78/78 f 53/53 79/79 54/54 f 54/54 79/79 80/80 f 82/82 83/83 81/81 f 81/81 83/83 84/84 f 85/85 86/86 52/52 f 52/52 86/86 53/53 f 57/57 60/60 87/87 f 87/87 60/60 88/88 f 89/89 90/90 43/43 f 43/43 90/90 44/44 f 43/43 42/42 89/89 f 89/89 42/42 91/91 f 40/40 39/39 92/92 f 92/92 39/39 93/93 f 94/94 70/70 64/64 f 64/64 70/70 69/69 f 13/13 61/61 9/9 f 9/9 61/61 4/4 f 25/25 28/28 69/69 f 69/69 28/28 95/95 f 96/96 25/25 68/68 f 68/68 25/25 69/69 f 98/98 99/99 97/97 f 97/97 99/99 100/100 f 101/101 102/102 104/104 f 104/104 102/102 103/103 f 106/106 30/30 105/105 f 105/105 30/30 29/29 f 51/51 54/54 107/107 f 107/107 54/54 108/108 f 54/54 80/80 108/108 f 108/108 80/80 109/109 f 111/111 112/112 110/110 f 110/110 112/112 113/113 f 115/115 5/5 114/114 f 114/114 5/5 116/116 f 115/115 41/41 5/5 f 5/5 41/41 6/6 f 36/36 35/35 111/111 f 111/111 35/35 117/117 f 35/35 118/118 117/117 f 117/117 118/118 119/119 f 34/34 120/120 35/35 f 35/35 120/120 118/118 f 34/34 45/45 120/120 f 120/120 45/45 121/121 f 125/125 126/126 124/124 f 124/124 126/126 127/127 f 128/128 129/129 14/14 f 14/14 129/129 130/130 f 33/33 131/131 46/46 f 46/46 131/131 132/132 f 133/133 94/94 63/63 f 63/63 94/94 64/64 f 134/134 135/135 137/137 f 137/137 135/135 136/136 f 139/139 140/140 138/138 f 138/138 140/140 141/141 f 77/77 142/142 78/78 f 78/78 142/142 143/143 f 144/144 145/145 20/20 f 20/20 145/145 146/146 f 148/148 149/149 147/147 f 147/147 149/149 72/72 f 151/151 152/152 150/150 f 150/150 152/152 153/153 f 82/82 101/101 83/83 f 83/83 101/101 104/104 f 101/101 82/82 155/155 f 155/155 82/82 154/154 f 156/156 157/157 58/58 f 58/58 157/157 59/59 f 158/158 68/68 147/147 f 147/147 68/68 67/67 f 159/159 146/146 15/15 f 15/15 146/146 16/16 f 68/68 158/158 96/96 f 96/96 158/158 160/160 f 129/129 66/66 130/130 f 130/130 66/66 65/65 f 162/162 163/163 161/161 f 161/161 163/163 164/164 f 166/166 167/167 165/165 f 165/165 167/167 168/168 f 170/170 171/171 169/169 f 169/169 171/171 172/172 f 174/174 171/171 173/173 f 173/173 171/171 170/170 f 176/176 177/177 175/175 f 175/175 177/177 178/178 f 180/180 181/181 179/179 f 179/179 181/181 24/24 f 182/182 183/183 21/21 f 21/21 183/183 184/184 f 81/81 185/185 82/82 f 82/82 185/185 154/154 f 186/186 187/187 188/188 f 188/188 187/187 144/144 f 158/158 71/71 160/160 f 160/160 71/71 189/189 f 190/190 135/135 157/157 f 157/157 135/135 59/59 f 169/169 172/172 139/139 f 139/139 172/172 140/140 f 147/147 72/72 158/158 f 158/158 72/72 71/71 f 192/192 193/193 191/191 f 191/191 193/193 194/194 f 167/167 166/166 49/49 f 49/49 166/166 195/195 f 196/196 190/190 50/50 f 50/50 190/190 157/157 f 197/197 198/198 200/200 f 200/200 198/198 199/199 f 21/21 24/24 182/182 f 182/182 24/24 181/181 f 146/146 159/159 20/20 f 20/20 159/159 17/17 f 182/182 181/181 81/81 f 81/81 181/181 185/185 f 201/201 185/185 180/180 f 180/180 185/185 181/181 f 202/202 203/203 83/83 f 83/83 203/203 84/84 f 205/205 206/206 204/204 f 204/204 206/206 85/85 f 207/207 22/22 184/184 f 184/184 22/22 21/21 f 179/179 24/24 208/208 f 208/208 24/24 23/23 f 208/208 209/209 179/179 f 179/179 209/209 205/205 f 209/209 210/210 205/205 f 205/205 210/210 206/206 f 212/212 206/206 211/211 f 211/211 206/206 210/210 f 179/179 205/205 180/180 f 180/180 205/205 204/204 f 213/213 176/176 88/88 f 88/88 176/176 214/214 f 86/86 85/85 212/212 f 212/212 85/85 206/206 f 193/193 217/217 218/218 f 217/217 219/219 218/218 f 218/218 219/219 220/220 f 219/219 18/18 220/220 f 220/220 18/18 17/17 f 19/19 221/221 20/20 f 20/20 221/221 144/144 f 222/222 223/223 225/225 f 225/225 223/223 224/224 f 175/175 226/226 176/176 f 176/176 226/226 214/214 f 227/227 87/87 214/214 f 214/214 87/87 88/88 f 220/220 17/17 228/228 f 228/228 17/17 159/159 f 134/134 213/213 60/60 f 60/60 213/213 88/88 f 138/138 229/229 151/151 f 151/151 229/229 152/152 f 193/193 192/192 210/210 f 210/210 192/192 211/211 f 230/230 194/194 218/218 f 218/218 194/194 193/193 f 231/231 232/232 228/228 f 228/228 232/232 230/230 f 233/233 234/234 91/91 f 91/91 234/234 89/89 f 235/235 236/236 93/93 f 93/93 236/236 92/92 f 230/230 232/232 234/234 f 234/234 232/232 237/237 f 47/47 238/238 48/48 f 48/48 238/238 239/239 f 240/240 191/191 235/235 f 235/235 191/191 236/236 f 5/5 8/8 116/116 f 116/116 8/8 241/241 f 242/242 243/243 189/189 f 189/189 243/243 160/160 f 244/244 245/245 98/98 f 98/98 245/245 99/99 f 156/156 246/246 47/47 f 47/47 246/246 238/238 f 76/76 247/247 77/77 f 77/77 247/247 248/248 f 250/250 125/125 249/249 f 249/249 125/125 124/124 f 252/252 253/253 251/251 f 251/251 253/253 254/254 f 111/111 110/110 36/36 f 36/36 110/110 255/255 f 256/256 33/33 255/255 f 255/255 33/33 36/36 f 257/257 258/258 154/154 f 154/154 258/258 155/155 f 63/63 169/169 133/133 f 133/133 169/169 139/139 f 66/66 170/170 63/63 f 63/63 170/170 169/169 f 173/173 170/170 129/129 f 129/129 170/170 66/66 f 129/129 128/128 173/173 f 173/173 128/128 259/259 f 128/128 260/260 259/259 f 259/259 260/260 261/261 f 213/213 134/134 262/262 f 262/262 134/134 137/137 f 263/263 264/264 186/186 f 186/186 264/264 187/187 f 112/112 265/265 113/113 f 113/113 265/265 266/266 f 11/11 267/267 268/268 f 234/234 233/233 230/230 f 230/230 233/233 194/194 f 153/153 269/269 70/70 f 70/70 269/269 67/67 f 175/175 178/178 165/165 f 165/165 178/178 141/141 f 150/150 153/153 94/94 f 94/94 153/153 70/70 f 271/271 221/221 270/270 f 270/270 221/221 207/207 f 269/269 153/153 272/272 f 272/272 153/153 152/152 f 121/121 45/45 109/109 f 109/109 45/45 108/108 f 47/47 50/50 156/156 f 156/156 50/50 157/157 f 57/57 273/273 58/58 f 58/58 273/273 274/274 f 145/145 275/275 260/260 f 260/260 275/275 261/261 f 276/276 149/149 143/143 f 143/143 149/149 78/78 f 148/148 269/269 75/75 f 75/75 269/269 272/272 f 207/207 277/277 270/270 f 270/270 277/277 278/278 f 195/195 196/196 49/49 f 49/49 196/196 50/50 f 59/59 135/135 60/60 f 60/60 135/135 134/134 f 83/83 104/104 202/202 f 202/202 104/104 279/279 f 149/149 148/148 78/78 f 78/78 148/148 75/75 f 247/247 278/278 248/248 f 248/248 278/278 277/277 f 183/183 182/182 84/84 f 84/84 182/182 81/81 f 48/48 239/239 281/281 f 281/281 239/239 282/282 f 227/227 223/223 283/283 f 283/283 223/223 222/222 f 223/223 226/226 224/224 f 224/224 226/226 168/168 f 281/281 282/282 224/224 f 224/224 282/282 225/225 f 165/165 168/168 175/175 f 175/175 168/168 226/226 f 264/264 263/263 138/138 f 138/138 263/263 229/229 f 14/14 16/16 128/128 f 128/128 16/16 260/260 f 220/220 228/228 218/218 f 218/218 228/228 230/230 f 87/87 227/227 284/284 f 284/284 227/227 283/283 f 260/260 16/16 145/145 f 145/145 16/16 146/146 f 244/244 98/98 258/258 f 258/258 98/98 155/155 f 58/58 274/274 156/156 f 156/156 274/274 246/246 f 107/107 285/285 51/51 f 51/51 285/285 55/55 f 243/243 286/286 160/160 f 160/160 286/286 96/96 f 234/234 237/237 89/89 f 89/89 237/237 90/90 f 46/46 132/132 107/107 f 107/107 132/132 285/285 f 253/253 252/252 249/249 f 249/249 252/252 250/250 f 286/286 26/26 96/96 f 96/96 26/26 25/25 f 106/106 105/105 287/287 f 287/287 105/105 288/288 f 272/272 152/152 289/289 f 289/289 152/152 229/229 f 138/138 151/151 139/139 f 139/139 151/151 133/133 f 183/183 290/290 161/161 f 161/161 290/290 162/162 f 291/291 292/292 277/277 f 277/277 292/292 293/293 f 151/151 150/150 133/133 f 133/133 150/150 94/94 f 262/262 275/275 177/177 f 177/177 275/275 187/187 f 144/144 187/187 145/145 f 145/145 187/187 275/275 f 273/273 57/57 284/284 f 284/284 57/57 87/87 f 174/174 136/136 190/190 f 190/190 136/136 135/135 f 111/111 117/117 112/112 f 112/112 117/117 38/38 f 117/117 119/119 38/38 f 38/38 119/119 123/123 f 112/112 38/38 265/265 f 265/265 38/38 37/37 f 287/287 288/288 254/254 f 254/254 288/288 251/251 f 228/228 159/159 231/231 f 231/231 159/159 15/15 f 223/223 227/227 226/226 f 226/226 227/227 214/214 f 147/147 67/67 148/148 f 148/148 67/67 269/269 f 224/224 168/168 281/281 f 281/281 168/168 167/167 f 199/199 163/163 200/200 f 200/200 163/163 162/162 f 45/45 46/46 108/108 f 108/108 46/46 107/107 f 281/281 167/167 48/48 f 48/48 167/167 49/49 f 161/161 164/164 291/291 f 291/291 164/164 292/292 f 38/38 123/123 39/39 f 293/293 294/294 277/277 f 277/277 294/294 248/248 f 284/284 283/283 296/296 f 296/296 283/283 295/295 f 284/284 296/296 273/273 f 273/273 296/296 297/297 f 274/274 273/273 298/298 f 298/298 273/273 297/297 f 246/246 274/274 299/299 f 299/299 274/274 298/298 f 283/283 222/222 295/295 f 295/295 222/222 300/300 f 222/222 225/225 300/300 f 300/300 225/225 301/301 f 301/301 225/225 302/302 f 302/302 225/225 282/282 f 303/303 304/304 300/300 f 300/300 304/304 295/295 f 306/306 307/307 305/305 f 305/305 307/307 308/308 f 309/309 310/310 308/308 f 308/308 310/310 305/305 f 308/308 307/307 312/312 f 312/312 307/307 311/311 f 313/313 314/314 312/312 f 312/312 314/314 315/315 f 311/311 316/316 312/312 f 312/312 316/316 313/313 f 317/317 304/304 311/311 f 311/311 304/304 316/316 f 315/315 309/309 312/312 f 312/312 309/309 308/308 f 318/318 319/319 321/321 f 321/321 319/319 320/320 f 319/319 318/318 309/309 f 309/309 318/318 310/310 f 311/311 307/307 317/317 f 317/317 307/307 306/306 f 306/306 297/297 317/317 f 317/317 297/297 296/296 f 306/306 322/322 297/297 f 297/297 322/322 298/298 f 305/305 323/323 306/306 f 306/306 323/323 322/322 f 323/323 305/305 324/324 f 324/324 305/305 310/310 f 304/304 317/317 295/295 f 295/295 317/317 296/296 f 318/318 325/325 310/310 f 310/310 325/325 324/324 f 323/323 324/324 326/326 f 326/326 324/324 327/327 f 324/324 325/325 327/327 f 327/327 325/325 328/328 f 326/326 327/327 329/329 f 329/329 327/327 330/330 f 329/329 331/331 326/326 f 326/326 331/331 332/332 f 333/333 330/330 328/328 f 328/328 330/330 327/327 f 323/323 326/326 322/322 f 322/322 326/326 332/332 f 322/322 332/332 298/298 f 298/298 332/332 299/299 f 325/325 318/318 334/334 f 334/334 318/318 321/321 f 313/313 316/316 335/335 f 335/335 316/316 304/304 f 335/335 336/336 313/313 f 313/313 336/336 314/314 f 304/304 303/303 335/335 f 335/335 303/303 337/337 f 336/336 335/335 338/338 f 338/338 335/335 337/337 f 336/336 339/339 314/314 f 314/314 339/339 340/340 f 246/246 299/299 238/238 f 238/238 299/299 341/341 f 239/239 342/342 282/282 f 282/282 342/342 302/302 f 342/342 239/239 341/341 f 341/341 239/239 238/238 f 341/341 331/331 342/342 f 342/342 331/331 343/343 f 331/331 329/329 343/343 f 343/343 329/329 344/344 f 342/342 343/343 302/302 f 302/302 343/343 345/345 f 341/341 299/299 331/331 f 331/331 299/299 332/332 f 346/346 301/301 345/345 f 345/345 301/301 302/302 f 346/346 303/303 301/301 f 301/301 303/303 300/300 f 347/347 337/337 346/346 f 346/346 337/337 303/303 f 347/347 346/346 348/348 f 348/348 346/346 345/345 f 349/349 347/347 350/350 f 350/350 347/347 348/348 f 343/343 344/344 345/345 f 345/345 344/344 348/348 f 344/344 351/351 348/348 f 348/348 351/351 350/350 f 337/337 347/347 338/338 f 338/338 347/347 349/349 f 353/353 338/338 352/352 f 352/352 338/338 349/349 f 352/352 355/355 354/354 f 354/354 355/355 356/356 f 352/352 349/349 355/355 f 355/355 349/349 350/350 f 352/352 354/354 353/353 f 353/353 354/354 334/334 f 353/353 334/334 339/339 f 339/339 334/334 321/321 f 339/339 336/336 353/353 f 353/353 336/336 338/338 f 329/329 330/330 344/344 f 344/344 330/330 351/351 f 356/356 351/351 333/333 f 333/333 351/351 330/330 f 356/356 355/355 351/351 f 351/351 355/355 350/350 f 354/354 356/356 328/328 f 328/328 356/356 333/333 f 328/328 325/325 354/354 f 354/354 325/325 334/334 f 309/309 315/315 319/319 f 319/319 315/315 320/320 f 320/320 340/340 321/321 f 321/321 340/340 339/339 f 320/320 315/315 340/340 f 340/340 315/315 314/314 f 137/137 136/136 261/261 f 261/261 136/136 259/259 f 140/140 166/166 141/141 f 141/141 166/166 165/165 f 172/172 171/171 195/195 f 195/195 171/171 196/196 f 171/171 174/174 196/196 f 196/196 174/174 190/190 f 178/178 177/177 264/264 f 264/264 177/177 187/187 f 172/172 195/195 140/140 f 140/140 195/195 166/166 f 137/137 261/261 262/262 f 262/262 261/261 275/275 f 178/178 264/264 141/141 f 141/141 264/264 138/138 f 262/262 177/177 213/213 f 213/213 177/177 176/176 f 136/136 174/174 259/259 f 259/259 174/174 173/173 f 358/358 359/359 357/357 f 357/357 359/359 360/360 f 362/362 363/363 361/361 f 361/361 363/363 364/364 f 361/361 364/364 365/365 f 365/365 364/364 366/366 f 367/367 368/368 370/370 f 370/370 368/368 369/369 f 76/76 371/371 247/247 f 247/247 371/371 372/372 f 373/373 374/374 362/362 f 362/362 374/374 363/363 f 376/376 377/377 375/375 f 375/375 377/377 378/378 f 289/289 229/229 380/380 f 380/380 229/229 379/379 f 381/381 379/379 263/263 f 263/263 379/379 229/229 f 383/383 384/384 382/382 f 382/382 384/384 385/385 f 386/386 368/368 374/374 f 374/374 368/368 363/363 f 76/76 289/289 371/371 f 371/371 289/289 380/380 f 377/377 376/376 359/359 f 359/359 376/376 387/387 f 388/388 386/386 360/360 f 360/360 386/386 374/374 f 389/389 383/383 366/366 f 366/366 383/383 390/390 f 392/392 393/393 391/391 f 391/391 393/393 394/394 f 383/383 382/382 390/390 f 390/390 382/382 395/395 f 396/396 365/365 390/390 f 390/390 365/365 366/366 f 389/389 366/366 367/367 f 367/367 366/366 364/364 f 357/357 397/397 358/358 f 358/358 397/397 398/398 f 373/373 399/399 357/357 f 357/357 399/399 397/397 f 389/389 367/367 400/400 f 400/400 367/367 370/370 f 382/382 385/385 375/375 f 375/375 385/385 372/372 f 357/357 360/360 373/373 f 373/373 360/360 374/374 f 361/361 401/401 362/362 f 362/362 401/401 402/402 f 387/387 388/388 359/359 f 359/359 388/388 360/360 f 363/363 368/368 364/364 f 364/364 368/368 367/367 f 358/358 398/398 403/403 f 403/403 398/398 404/404 f 396/396 392/392 405/405 f 405/405 392/392 391/391 f 392/392 395/395 393/393 f 393/393 395/395 378/378 f 393/393 403/403 394/394 f 394/394 403/403 404/404 f 375/375 378/378 382/382 f 382/382 378/378 395/395 f 365/365 396/396 406/406 f 406/406 396/396 405/405 f 362/362 402/402 373/373 f 373/373 402/402 399/399 f 271/271 270/270 400/400 f 400/400 270/270 384/384 f 401/401 361/361 406/406 f 406/406 361/361 365/365 f 381/381 369/369 386/386 f 386/386 369/369 368/368 f 392/392 396/396 395/395 f 395/395 396/396 390/390 f 393/393 378/378 403/403 f 403/403 378/378 377/377 f 403/403 377/377 358/358 f 358/358 377/377 359/359 f 406/406 405/405 408/408 f 408/408 405/405 407/407 f 406/406 408/408 401/401 f 401/401 408/408 409/409 f 401/401 409/409 402/402 f 402/402 409/409 410/410 f 402/402 410/410 399/399 f 399/399 410/410 411/411 f 405/405 391/391 407/407 f 407/407 391/391 412/412 f 391/391 394/394 412/412 f 412/412 394/394 413/413 f 394/394 404/404 413/413 f 413/413 404/404 414/414 f 415/415 416/416 412/412 f 412/412 416/416 407/407 f 418/418 419/419 417/417 f 417/417 419/419 420/420 f 421/421 422/422 418/418 f 418/418 422/422 419/419 f 419/419 422/422 424/424 f 424/424 422/422 423/423 f 425/425 426/426 424/424 f 424/424 426/426 427/427 f 423/423 428/428 424/424 f 424/424 428/428 425/425 f 427/427 420/420 424/424 f 424/424 420/420 419/419 f 420/420 429/429 417/417 f 417/417 429/429 430/430 f 423/423 422/422 431/431 f 431/431 422/422 421/421 f 421/421 409/409 431/431 f 431/431 409/409 408/408 f 421/421 432/432 409/409 f 409/409 432/432 410/410 f 418/418 433/433 421/421 f 421/421 433/433 432/432 f 434/434 433/433 417/417 f 417/417 433/433 418/418 f 431/431 416/416 423/423 f 423/423 416/416 428/428 f 416/416 431/431 407/407 f 407/407 431/431 408/408 f 435/435 434/434 430/430 f 430/430 434/434 417/417 f 433/433 434/434 436/436 f 436/436 434/434 437/437 f 434/434 435/435 437/437 f 437/437 435/435 438/438 f 436/436 437/437 439/439 f 439/439 437/437 440/440 f 439/439 441/441 436/436 f 436/436 441/441 442/442 f 438/438 443/443 437/437 f 437/437 443/443 440/440 f 436/436 442/442 433/433 f 433/433 442/442 432/432 f 432/432 442/442 410/410 f 410/410 442/442 411/411 f 435/435 430/430 445/445 f 445/445 430/430 444/444 f 430/430 429/429 444/444 f 444/444 429/429 446/446 f 425/425 428/428 447/447 f 447/447 428/428 416/416 f 426/426 425/425 448/448 f 448/448 425/425 447/447 f 416/416 415/415 447/447 f 447/447 415/415 449/449 f 447/447 449/449 448/448 f 448/448 449/449 450/450 f 451/451 452/452 448/448 f 448/448 452/452 426/426 f 446/446 452/452 444/444 f 444/444 452/452 451/451 f 399/399 411/411 397/397 f 397/397 411/411 453/453 f 398/398 454/454 404/404 f 404/404 454/454 414/414 f 454/454 398/398 453/453 f 453/453 398/398 397/397 f 453/453 441/441 454/454 f 454/454 441/441 455/455 f 441/441 439/439 455/455 f 455/455 439/439 456/456 f 454/454 455/455 414/414 f 414/414 455/455 457/457 f 441/441 453/453 442/442 f 442/442 453/453 411/411 f 458/458 413/413 457/457 f 457/457 413/413 414/414 f 458/458 415/415 413/413 f 413/413 415/415 412/412 f 458/458 459/459 415/415 f 415/415 459/459 449/449 f 459/459 458/458 460/460 f 460/460 458/458 457/457 f 461/461 459/459 462/462 f 462/462 459/459 460/460 f 455/455 456/456 457/457 f 457/457 456/456 460/460 f 456/456 463/463 460/460 f 460/460 463/463 462/462 f 459/459 461/461 449/449 f 449/449 461/461 450/450 f 465/465 450/450 464/464 f 464/464 450/450 461/461 f 464/464 467/467 466/466 f 466/466 467/467 468/468 f 464/464 461/461 467/467 f 467/467 461/461 462/462 f 464/464 466/466 465/465 f 465/465 466/466 445/445 f 465/465 445/445 451/451 f 451/451 445/445 444/444 f 451/451 448/448 465/465 f 465/465 448/448 450/450 f 439/439 440/440 456/456 f 456/456 440/440 463/463 f 468/468 463/463 443/443 f 443/443 463/463 440/440 f 468/468 467/467 463/463 f 463/463 467/467 462/462 f 466/466 468/468 438/438 f 438/438 468/468 443/443 f 438/438 435/435 466/466 f 466/466 435/435 445/445 f 420/420 427/427 429/429 f 429/429 427/427 446/446 f 446/446 427/427 452/452 f 452/452 427/427 426/426 f 370/370 369/369 188/188 f 188/188 369/369 186/186 f 371/371 376/376 372/372 f 372/372 376/376 375/375 f 380/380 379/379 387/387 f 387/387 379/379 388/388 f 379/379 381/381 388/388 f 388/388 381/381 386/386 f 385/385 384/384 278/278 f 278/278 384/384 270/270 f 380/380 387/387 371/371 f 371/371 387/387 376/376 f 400/400 370/370 271/271 f 271/271 370/370 188/188 f 385/385 278/278 372/372 f 372/372 278/278 247/247 f 400/400 384/384 389/389 f 389/389 384/384 383/383 f 369/369 381/381 186/186 f 186/186 381/381 263/263 f 221/221 271/271 144/144 f 144/144 271/271 188/188 f 221/221 19/19 207/207 f 207/207 19/19 22/22 f 19/19 18/18 22/22 f 22/22 18/18 23/23 f 18/18 219/219 23/23 f 23/23 219/219 208/208 f 469/469 470/470 472/472 f 472/472 470/470 471/471 f 474/474 475/475 473/473 f 473/473 475/475 476/476 f 473/473 476/476 477/477 f 477/477 476/476 478/478 f 480/480 481/481 479/479 f 479/479 481/481 482/482 f 483/483 484/484 474/474 f 474/474 484/484 475/475 f 486/486 487/487 485/485 f 485/485 487/487 488/488 f 489/489 490/490 77/77 f 77/77 490/490 142/142 f 491/491 489/489 248/248 f 248/248 489/489 77/77 f 493/493 494/494 492/492 f 492/492 494/494 495/495 f 496/496 480/480 484/484 f 484/484 480/480 475/475 f 486/486 497/497 487/487 f 487/487 497/497 471/471 f 498/498 496/496 472/472 f 472/472 496/496 484/484 f 499/499 493/493 478/478 f 478/478 493/493 500/500 f 501/501 502/502 504/504 f 504/504 502/502 503/503 f 493/493 492/492 500/500 f 500/500 492/492 505/505 f 506/506 477/477 500/500 f 500/500 477/477 478/478 f 499/499 478/478 479/479 f 479/479 478/478 476/476 f 469/469 507/507 470/470 f 470/470 507/507 508/508 f 483/483 509/509 469/469 f 469/469 509/509 507/507 f 479/479 482/482 499/499 f 499/499 482/482 510/510 f 492/492 495/495 485/485 f 485/485 495/495 511/511 f 483/483 469/469 484/484 f 484/484 469/469 472/472 f 473/473 512/512 474/474 f 474/474 512/512 513/513 f 497/497 498/498 471/471 f 471/471 498/498 472/472 f 475/475 480/480 476/476 f 476/476 480/480 479/479 f 470/470 508/508 514/514 f 514/514 508/508 515/515 f 506/506 502/502 516/516 f 516/516 502/502 501/501 f 503/503 502/502 488/488 f 488/488 502/502 505/505 f 514/514 515/515 503/503 f 503/503 515/515 504/504 f 485/485 488/488 492/492 f 492/492 488/488 505/505 f 477/477 506/506 517/517 f 517/517 506/506 516/516 f 474/474 513/513 483/483 f 483/483 513/513 509/509 f 510/510 292/292 494/494 f 494/494 292/292 164/164 f 512/512 473/473 517/517 f 517/517 473/473 477/477 f 491/491 481/481 496/496 f 496/496 481/481 480/480 f 502/502 506/506 505/505 f 505/505 506/506 500/500 f 503/503 488/488 514/514 f 514/514 488/488 487/487 f 514/514 487/487 470/470 f 470/470 487/487 471/471 f 517/517 516/516 519/519 f 519/519 516/516 518/518 f 517/517 519/519 512/512 f 512/512 519/519 520/520 f 512/512 520/520 513/513 f 513/513 520/520 521/521 f 513/513 521/521 509/509 f 509/509 521/521 522/522 f 516/516 501/501 518/518 f 518/518 501/501 523/523 f 501/501 504/504 523/523 f 523/523 504/504 524/524 f 524/524 504/504 525/525 f 525/525 504/504 515/515 f 526/526 527/527 523/523 f 523/523 527/527 518/518 f 529/529 530/530 528/528 f 528/528 530/530 531/531 f 532/532 533/533 529/529 f 529/529 533/533 530/530 f 530/530 533/533 535/535 f 535/535 533/533 534/534 f 536/536 537/537 535/535 f 535/535 537/537 538/538 f 534/534 539/539 535/535 f 535/535 539/539 536/536 f 538/538 531/531 535/535 f 535/535 531/531 530/530 f 540/540 541/541 531/531 f 531/531 541/541 528/528 f 533/533 532/532 534/534 f 534/534 532/532 542/542 f 532/532 520/520 542/542 f 542/542 520/520 519/519 f 532/532 543/543 520/520 f 520/520 543/543 521/521 f 529/529 544/544 532/532 f 532/532 544/544 543/543 f 544/544 529/529 545/545 f 545/545 529/529 528/528 f 534/534 542/542 539/539 f 539/539 542/542 527/527 f 527/527 542/542 518/518 f 518/518 542/542 519/519 f 541/541 546/546 528/528 f 528/528 546/546 545/545 f 547/547 544/544 548/548 f 548/548 544/544 545/545 f 546/546 549/549 545/545 f 545/545 549/549 548/548 f 550/550 547/547 551/551 f 551/551 547/547 548/548 f 547/547 550/550 553/553 f 553/553 550/550 552/552 f 549/549 554/554 548/548 f 548/548 554/554 551/551 f 544/544 547/547 543/543 f 543/543 547/547 553/553 f 543/543 553/553 521/521 f 521/521 553/553 522/522 f 546/546 541/541 556/556 f 556/556 541/541 555/555 f 541/541 540/540 555/555 f 555/555 540/540 557/557 f 536/536 539/539 558/558 f 558/558 539/539 527/527 f 537/537 536/536 559/559 f 559/559 536/536 558/558 f 527/527 526/526 558/558 f 558/558 526/526 560/560 f 559/559 558/558 561/561 f 561/561 558/558 560/560 f 559/559 562/562 537/537 f 537/537 562/562 563/563 f 557/557 563/563 555/555 f 555/555 563/563 562/562 f 509/509 522/522 507/507 f 507/507 522/522 564/564 f 508/508 565/565 515/515 f 515/515 565/565 525/525 f 565/565 508/508 564/564 f 564/564 508/508 507/507 f 564/564 552/552 565/565 f 565/565 552/552 566/566 f 552/552 550/550 566/566 f 566/566 550/550 567/567 f 565/565 566/566 525/525 f 525/525 566/566 568/568 f 564/564 522/522 552/552 f 552/552 522/522 553/553 f 569/569 524/524 568/568 f 568/568 524/524 525/525 f 569/569 526/526 524/524 f 524/524 526/526 523/523 f 570/570 560/560 569/569 f 569/569 560/560 526/526 f 570/570 569/569 571/571 f 571/571 569/569 568/568 f 572/572 570/570 573/573 f 573/573 570/570 571/571 f 566/566 567/567 568/568 f 568/568 567/567 571/571 f 567/567 574/574 571/571 f 571/571 574/574 573/573 f 570/570 572/572 560/560 f 560/560 572/572 561/561 f 576/576 561/561 575/575 f 575/575 561/561 572/572 f 575/575 578/578 577/577 f 577/577 578/578 579/579 f 575/575 572/572 578/578 f 578/578 572/572 573/573 f 575/575 577/577 576/576 f 576/576 577/577 556/556 f 576/576 556/556 562/562 f 562/562 556/556 555/555 f 562/562 559/559 576/576 f 576/576 559/559 561/561 f 550/550 551/551 567/567 f 567/567 551/551 574/574 f 579/579 574/574 554/554 f 554/554 574/574 551/551 f 579/579 578/578 574/574 f 574/574 578/578 573/573 f 579/579 554/554 577/577 f 577/577 554/554 549/549 f 549/549 546/546 577/577 f 577/577 546/546 556/556 f 531/531 538/538 540/540 f 540/540 538/538 557/557 f 557/557 538/538 563/563 f 563/563 538/538 537/537 f 481/481 294/294 482/482 f 482/482 294/294 293/293 f 580/580 486/486 511/511 f 511/511 486/486 485/485 f 490/490 489/489 497/497 f 497/497 489/489 498/498 f 489/489 491/491 498/498 f 498/498 491/491 496/496 f 163/163 495/495 164/164 f 164/164 495/495 494/494 f 580/580 490/490 486/486 f 486/486 490/490 497/497 f 482/482 293/293 510/510 f 510/510 293/293 292/292 f 495/495 163/163 511/511 f 511/511 163/163 199/199 f 494/494 493/493 510/510 f 510/510 493/493 499/499 f 481/481 491/491 294/294 f 294/294 491/491 248/248 f 582/582 583/583 581/581 f 581/581 583/583 584/584 f 586/586 587/587 585/585 f 585/585 587/587 588/588 f 585/585 588/588 589/589 f 589/589 588/588 590/590 f 592/592 593/593 591/591 f 591/591 593/593 594/594 f 595/595 596/596 598/598 f 598/598 596/596 597/597 f 599/599 600/600 586/586 f 586/586 600/600 587/587 f 601/601 602/602 604/604 f 604/604 602/602 603/603 f 605/605 606/606 608/608 f 608/608 606/606 607/607 f 609/609 607/607 200/200 f 200/200 607/607 606/606 f 610/610 611/611 613/613 f 613/613 611/611 612/612 f 600/600 614/614 587/587 f 587/587 614/614 592/592 f 596/596 605/605 597/597 f 597/597 605/605 608/608 f 602/602 615/615 603/603 f 603/603 615/615 583/583 f 616/616 614/614 584/584 f 584/584 614/614 600/600 f 611/611 618/618 617/617 f 617/617 618/618 590/590 f 620/620 621/621 619/619 f 619/619 621/621 622/622 f 610/610 623/623 611/611 f 611/611 623/623 618/618 f 624/624 589/589 618/618 f 618/618 589/589 590/590 f 617/617 590/590 591/591 f 591/591 590/590 588/588 f 581/581 625/625 582/582 f 582/582 625/625 626/626 f 599/599 627/627 581/581 f 581/581 627/627 625/625 f 591/591 594/594 617/617 f 617/617 594/594 628/628 f 601/601 610/610 598/598 f 598/598 610/610 613/613 f 581/581 584/584 599/599 f 599/599 584/584 600/600 f 585/585 629/629 586/586 f 586/586 629/629 630/630 f 615/615 616/616 583/583 f 583/583 616/616 584/584 f 587/587 592/592 588/588 f 588/588 592/592 591/591 f 582/582 626/626 631/631 f 631/631 626/626 632/632 f 624/624 620/620 633/633 f 633/633 620/620 619/619 f 621/621 620/620 604/604 f 604/604 620/620 623/623 f 631/631 632/632 621/621 f 621/621 632/632 622/622 f 610/610 601/601 623/623 f 623/623 601/601 604/604 f 589/589 624/624 634/634 f 634/634 624/624 633/633 f 586/586 630/630 599/599 f 599/599 630/630 627/627 f 203/203 202/202 628/628 f 628/628 202/202 612/612 f 629/629 585/585 634/634 f 634/634 585/585 589/589 f 609/609 593/593 614/614 f 614/614 593/593 592/592 f 620/620 624/624 623/623 f 623/623 624/624 618/618 f 631/631 621/621 603/603 f 603/603 621/621 604/604 f 582/582 631/631 583/583 f 583/583 631/631 603/603 f 634/634 633/633 636/636 f 636/636 633/633 635/635 f 634/634 636/636 629/629 f 629/629 636/636 637/637 f 629/629 637/637 630/630 f 630/630 637/637 638/638 f 630/630 638/638 627/627 f 627/627 638/638 639/639 f 633/633 619/619 635/635 f 635/635 619/619 640/640 f 619/619 622/622 640/640 f 640/640 622/622 641/641 f 641/641 622/622 642/642 f 642/642 622/622 632/632 f 644/644 635/635 643/643 f 643/643 635/635 640/640 f 645/645 646/646 648/648 f 648/648 646/646 647/647 f 649/649 650/650 646/646 f 646/646 650/650 647/647 f 647/647 650/650 652/652 f 652/652 650/650 651/651 f 652/652 653/653 655/655 f 655/655 653/653 654/654 f 651/651 656/656 652/652 f 652/652 656/656 653/653 f 655/655 648/648 652/652 f 652/652 648/648 647/647 f 648/648 657/657 645/645 f 645/645 657/657 658/658 f 650/650 649/649 651/651 f 651/651 649/649 659/659 f 649/649 637/637 659/659 f 659/659 637/637 636/636 f 649/649 660/660 637/637 f 637/637 660/660 638/638 f 661/661 660/660 646/646 f 646/646 660/660 649/649 f 662/662 661/661 645/645 f 645/645 661/661 646/646 f 651/651 659/659 656/656 f 656/656 659/659 644/644 f 644/644 659/659 635/635 f 635/635 659/659 636/636 f 663/663 662/662 658/658 f 658/658 662/662 645/645 f 664/664 661/661 665/665 f 665/665 661/661 662/662 f 663/663 666/666 662/662 f 662/662 666/666 665/665 f 667/667 664/664 668/668 f 668/668 664/664 665/665 f 664/664 667/667 670/670 f 670/670 667/667 669/669 f 666/666 671/671 665/665 f 665/665 671/671 668/668 f 661/661 664/664 660/660 f 660/660 664/664 670/670 f 660/660 670/670 638/638 f 638/638 670/670 639/639 f 658/658 672/672 663/663 f 663/663 672/672 673/673 f 658/658 657/657 672/672 f 672/672 657/657 674/674 f 653/653 656/656 675/675 f 675/675 656/656 644/644 f 653/653 675/675 654/654 f 654/654 675/675 676/676 f 675/675 644/644 677/677 f 677/677 644/644 643/643 f 676/676 675/675 678/678 f 678/678 675/675 677/677 f 679/679 680/680 676/676 f 676/676 680/680 654/654 f 674/674 680/680 672/672 f 672/672 680/680 679/679 f 627/627 639/639 625/625 f 625/625 639/639 681/681 f 626/626 682/682 632/632 f 632/632 682/682 642/642 f 681/681 682/682 625/625 f 625/625 682/682 626/626 f 669/669 683/683 681/681 f 681/681 683/683 682/682 f 667/667 684/684 669/669 f 669/669 684/684 683/683 f 682/682 683/683 642/642 f 642/642 683/683 685/685 f 681/681 639/639 669/669 f 669/669 639/639 670/670 f 686/686 641/641 685/685 f 685/685 641/641 642/642 f 641/641 686/686 640/640 f 640/640 686/686 643/643 f 686/686 687/687 643/643 f 643/643 687/687 677/677 f 687/687 686/686 688/688 f 688/688 686/686 685/685 f 689/689 687/687 690/690 f 690/690 687/687 688/688 f 683/683 684/684 685/685 f 685/685 684/684 688/688 f 684/684 691/691 688/688 f 688/688 691/691 690/690 f 687/687 689/689 677/677 f 677/677 689/689 678/678 f 693/693 678/678 692/692 f 692/692 678/678 689/689 f 692/692 695/695 694/694 f 694/694 695/695 696/696 f 692/692 689/689 695/695 f 695/695 689/689 690/690 f 692/692 694/694 693/693 f 693/693 694/694 673/673 f 693/693 673/673 679/679 f 679/679 673/673 672/672 f 679/679 676/676 693/693 f 693/693 676/676 678/678 f 684/684 667/667 691/691 f 691/691 667/667 668/668 f 696/696 691/691 671/671 f 671/671 691/691 668/668 f 696/696 695/695 691/691 f 691/691 695/695 690/690 f 694/694 696/696 666/666 f 666/666 696/696 671/671 f 666/666 663/663 694/694 f 694/694 663/663 673/673 f 648/648 655/655 657/657 f 657/657 655/655 674/674 f 674/674 655/655 680/680 f 680/680 655/655 654/654 f 593/593 162/162 594/594 f 594/594 162/162 290/290 f 598/598 597/597 601/601 f 601/601 597/597 602/602 f 615/615 608/608 616/616 f 616/616 608/608 607/607 f 607/607 609/609 616/616 f 616/616 609/609 614/614 f 697/697 595/595 613/613 f 613/613 595/595 598/598 f 597/597 608/608 602/602 f 602/602 608/608 615/615 f 594/594 290/290 628/628 f 628/628 290/290 203/203 f 628/628 612/612 617/617 f 617/617 612/612 611/611 f 593/593 609/609 162/162 f 162/162 609/609 200/200 f 105/105 29/29 698/698 f 698/698 29/29 699/699 f 268/268 126/126 701/701 f 701/701 126/126 700/700 f 126/126 125/125 700/700 f 700/700 125/125 702/702 f 252/252 703/703 250/250 f 250/250 703/703 704/704 f 32/32 268/268 705/705 f 705/705 268/268 701/701 f 288/288 105/105 706/706 f 706/706 105/105 698/698 f 29/29 32/32 699/699 f 699/699 32/32 705/705 f 707/707 251/251 706/706 f 706/706 251/251 288/288 f 250/250 704/704 125/125 f 125/125 704/704 702/702 f 703/703 252/252 707/707 f 707/707 252/252 251/251 f 706/706 708/708 707/707 f 707/707 708/708 709/709 f 707/707 709/709 703/703 f 703/703 709/709 710/710 f 703/703 710/710 704/704 f 704/704 710/710 711/711 f 704/704 711/711 702/702 f 702/702 711/711 712/712 f 706/706 698/698 708/708 f 708/708 698/698 713/713 f 698/698 699/699 713/713 f 713/713 699/699 714/714 f 699/699 705/705 714/714 f 714/714 705/705 715/715 f 717/717 708/708 716/716 f 716/716 708/708 713/713 f 719/719 720/720 718/718 f 718/718 720/720 721/721 f 722/722 723/723 719/719 f 719/719 723/723 720/720 f 724/724 725/725 723/723 f 723/723 725/725 720/720 f 724/724 726/726 725/725 f 725/725 726/726 727/727 f 728/728 721/721 725/725 f 725/725 721/721 720/720 f 721/721 728/728 729/729 f 729/729 728/728 730/730 f 729/729 731/731 721/721 f 721/721 731/731 718/718 f 724/724 723/723 732/732 f 732/732 723/723 722/722 f 722/722 710/710 732/732 f 732/732 710/710 709/709 f 722/722 733/733 710/710 f 710/710 733/733 711/711 f 719/719 734/734 722/722 f 722/722 734/734 733/733 f 734/734 719/719 735/735 f 735/735 719/719 718/718 f 724/724 732/732 726/726 f 726/726 732/732 717/717 f 717/717 732/732 708/708 f 708/708 732/732 709/709 f 731/731 736/736 718/718 f 718/718 736/736 735/735 f 737/737 734/734 738/738 f 738/738 734/734 735/735 f 736/736 739/739 735/735 f 735/735 739/739 738/738 f 740/740 737/737 741/741 f 741/741 737/737 738/738 f 737/737 740/740 743/743 f 743/743 740/740 742/742 f 739/739 744/744 738/738 f 738/738 744/744 741/741 f 734/734 737/737 733/733 f 733/733 737/737 743/743 f 733/733 743/743 711/711 f 711/711 743/743 712/712 f 736/736 731/731 746/746 f 746/746 731/731 745/745 f 731/731 729/729 745/745 f 745/745 729/729 730/730 f 727/727 726/726 747/747 f 747/747 726/726 717/717 f 748/748 727/727 749/749 f 749/749 727/727 747/747 f 747/747 717/717 750/750 f 750/750 717/717 716/716 f 749/749 747/747 751/751 f 751/751 747/747 750/750 f 749/749 752/752 748/748 f 748/748 752/752 753/753 f 730/730 753/753 745/745 f 745/745 753/753 752/752 f 728/728 725/725 748/748 f 748/748 725/725 727/727 f 730/730 728/728 753/753 f 753/753 728/728 748/748 f 700/700 702/702 754/754 f 754/754 702/702 712/712 f 705/705 701/701 715/715 f 715/715 701/701 755/755 f 754/754 755/755 700/700 f 700/700 755/755 701/701 f 742/742 756/756 754/754 f 754/754 756/756 755/755 f 740/740 757/757 742/742 f 742/742 757/757 756/756 f 755/755 756/756 715/715 f 715/715 756/756 758/758 f 754/754 712/712 742/742 f 742/742 712/712 743/743 f 759/759 714/714 758/758 f 758/758 714/714 715/715 f 714/714 759/759 713/713 f 713/713 759/759 716/716 f 759/759 760/760 716/716 f 716/716 760/760 750/750 f 760/760 759/759 761/761 f 761/761 759/759 758/758 f 762/762 760/760 763/763 f 763/763 760/760 761/761 f 756/756 757/757 758/758 f 758/758 757/757 761/761 f 757/757 764/764 761/761 f 761/761 764/764 763/763 f 760/760 762/762 750/750 f 750/750 762/762 751/751 f 766/766 751/751 765/765 f 765/765 751/751 762/762 f 767/767 765/765 769/769 f 769/769 765/765 768/768 f 765/765 762/762 768/768 f 768/768 762/762 763/763 f 765/765 767/767 766/766 f 766/766 767/767 746/746 f 766/766 746/746 752/752 f 752/752 746/746 745/745 f 752/752 749/749 766/766 f 766/766 749/749 751/751 f 757/757 740/740 764/764 f 764/764 740/740 741/741 f 769/769 764/764 744/744 f 744/744 764/764 741/741 f 769/769 768/768 764/764 f 764/764 768/768 763/763 f 767/767 769/769 739/739 f 739/739 769/769 744/744 f 739/739 736/736 767/767 f 767/767 736/736 746/746 f 219/219 217/217 208/208 f 208/208 217/217 209/209 f 209/209 217/217 210/210 f 210/210 217/217 193/193 f 198/198 580/580 199/199 f 199/199 580/580 511/511 f 76/76 75/75 289/289 f 289/289 75/75 272/272 f 277/277 207/207 291/291 f 291/291 207/207 184/184 f 290/290 183/183 203/203 f 203/203 183/183 84/84 f 490/490 580/580 142/142 f 142/142 580/580 198/198 f 142/142 198/198 143/143 f 143/143 198/198 197/197 f 149/149 276/276 72/72 f 72/72 276/276 73/73 f 104/104 103/103 279/279 f 279/279 103/103 770/770 f 770/770 596/596 279/279 f 279/279 596/596 595/595 f 605/605 596/596 771/771 f 771/771 596/596 770/770 f 771/771 770/770 772/772 f 772/772 770/770 103/103 f 772/772 103/103 773/773 f 773/773 103/103 102/102 f 155/155 774/774 101/101 f 101/101 774/774 102/102 f 773/773 102/102 97/97 f 97/97 102/102 774/774 f 775/775 773/773 100/100 f 100/100 773/773 97/97 f 773/773 775/775 772/772 f 772/772 775/775 776/776 f 772/772 776/776 771/771 f 771/771 776/776 777/777 f 200/200 606/606 197/197 f 197/197 606/606 777/777 f 189/189 71/71 778/778 f 778/778 71/71 74/74 f 97/97 774/774 98/98 f 98/98 774/774 155/155 f 183/183 161/161 184/184 f 184/184 161/161 291/291 f 777/777 276/276 197/197 f 197/197 276/276 143/143 f 777/777 606/606 771/771 f 771/771 606/606 605/605 f 613/613 612/612 697/697 f 697/697 612/612 202/202 f 595/595 697/697 279/279 f 279/279 697/697 202/202 f 73/73 276/276 776/776 f 776/776 276/276 777/777 f 776/776 775/775 73/73 f 73/73 775/775 74/74 f 100/100 778/778 775/775 f 775/775 778/778 74/74 f 778/778 100/100 189/189 f 189/189 100/100 99/99 f 245/245 242/242 99/99 f 99/99 242/242 189/189 f 131/131 33/33 256/256 f 28/28 1/1 95/95 f 95/95 1/1 62/62 f 27/27 2/2 28/28 f 28/28 2/2 1/1 f 265/265 115/115 266/266 f 266/266 115/115 114/114 f 95/95 62/62 69/69 f 69/69 62/62 64/64 f 62/62 61/61 64/64 f 64/64 61/61 65/65 f 61/61 13/13 65/65 f 65/65 13/13 130/130 f 13/13 12/12 130/130 f 130/130 12/12 14/14 f 31/31 11/11 32/32 f 32/32 11/11 268/268 f 15/15 12/12 31/31 f 31/31 12/12 11/11 f 31/31 30/30 15/15 f 15/15 30/30 231/231 f 30/30 106/106 231/231 f 231/231 106/106 232/232 f 287/287 237/237 106/106 f 106/106 237/237 232/232 f 254/254 90/90 287/287 f 287/287 90/90 237/237 f 253/253 44/44 254/254 f 254/254 44/44 90/90 f 253/253 249/249 44/44 f 44/44 249/249 7/7 f 267/267 127/127 268/268 f 268/268 127/127 126/126 f 10/10 3/3 241/241 f 241/241 3/3 116/116 f 3/3 2/2 116/116 f 116/116 2/2 114/114 f 2/2 27/27 114/114 f 114/114 27/27 266/266 f 27/27 26/26 266/266 f 266/266 26/26 113/113 f 26/26 286/286 113/113 f 113/113 286/286 110/110 f 286/286 243/243 110/110 f 110/110 243/243 255/255 f 243/243 242/242 255/255 f 255/255 242/242 256/256 f 242/242 245/245 256/256 f 256/256 245/245 131/131 f 245/245 244/244 131/131 f 131/131 244/244 132/132 f 265/265 37/37 115/115 f 115/115 37/37 41/41 f 41/41 37/37 42/42 f 42/42 37/37 40/40 f 92/92 91/91 40/40 f 40/40 91/91 42/42 f 236/236 233/233 92/92 f 92/92 233/233 91/91 f 191/191 194/194 236/236 f 236/236 194/194 233/233 f 258/258 285/285 244/244 f 244/244 285/285 132/132 f 257/257 55/55 258/258 f 258/258 55/55 285/285 f 257/257 154/154 201/201 f 201/201 154/154 185/185 f 56/56 201/201 204/204 f 204/204 201/201 180/180 f 55/55 257/257 56/56 f 56/56 257/257 201/201 f 204/204 85/85 56/56 f 56/56 85/85 52/52 f 86/86 122/122 53/53 f 53/53 122/122 79/79 f 212/212 215/215 86/86 f 86/86 215/215 122/122 f 211/211 216/216 212/212 f 212/212 216/216 215/215 f 192/192 280/280 211/211 f 211/211 280/280 216/216 f 191/191 240/240 192/192 f 192/192 240/240 280/280 f 249/249 124/124 7/7 f 7/7 124/124 8/8 f 124/124 127/127 8/8 f 8/8 127/127 241/241 f 127/127 267/267 241/241 f 241/241 267/267 10/10 f 10/10 267/267 9/9 f 9/9 267/267 11/11 ================================================ FILE: main/config.py ================================================ import os import os.path as osp import sys import numpy as np class Config: ## dataset # HO3D, DEX_YCB trainset = 'HO3D' testset = 'DEX_YCB' ## input, output input_img_shape = (256,256) ## training config if trainset == 'HO3D': lr_dec_epoch = [10*i for i in range(1,7)] end_epoch = 70 lr = 1e-4 lr_dec_factor = 0.7 elif trainset == 'DEX_YCB': lr_dec_epoch = [i for i in range(1,25)] end_epoch = 25 lr = 1e-4 lr_dec_factor = 0.9 train_batch_size = 16 # per GPU lambda_mano_verts = 1e4 lambda_mano_joints = 1e4 lambda_mano_pose = 10 lambda_mano_shape = 0.1 lambda_joints_img = 100 ckpt_freq = 10 ## testing config test_batch_size = 64 ## others num_thread = 20 gpu_ids = '0' num_gpus = 1 continue_train = False ## directory cur_dir = osp.dirname(os.path.abspath(__file__)) root_dir = osp.join(cur_dir, '..') data_dir = osp.join(root_dir, 'data') output_dir = osp.join(root_dir, 'output') model_dir = osp.join(output_dir, 'model_dump') vis_dir = osp.join(output_dir, 'vis') log_dir = osp.join(output_dir, 'log') result_dir = osp.join(output_dir, 'result') mano_path = osp.join(root_dir, 'common', 'utils', 'manopth') def set_args(self, gpu_ids, continue_train=False): self.gpu_ids = gpu_ids self.num_gpus = len(self.gpu_ids.split(',')) self.continue_train = continue_train os.environ["CUDA_VISIBLE_DEVICES"] = self.gpu_ids print('>>> Using GPU: {}'.format(self.gpu_ids)) cfg = Config() sys.path.insert(0, osp.join(cfg.root_dir, 'common')) from utils.dir import add_pypath, make_folder add_pypath(osp.join(cfg.data_dir)) add_pypath(osp.join(cfg.data_dir, cfg.trainset)) add_pypath(osp.join(cfg.data_dir, cfg.testset)) make_folder(cfg.model_dir) make_folder(cfg.vis_dir) make_folder(cfg.log_dir) make_folder(cfg.result_dir) ================================================ FILE: main/model.py ================================================ import torch import torch.nn as nn from torch.nn import functional as F from nets.backbone import FPN from nets.transformer import Transformer from nets.regressor import Regressor from utils.mano import MANO from utils.fitting import ScaleTranslationLoss, FittingMonitor from utils.optimizers import optim_factory from utils.camera import PerspectiveCamera from config import cfg import math class Model(nn.Module): def __init__(self, backbone, FIT, SET, regressor): super(Model, self).__init__() self.backbone = backbone self.FIT = FIT self.SET = SET self.regressor = regressor self.fitting_loss = ScaleTranslationLoss(list(range(0, 21))) # fitting joint indices def forward(self, inputs, targets, meta_info, mode): p_feats, s_feats = self.backbone(inputs['img']) # primary, secondary feats feats = self.FIT(s_feats, p_feats) feats = self.SET(feats, feats) if mode == 'train': gt_mano_params = torch.cat([targets['mano_pose'], targets['mano_shape']], dim=1) else: gt_mano_params = None pred_mano_results, gt_mano_results, preds_joints_img = self.regressor(feats, gt_mano_params) if mode == 'train': # loss functions loss = {} loss['mano_verts'] = cfg.lambda_mano_verts * F.mse_loss(pred_mano_results['verts3d'], gt_mano_results['verts3d']) loss['mano_joints'] = cfg.lambda_mano_joints * F.mse_loss(pred_mano_results['joints3d'], gt_mano_results['joints3d']) loss['mano_pose'] = cfg.lambda_mano_pose * F.mse_loss(pred_mano_results['mano_pose'], gt_mano_results['mano_pose']) loss['mano_shape'] = cfg.lambda_mano_shape * F.mse_loss(pred_mano_results['mano_shape'], gt_mano_results['mano_shape']) loss['joints_img'] = cfg.lambda_joints_img * F.mse_loss(preds_joints_img[0], targets['joints_img']) return loss else: # test output out = {} out['joints_coord_img'] = preds_joints_img[0] out['mano_pose'] = pred_mano_results['mano_pose_aa'] out['mano_shape'] = pred_mano_results['mano_shape'] out['joints_coord_cam'] = pred_mano_results['joints3d'] out['mesh_coord_cam'] = pred_mano_results['verts3d'] out['manojoints2cam'] = pred_mano_results['manojoints2cam'] out['mano_pose_aa'] = pred_mano_results['mano_pose_aa'] return out def get_mesh_scale_trans(self, pred_joint_img, pred_joint_cam, init_scale=1., init_depth=1., camera=None, depth_map=None): """ pred_joint_img: (batch_size, 21, 2) pred_joint_cam: (batch_size, 21, 3) """ if camera is None: camera = PerspectiveCamera() dtype, device = pred_joint_cam.dtype, pred_joint_cam.device hand_scale = torch.tensor([init_scale / 1.0], dtype=dtype, device=device, requires_grad=False) hand_translation = torch.tensor([0, 0, init_depth], dtype=dtype, device=device, requires_grad=True) if depth_map is not None: tensor_depth = torch.tensor(depth_map, device=device, dtype=dtype)[ None, None, :, :] grid = pred_joint_img.clone() grid[:, :, 0] /= tensor_depth.shape[-1] grid[:, :, 1] /= tensor_depth.shape[-2] grid = 2 * grid - 1 joints_depth = torch.nn.functional.grid_sample( tensor_depth, grid[:, None, :, :]) # (1, 1, 1, 21) joints_depth = joints_depth.reshape(1, 21, 1) hand_translation = torch.tensor( [0, 0, joints_depth[0, cfg.fitting_joint_idxs, 0].mean() / 1000.], device=device, requires_grad=True) # intended only for demo mesh rendering batch_size = 1 self.fitting_loss.trans_estimation = hand_translation.clone() params = [] params.append(hand_translation) params.append(hand_scale) optimizer, create_graph = optim_factory.create_optimizer( params, optim_type='lbfgsls', lr=1.0e-1) # optimization print("[Fitting]: fitting the hand scale and translation...") with FittingMonitor(batch_size=batch_size) as monitor: fit_camera = monitor.create_fitting_closure( optimizer, camera, pred_joint_cam, pred_joint_img, hand_translation, hand_scale, self.fitting_loss, create_graph=create_graph) loss_val = monitor.run_fitting( optimizer, fit_camera, params) print(f"[Fitting]: fitting finished with loss of {loss_val}") print(f"Scale: {hand_scale.detach().cpu().numpy()}, Translation: {hand_translation.detach().cpu().numpy()}") return hand_scale, hand_translation def init_weights(m): if type(m) == nn.ConvTranspose2d: nn.init.normal_(m.weight,std=0.001) elif type(m) == nn.Conv2d: nn.init.normal_(m.weight,std=0.001) nn.init.constant_(m.bias, 0) elif type(m) == nn.BatchNorm2d: nn.init.constant_(m.weight,1) nn.init.constant_(m.bias,0) elif type(m) == nn.Linear: nn.init.normal_(m.weight,std=0.01) nn.init.constant_(m.bias,0) def get_model(mode): backbone = FPN(pretrained=True) FIT = Transformer(injection=True) # feature injecting transformer SET = Transformer(injection=False) # self enhancing transformer regressor = Regressor() if mode == 'train': FIT.apply(init_weights) SET.apply(init_weights) regressor.apply(init_weights) model = Model(backbone, FIT, SET, regressor) return model ================================================ FILE: main/test.py ================================================ import torch import argparse from tqdm import tqdm import numpy as np import torch.backends.cudnn as cudnn from config import cfg from base import Tester def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('--gpu', type=str, dest='gpu_ids') parser.add_argument('--test_epoch', type=str, dest='test_epoch') args = parser.parse_args() if not args.gpu_ids: assert 0, "Please set propoer gpu ids" if '-' in args.gpu_ids: gpus = args.gpu_ids.split('-') gpus[0] = int(gpus[0]) gpus[1] = int(gpus[1]) + 1 args.gpu_ids = ','.join(map(lambda x: str(x), list(range(*gpus)))) assert args.test_epoch, 'Test epoch is required.' return args def main(): args = parse_args() cfg.set_args(args.gpu_ids) cudnn.benchmark = True tester = Tester(args.test_epoch) tester._make_batch_generator() tester._make_model() eval_result = {} cur_sample_idx = 0 for itr, (inputs, targets, meta_info) in enumerate(tqdm(tester.batch_generator)): # forward with torch.no_grad(): out = tester.model(inputs, targets, meta_info, 'test') # save output out = {k: v.cpu().numpy() for k,v in out.items()} for k,v in out.items(): batch_size = out[k].shape[0] out = [{k: v[bid] for k,v in out.items()} for bid in range(batch_size)] # evaluate tester._evaluate(out, cur_sample_idx) cur_sample_idx += len(out) tester._print_eval_result(args.test_epoch) if __name__ == "__main__": main() ================================================ FILE: main/train.py ================================================ import argparse from config import cfg import torch from base import Trainer import torch.backends.cudnn as cudnn def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('--gpu', type=str, dest='gpu_ids') parser.add_argument('--continue', dest='continue_train', action='store_true') args = parser.parse_args() if not args.gpu_ids: assert 0, "Please set propoer gpu ids" if '-' in args.gpu_ids: gpus = args.gpu_ids.split('-') gpus[0] = int(gpus[0]) gpus[1] = int(gpus[1]) + 1 args.gpu_ids = ','.join(map(lambda x: str(x), list(range(*gpus)))) return args def main(): # argument parse and create log args = parse_args() cfg.set_args(args.gpu_ids, args.continue_train) cudnn.benchmark = True trainer = Trainer() trainer._make_batch_generator() trainer._make_model() # train for epoch in range(trainer.start_epoch, cfg.end_epoch): trainer.set_lr(epoch) trainer.tot_timer.tic() trainer.read_timer.tic() for itr, (inputs, targets, meta_info) in enumerate(trainer.batch_generator): trainer.read_timer.toc() trainer.gpu_timer.tic() # forward trainer.optimizer.zero_grad() loss = trainer.model(inputs, targets, meta_info, 'train') loss = {k:loss[k].mean() for k in loss} # backward sum(loss[k] for k in loss).backward() trainer.optimizer.step() trainer.gpu_timer.toc() screen = [ 'Epoch %d/%d itr %d/%d:' % (epoch, cfg.end_epoch, itr, trainer.itr_per_epoch), 'lr: %g' % (trainer.get_lr()), 'speed: %.2f(%.2fs r%.2f)s/itr' % ( trainer.tot_timer.average_time, trainer.gpu_timer.average_time, trainer.read_timer.average_time), '%.2fh/epoch' % (trainer.tot_timer.average_time / 3600. * trainer.itr_per_epoch), ] screen += ['%s: %.4f' % ('loss_' + k, v.detach()) for k,v in loss.items()] trainer.logger.info(' '.join(screen)) trainer.tot_timer.toc() trainer.tot_timer.tic() trainer.read_timer.tic() if (epoch+1)%cfg.ckpt_freq== 0 or epoch+1 == cfg.end_epoch: trainer.save_model({ 'epoch': epoch, 'network': trainer.model.state_dict(), 'optimizer': trainer.optimizer.state_dict(), }, epoch+1) if __name__ == "__main__": main() ================================================ FILE: requiremets.sh ================================================ pip install numpy==1.17.4 torch==1.9.1 torchvision==0.10.1 einops chumpy opencv-python pycocotools pyrender tqdm