"src/diffusers/models/autoencoders/vae.py" did not exist on "cc59b05635fb9f4affc6b984c4585372aa32efa8"
Commit f23248c0 authored by facebook-github-bot's avatar facebook-github-bot
Browse files

Initial commit

fbshipit-source-id: f4a8ba78691d8cf46e003ef0bd2e95f170932778
parents
# Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at <opensource-conduct@fb.com>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
# Contributing to d2go
We want to make contributing to this project as easy and transparent as
possible.
## Pull Requests
We actively welcome your pull requests.
1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. If you haven't already, complete the Contributor License Agreement ("CLA").
## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need
to do this once to work on any of Facebook's open source projects.
Complete your CLA here: <https://code.facebook.com/cla>
## Issues
We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.
## License
By contributing to d2go, you agree that your contributions will be licensed
under the LICENSE file in the root directory of this source tree.
name: Unit Test
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: seanmiddleditch/gha-setup-ninja@master
- name: Set up Python
uses: s-weigand/setup-conda@v1
with:
python-version: 3.7
- name: Install Dependencies
run: |
conda install pytorch torchvision -c pytorch-nightly
python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
pip install git+https://github.com/facebookresearch/mobile-vision
pip install scikit-learn
pip install pytest
pip install -e .
- name: Run pytest
env:
OSSRUN: 1
run: |
python -m unittest discover tests
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-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/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# 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/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
*.swp
*.DS_Store
version.py
TARGETS
# internal
*/**/fb/*
*/**/*_fb.py
defs.bzl
datasets/
output/
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2021 - present, Facebook, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
# D2Go Model Zoo and Baselines
## Introduction
This page holds a reference for example configs, pretrained models and training/evaluation metrics. You can access these models from code using d2go.model_zoo API.
### How to
- Train: the "name" column contains a link to the config file. Running `tools/train_net.py --num-gpus 8` with the config file will reproduce the corresponding model.
- Evaluation: Running `tools/train_net.py --eval-only` with the config file and pretrained model will evaluate the results.
- Training curves and other statistics can be found in `metrics` for each model.
### Backbone Models
FBNet series are efficient mobile backbones discovered via neural architecture search, which are specially optimized for mobile devices. Please see details in the [paper](https://arxiv.org/pdf/2006.02049.pdf). If using our code/models in your research, please cite our paper:
```
@article{dai2020fbnetv3,
title={FBNetV3: Joint architecture-recipe search using neural acquisition function},
author={Dai, Xiaoliang and Wan, Alvin and Zhang, Peizhao and Wu, Bichen and He, Zijian and Wei, Zhen and Chen, Kan and Tian, Yuandong and Yu, Matthew and Vajda, Peter and others},
journal={arXiv preprint arXiv:2006.02049},
year={2020}
}
```
## COCO Object Detection
| name | box AP | latency | model id | download |
| ------------------------------------------------------------ | ------ | ------- | --------- | ------------------------------------------------------------ |
| [Faster-RCNN-FBNetV3A](./configs/faster_rcnn_fbnetv3a_C4.yaml) | 22.99 | 59ms | 246823121 | [model](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/246823121/model_0479999.pth) \|[metrics](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/246823121/metrics.json) |
| [Faster-RCNN-FBNetV3A-dsmask](./configs/faster_rcnn_fbnetv3a_dsmask_C4.yaml) | 21.06 | 30ms | 250414811 | [model](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250414811/model_0399999.pth) \|[metrics](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250414811/metrics.json) |
| [Faster-RCNN-FBNetV3G-FPN](./configs/faster_rcnn_fbnetv3g_fpn.yaml) | 43.13 | | 250356938 | [model](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250356938/model_0374999.pth) \|[metrics](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250356938/metrics.json) |
## COCO Instance Segmentation
| name | box AP | mask AP | model id | download |
| ------------------------------------------------------------ | ------ | ------- | --------- | ------------------------------------------------------------ |
| [Mask-RCNN-FBNetV3A](./configs/mask_rcnn_fbnetv3a_C4.yaml) | 23.74 | 21.18 | 250355374 | [model](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250355374/model_0479999.pth) \|[metrics](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250355374/metrics.json) |
| [Mask-RCNN-FBNetV3A-dsmask](./configs/mask_rcnn_fbnetv3a_dsmask_C4.yaml) | 21.81 | 19.76 | 250414867 | [model](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250414867/model_0399999.pth) \|[metrics](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250414867/metrics.json) |
| [Mask-RCNN-FBNetV3G-FPN](./configs/mask_rcnn_fbnetv3g_fpn.yaml) | 43.88 | 39.25 | 250376154 | [model](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250376154/model_0404999.pth) \|[metrics](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250376154/metrics.json) |
### COCO Person Keypoint Detection
| name | box AP | kp. AP | model id | download |
| ------------------------------------------------------------ | ------ | ------ | --------- | ------------------------------------------------------------ |
| [Keypoint-RCNN-FBNetV3A-dsmask](./configs/keypoint_rcnn_fbnetv3a_dsmask_C4.yaml) | 31.24 | 35.56 | 250430934 | [model](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250430934/model_0389999.pth) \|[metrics](https://mobile-cv.s3-us-west-2.amazonaws.com/d2go/models/250430934/metrics.json) |
# D2Go
D2Go is a production ready software system from FacebookResearch, which supports end-to-end model training and deployment for mobile platforms.
## What's D2Go
- It is a deep learning toolkit powered by [PyTorch](https://pytorch.org/) and [Detectron2](https://github.com/facebookresearch/detectron2).
- State-of-the-art efficient backbone networks for mobile devices.
- End-to-end model training, quantization and depoyment pipeline.
- Easy export to TorchScript format for deployment.
## Installation
Install PyTorch Nightly (use CUDA 10.2 as example, see details at [PyTorch Website](https://pytorch.org/get-started/)):
```bash
conda install pytorch torchvision cudatoolkit=10.2 -c pytorch-nightly
```
Install Detectron2 (other installation options at [Detectron2](https://github.com/facebookresearch/detectron2/blob/master/INSTALL.md)):
```bash
python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
```
Install mobile_cv:
```bash
python -m pip install 'git+https://github.com/facebookresearch/mobile-vision.git'
```
Install d2go:
```bash
git clone https://github.com/facebookresearch/d2go
cd d2go & python -m pip install .
```
## Get Started
- Getting Started tutorial Coming soon.
- See our [model zoo](./MODEL_ZOO.md) for example configs and pretrained models.
## License
D2Go is released under the [Apache 2.0 license](LICENSE).
MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
MASK_ON: False
FBNET_V2:
ARCH: "FBNetV3_A"
NORM: "naiveSyncBN"
WIDTH_DIVISOR: 8
BACKBONE:
NAME: FBNetV2C4Backbone
ANCHOR_GENERATOR:
# SIZES: [[32, 64, 128, 256, 512]] # NOTE: for smaller resolution (320 < 512)
SIZES: [[32, 64, 96, 128, 160]]
ASPECT_RATIOS: [[0.5, 1.0, 2.0]] # Three aspect ratios (same for all in feature maps)
RPN:
HEAD_NAME: FBNetV2RpnHead
IN_FEATURES: ["trunk3"]
# Default values are 12000/2000 for train and 6000/1000 for test. In FBNet
# we use smaller numbers. TODO: reduce proposals for test in .yaml directly.
PRE_NMS_TOPK_TRAIN: 2000
POST_NMS_TOPK_TRAIN: 2000
PRE_NMS_TOPK_TEST: 1000
POST_NMS_TOPK_TEST: 30
ROI_HEADS:
NAME: StandardROIHeads
IN_FEATURES: ["trunk3"]
ROI_BOX_HEAD:
NAME: FBNetV2RoIBoxHead
POOLER_RESOLUTION: 6
NORM: "naiveSyncBN"
ROI_MASK_HEAD:
NAME: "MaskRCNNConvUpsampleHead"
NUM_CONV: 4
POOLER_RESOLUTION: 14
MODEL_EMA:
ENABLED: True
DECAY: 0.9998
DATASETS:
TRAIN: ("coco_2017_train",)
TEST: ("coco_2017_val",)
SOLVER:
IMS_PER_BATCH: 32
BASE_LR: 0.16
STEPS: (60000, 80000)
MAX_ITER: 540000
LR_SCHEDULER_NAME: WarmupCosineLR
TEST:
EVAL_PERIOD: 10000
INPUT:
MAX_SIZE_TEST: 320
MAX_SIZE_TRAIN: 320
MIN_SIZE_TEST: 224
MIN_SIZE_TRAIN: (224,)
VERSION: 2
MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
MASK_ON: False
FBNET_V2:
ARCH: "FBNetV3_A_dsmask"
NORM: "naiveSyncBN"
WIDTH_DIVISOR: 8
BACKBONE:
NAME: FBNetV2C4Backbone
ANCHOR_GENERATOR:
# SIZES: [[32, 64, 128, 256, 512]] # NOTE: for smaller resolution (320 < 512)
SIZES: [[32, 64, 96, 128, 160]]
ASPECT_RATIOS: [[0.5, 1.0, 2.0]] # Three aspect ratios (same for all in feature maps)
RPN:
HEAD_NAME: FBNetV2RpnHead
IN_FEATURES: ["trunk3"]
# Default values are 12000/2000 for train and 6000/1000 for test. In FBNet
# we use smaller numbers. TODO: reduce proposals for test in .yaml directly.
PRE_NMS_TOPK_TRAIN: 2000
POST_NMS_TOPK_TRAIN: 2000
PRE_NMS_TOPK_TEST: 1000
POST_NMS_TOPK_TEST: 30
ROI_HEADS:
NAME: StandardROIHeads
IN_FEATURES: ["trunk3"]
ROI_BOX_HEAD:
NAME: FBNetV2RoIBoxHead
POOLER_RESOLUTION: 6
NORM: "naiveSyncBN"
ROI_MASK_HEAD:
NAME: "MaskRCNNConvUpsampleHead"
NUM_CONV: 4
POOLER_RESOLUTION: 14
MODEL_EMA:
ENABLED: True
DECAY: 0.9998
DATASETS:
TRAIN: ("coco_2017_train",)
TEST: ("coco_2017_val",)
SOLVER:
IMS_PER_BATCH: 32
BASE_LR: 0.16
STEPS: (60000, 80000)
MAX_ITER: 540000
LR_SCHEDULER_NAME: WarmupCosineLR
TEST:
EVAL_PERIOD: 10000
INPUT:
MAX_SIZE_TEST: 320
MAX_SIZE_TRAIN: 320
MIN_SIZE_TEST: 224
MIN_SIZE_TRAIN: (224,)
VERSION: 2
MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
MASK_ON: False
FBNET_V2:
ARCH: "FBNetV3_G_fpn"
NORM: "naiveSyncBN"
WIDTH_DIVISOR: 8
BACKBONE:
NAME: FBNetV2FpnBackbone
FREEZE_AT: 0
RESNETS:
DEPTH: 50
OUT_FEATURES: ["res2", "res3", "res4", "res5"]
FPN:
IN_FEATURES: [trunk1, trunk2, trunk3, trunk4]
NORM: "naiveSyncBN"
OUT_CHANNELS: 128 # NOTE: reduce from default 256 channels
ANCHOR_GENERATOR:
SIZES: [[32], [64], [128], [256], [512]] # One size for each in feature map
ASPECT_RATIOS: [[0.5, 1.0, 2.0]] # Three aspect ratios (same for all in feature maps)
RPN:
HEAD_NAME: FBNetV2RpnHead
IN_FEATURES: [p2, p3, p4, p5, p6]
# Default values are 12000/2000 for train and 6000/1000 for test. In FBNet
# we use smaller numbers. TODO: reduce proposals for test in .yaml directly.
PRE_NMS_TOPK_TRAIN: 2000
POST_NMS_TOPK_TRAIN: 2000
PRE_NMS_TOPK_TEST: 1000
POST_NMS_TOPK_TEST: 1000
ROI_HEADS:
NAME: StandardROIHeads
IN_FEATURES: [p3, p4, p5, p6]
ROI_BOX_HEAD:
NAME: FBNetV2RoIBoxHead
POOLER_RESOLUTION: 6
NORM: "naiveSyncBN"
ROI_MASK_HEAD:
NAME: "MaskRCNNConvUpsampleHead"
NUM_CONV: 4
POOLER_RESOLUTION: 14
MODEL_EMA:
ENABLED: True
DECAY: 0.9998
DATASETS:
TRAIN: ("coco_2017_train",)
TEST: ("coco_2017_val",)
SOLVER:
IMS_PER_BATCH: 32
BASE_LR: 0.16
STEPS: (60000, 80000)
MAX_ITER: 450000
LR_SCHEDULER_NAME: WarmupCosineLR
TEST:
EVAL_PERIOD: 5000
INPUT:
MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800)
VERSION: 2
MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
KEYPOINT_ON: True
MASK_ON: False
# WEIGHTS: manifold://xiaoliangdai_model/tree/xiaoliangdai/20210126/faster_rcnn.ULfbyCBZtx/e2e_train/model_0179999.pth
FBNET_V2:
ARCH: "FBNetV3_A_dsmask"
NORM: "naiveSyncBN"
WIDTH_DIVISOR: 8
SCALE_FACTOR: 0.75
BACKBONE:
NAME: FBNetV2C4Backbone
ANCHOR_GENERATOR:
# SIZES: [[32, 64, 128, 256, 512]] # NOTE: for smaller resolution (320 < 512)
SIZES: [[32, 64, 96, 128, 160]] # NOTE: for smaller resolution (320 < 512)
RPN:
HEAD_NAME: FBNetV2RpnHead
IN_FEATURES: ["trunk3"]
# Default values are 12000/2000 for train and 6000/1000 for test. In FBNet
# we use smaller numbers. TODO: reduce proposals for test in .yaml directly.
POST_NMS_TOPK_TEST: 30
POST_NMS_TOPK_TRAIN: 1000
PRE_NMS_TOPK_TEST: 6000
PRE_NMS_TOPK_TRAIN: 4000
ROI_HEADS:
NUM_CLASSES: 1
IN_FEATURES: ["trunk3"]
NAME: StandardROIHeads
ROI_BOX_HEAD:
SMOOTH_L1_BETA: 0.5 # 1.0? Keypoint AP degrades (though box AP improves) when using plain L1 loss
NAME: FBNetV2RoIBoxHead
POOLER_RESOLUTION: 6
NORM: "naiveSyncBN"
ROI_MASK_HEAD:
NAME: "FBNetV2RoIMaskHead"
NUM_CONV: 0
POOLER_RESOLUTION: 6
ROI_KEYPOINT_HEAD:
NAME: FBNetV2RoIKeypointHeadKPRCNNIRFPredictorNoUpscale
POOLER_RESOLUTION: 6
POOLER_SAMPLING_RATIO: 0
POOLER_TYPE: ROIAlignV2
# NUM_KEYPOINTS: 100
PIXEL_MEAN: [103.53, 116.28, 123.675]
PIXEL_STD: [57.375, 57.12, 58.395]
MODEL_EMA:
ENABLED: True
DECAY: 0.9998
DATASETS:
TRAIN: ("keypoints_coco_2017_train",)
TEST: ("keypoints_coco_2017_val",)
# TRAIN: ("02-11-2020_999tasks", "17-11-2020_545tasks", "06-11-2020_623tasks", "30-10-2020_602tasks")
# TEST: ("11-11-2020_387tasks",)
#DATALOADER:
#NUM_WORKERS: 0
SOLVER:
IMS_PER_BATCH: 32
BASE_LR: 0.16
STEPS: (60000, 80000)
MAX_ITER: 450000
LR_SCHEDULER_NAME: WarmupCosineLR
TEST:
EVAL_PERIOD: 5000
# KEYPOINT_OKS_SIGMAS: [0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025, 0.025]
INPUT:
MAX_SIZE_TEST: 448
MAX_SIZE_TRAIN: 448
MIN_SIZE_TEST: 224
MIN_SIZE_TRAIN: (224,)
VERSION: 2
EXPORT_CAFFE2:
USE_HEATMAP_MAX_KEYPOINT: True
#MODEL_EMA:
# DECAY: 0.9998
# DEVICE:
# ENABLED: True
# USE_EMA_WEIGHTS_FOR_EVAL_ONLY: True
MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
MASK_ON: True
FBNET_V2:
ARCH: "FBNetV3_A"
NORM: "naiveSyncBN"
WIDTH_DIVISOR: 8
BACKBONE:
NAME: FBNetV2C4Backbone
ANCHOR_GENERATOR:
# SIZES: [[32, 64, 128, 256, 512]] # NOTE: for smaller resolution (320 < 512)
SIZES: [[32, 64, 96, 128, 160]]
ASPECT_RATIOS: [[0.5, 1.0, 2.0]] # Three aspect ratios (same for all in feature maps)
RPN:
HEAD_NAME: FBNetV2RpnHead
IN_FEATURES: ["trunk3"]
# Default values are 12000/2000 for train and 6000/1000 for test. In FBNet
# we use smaller numbers. TODO: reduce proposals for test in .yaml directly.
PRE_NMS_TOPK_TRAIN: 2000
POST_NMS_TOPK_TRAIN: 2000
PRE_NMS_TOPK_TEST: 1000
POST_NMS_TOPK_TEST: 30
ROI_HEADS:
NAME: StandardROIHeads
IN_FEATURES: ["trunk3"]
ROI_BOX_HEAD:
NAME: FBNetV2RoIBoxHead
POOLER_RESOLUTION: 6
NORM: "naiveSyncBN"
ROI_MASK_HEAD:
NAME: "MaskRCNNConvUpsampleHead"
NUM_CONV: 4
POOLER_RESOLUTION: 14
MODEL_EMA:
ENABLED: True
DECAY: 0.9998
DATASETS:
TRAIN: ("coco_2017_train",)
TEST: ("coco_2017_val",)
SOLVER:
IMS_PER_BATCH: 32
BASE_LR: 0.16
STEPS: (60000, 80000)
MAX_ITER: 540000
LR_SCHEDULER_NAME: WarmupCosineLR
TEST:
EVAL_PERIOD: 10000
INPUT:
MAX_SIZE_TEST: 320
MAX_SIZE_TRAIN: 320
MIN_SIZE_TEST: 224
MIN_SIZE_TRAIN: (224,)
VERSION: 2
MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
MASK_ON: True
FBNET_V2:
ARCH: "FBNetV3_A_dsmask"
NORM: "naiveSyncBN"
WIDTH_DIVISOR: 8
BACKBONE:
NAME: FBNetV2C4Backbone
ANCHOR_GENERATOR:
# SIZES: [[32, 64, 128, 256, 512]] # NOTE: for smaller resolution (320 < 512)
SIZES: [[32, 64, 96, 128, 160]]
ASPECT_RATIOS: [[0.5, 1.0, 2.0]] # Three aspect ratios (same for all in feature maps)
RPN:
HEAD_NAME: FBNetV2RpnHead
IN_FEATURES: ["trunk3"]
# Default values are 12000/2000 for train and 6000/1000 for test. In FBNet
# we use smaller numbers. TODO: reduce proposals for test in .yaml directly.
PRE_NMS_TOPK_TRAIN: 2000
POST_NMS_TOPK_TRAIN: 2000
PRE_NMS_TOPK_TEST: 1000
POST_NMS_TOPK_TEST: 30
ROI_HEADS:
NAME: StandardROIHeads
IN_FEATURES: ["trunk3"]
ROI_BOX_HEAD:
NAME: FBNetV2RoIBoxHead
POOLER_RESOLUTION: 6
NORM: "naiveSyncBN"
ROI_MASK_HEAD:
NAME: "MaskRCNNConvUpsampleHead"
NUM_CONV: 4
POOLER_RESOLUTION: 14
MODEL_EMA:
ENABLED: True
DECAY: 0.9998
DATASETS:
TRAIN: ("coco_2017_train",)
TEST: ("coco_2017_val",)
SOLVER:
IMS_PER_BATCH: 32
BASE_LR: 0.16
STEPS: (60000, 80000)
MAX_ITER: 540000
LR_SCHEDULER_NAME: WarmupCosineLR
TEST:
EVAL_PERIOD: 10000
INPUT:
MAX_SIZE_TEST: 320
MAX_SIZE_TRAIN: 320
MIN_SIZE_TEST: 224
MIN_SIZE_TRAIN: (224,)
VERSION: 2
MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
MASK_ON: True
FBNET_V2:
ARCH: "FBNetV3_G_fpn"
NORM: "naiveSyncBN"
WIDTH_DIVISOR: 8
BACKBONE:
NAME: FBNetV2FpnBackbone
FREEZE_AT: 0
RESNETS:
DEPTH: 50
OUT_FEATURES: ["res2", "res3", "res4", "res5"]
FPN:
IN_FEATURES: [trunk1, trunk2, trunk3, trunk4]
NORM: "naiveSyncBN"
OUT_CHANNELS: 128 # NOTE: reduce from default 256 channels
ANCHOR_GENERATOR:
SIZES: [[32], [64], [128], [256], [512]] # One size for each in feature map
ASPECT_RATIOS: [[0.5, 1.0, 2.0]] # Three aspect ratios (same for all in feature maps)
RPN:
HEAD_NAME: FBNetV2RpnHead
IN_FEATURES: [p2, p3, p4, p5, p6]
# Default values are 12000/2000 for train and 6000/1000 for test. In FBNet
# we use smaller numbers. TODO: reduce proposals for test in .yaml directly.
PRE_NMS_TOPK_TRAIN: 2000
POST_NMS_TOPK_TRAIN: 2000
PRE_NMS_TOPK_TEST: 1000
POST_NMS_TOPK_TEST: 1000
ROI_HEADS:
NAME: StandardROIHeads
IN_FEATURES: [p3, p4, p5, p6]
ROI_BOX_HEAD:
NAME: FBNetV2RoIBoxHead
POOLER_RESOLUTION: 6
NORM: "naiveSyncBN"
ROI_MASK_HEAD:
NAME: "MaskRCNNConvUpsampleHead"
NUM_CONV: 4
POOLER_RESOLUTION: 14
MODEL_EMA:
ENABLED: True
DECAY: 0.9998
DATASETS:
TRAIN: ("coco_2017_train",)
TEST: ("coco_2017_val",)
SOLVER:
IMS_PER_BATCH: 32
BASE_LR: 0.16
STEPS: (60000, 80000)
MAX_ITER: 450000
LR_SCHEDULER_NAME: WarmupCosineLR
TEST:
EVAL_PERIOD: 5000
INPUT:
MIN_SIZE_TRAIN: (640, 672, 704, 736, 768, 800)
VERSION: 2
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
# Set up custom environment before nearly anything else is imported
# NOTE: this should be the first import (no not reorder)
from d2go import initializer, optimizer # NOQA
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from .config import ( # noqa, forward namespace
CONFIG_SCALING_METHOD_REGISTRY,
CfgNode,
auto_scale_world_size,
reroute_config_path,
get_cfg_diff_table,
)
from .utils import temp_defrost # noqa, forward namespace
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import contextlib
import logging
import os
import mock
import yaml
from detectron2.config import CfgNode as _CfgNode
from fvcore.common.registry import Registry
from d2go.utils.helper import reroute_config_path
logger = logging.getLogger(__name__)
def get_cfg_diff_table(cfg, original_cfg):
# print out the differences
from d2go.config import CfgNode
def _find_all_keys(obj):
assert isinstance(obj, CfgNode)
ret = []
for key in sorted(obj.keys()):
value = obj[key]
if isinstance(value, CfgNode):
for sub_key in _find_all_keys(value):
ret.append("{}.{}".format(key, sub_key))
else:
ret.append(key)
return ret
def _get_value(obj, full_key):
for k in full_key.split("."):
obj = obj[k]
return obj
all_old_keys = _find_all_keys(original_cfg)
all_new_keys = _find_all_keys(cfg)
assert all_old_keys == all_new_keys
diff_table = []
for full_key in all_new_keys:
old_value = _get_value(original_cfg, full_key)
new_value = _get_value(cfg, full_key)
if old_value != new_value:
diff_table.append([full_key, old_value, new_value])
from tabulate import tabulate
table = tabulate(
diff_table,
tablefmt="pipe",
headers=["config key", "old value", "new value"],
)
return table
class CfgNode(_CfgNode):
def merge_from_file(self, cfg_filename: str, *args, **kwargs):
cfg_filename = reroute_config_path(cfg_filename)
with reroute_load_yaml_with_base():
return super().merge_from_file(cfg_filename, *args, **kwargs)
@staticmethod
def load_yaml_with_base(filename: str, *args, **kwargs):
with reroute_load_yaml_with_base():
return _CfgNode.load_yaml_with_base(filename, *args, **kwargs)
def merge_from_other_cfg(self, cfg_other):
# NOTE: D24397488 changes default MODEL.FBNET_V2.ARCH_DEF from "" to [], change
# the value to be able to load old full configs.
# TODO: remove this by end of 2020.
if cfg_other.get("MODEL", {}).get("FBNET_V2", {}).get("ARCH_DEF", None) == "":
import logging
logger = logging.getLogger(__name__)
logger.warning("Default value for MODEL.FBNET_V2.ARCH_DEF has changed to []")
cfg_other.MODEL.FBNET_V2.ARCH_DEF = []
return super().merge_from_other_cfg(cfg_other)
def __hash__(self):
# dump follows alphabetical order, thus good for hash use
return hash(self.dump())
@contextlib.contextmanager
def reroute_load_yaml_with_base():
BASE_KEY = "_BASE_"
_safe_load = yaml.safe_load
_unsafe_load = yaml.unsafe_load
def mock_safe_load(f):
cfg = _safe_load(f)
if BASE_KEY in cfg:
cfg[BASE_KEY] = reroute_config_path(cfg[BASE_KEY])
return cfg
def mock_unsafe_load(f):
cfg = _unsafe_load(f)
if BASE_KEY in cfg:
cfg[BASE_KEY] = reroute_config_path(cfg[BASE_KEY])
return cfg
with mock.patch("yaml.safe_load", side_effect=mock_safe_load):
with mock.patch("yaml.unsafe_load", side_effect=mock_unsafe_load):
yield
CONFIG_SCALING_METHOD_REGISTRY = Registry("CONFIG_SCALING_METHOD")
def auto_scale_world_size(cfg, new_world_size):
"""
Usually the config file is written for a specific number of devices, this method
scales the config (in-place!) according to the actual world size using the
pre-registered scaling methods specified as cfg.SOLVER.AUTO_SCALING_METHODS.
Note for registering scaling methods:
- The method will only be called when scaling is needed. It won't be called
if SOLVER.REFERENCE_WORLD_SIZE is 0 or equal to target world size. Thus
cfg.SOLVER.REFERENCE_WORLD_SIZE will always be positive.
- The method updates cfg in-place, no return is required.
- No need for changing SOLVER.REFERENCE_WORLD_SIZE.
Args:
cfg (CfgNode): original config which contains SOLVER.REFERENCE_WORLD_SIZE and
SOLVER.AUTO_SCALING_METHODS.
new_world_size: the target world size
"""
old_world_size = cfg.SOLVER.REFERENCE_WORLD_SIZE
if old_world_size == 0 or old_world_size == new_world_size:
return cfg
original_cfg = cfg.clone()
frozen = original_cfg.is_frozen()
cfg.defrost()
assert len(cfg.SOLVER.AUTO_SCALING_METHODS) > 0, cfg.SOLVER.AUTO_SCALING_METHODS
for scaling_method in cfg.SOLVER.AUTO_SCALING_METHODS:
logger.info("Applying auto scaling method: {}".format(scaling_method))
CONFIG_SCALING_METHOD_REGISTRY.get(scaling_method)(cfg, new_world_size)
assert (
cfg.SOLVER.REFERENCE_WORLD_SIZE == cfg.SOLVER.REFERENCE_WORLD_SIZE
), "Runner's scale_world_size shouldn't change SOLVER.REFERENCE_WORLD_SIZE"
cfg.SOLVER.REFERENCE_WORLD_SIZE = new_world_size
if frozen:
cfg.freeze()
table = get_cfg_diff_table(cfg, original_cfg)
logger.info("Auto-scaled the config according to the actual world size: \n" + table)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import contextlib
import copy
import json
import shlex
from typing import Dict, List
@contextlib.contextmanager
def temp_defrost(cfg):
is_frozen = cfg.is_frozen()
if is_frozen:
cfg.defrost()
yield cfg
if is_frozen:
cfg.freeze()
def str_wrap_fbnet_arch_def(d: Dict, inplace=False) -> Dict:
"""Replaces MODEL.FBNET_V2.ARCH_DEF with wrapped json string
Searches the input dict to see if it contains MODEL.FBNET_V2.ARCH_DEF
and replaces the value with a wrapped json string
The json string is created because FBNet builder runs json.loads on the
archdef. The json string needs to be wrapped in another string because
CfgNode runs literal_eval in order to check whether it should continue
to create CfgNodes if the value is a dict.
arch_def = {...} # {...}
arch_def = json.dumps(arch_def) # '{...}'
arch_def = strwrap(arch_def) # '"{...}"'
CfgNode(arch_def) => literal_eval(arch_def) # '{...}'
FBNetBuilder(arch_def) => json.loads(arch_def) # {...}
Example:
config = {"MODEL": {"FBNET_V2": {"ARCH_DEF": [1, 1, 1]}}}
str_wrap_fbnet_arch_def(config)
=> {"MODEL": {"FBNET_V2": {"ARCH_DEF": '''"[1, 1, 1]"'''}}}
"""
if not inplace:
d = copy.deepcopy(d)
try:
archdef = d["MODEL"]["FBNET_V2"]["ARCH_DEF"]
# MODEL.FBNET_V2.ARCH_DEF needs to be json str
archdef = json.dumps(archdef)
# CfgNode runs literal_eval when merging so wrap around str
archdef = shlex.quote(archdef)
d["MODEL"]["FBNET_V2"]["ARCH_DEF"] = archdef
except KeyError:
pass
return d
def flatten_config_dict(x, prefix=""):
"""Flattens config dict into single layer dict
Example:
flatten_config_dict({
MODEL: {
FBNET_V2: {
ARCH_DEF: "val0"
}
}
})
=> {"MODEL.FBNET_V2.ARCH_DEF": "val0"}
"""
if not isinstance(x, dict):
return {prefix: x}
d = {}
for k, v in x.items():
new_key = f"{prefix}.{k}" if prefix else k
d.update(flatten_config_dict(v, new_key))
return d
def config_dict_to_list_str(config_dict: Dict) -> List[str]:
"""Creates a list of str given configuration dict
This can be useful to generate pretraining or overwrite opts
in D2Go when a user has config_dict
"""
d = flatten_config_dict(config_dict)
str_list = []
for k, v in d.items():
str_list.append(k)
str_list.append(str(v))
return str_list
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import d2go.data.datasets
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import itertools
import logging
import operator
from collections import OrderedDict, defaultdict
from typing import Dict
import torch
from d2go.config import CfgNode
from d2go.data.utils import ClipLengthGroupedDataset
from detectron2.data import build_batch_data_loader, get_detection_dataset_dicts
from detectron2.data.build import worker_init_reset_seed
from detectron2.data.common import MapDataset, DatasetFromList
from detectron2.data.dataset_mapper import DatasetMapper
from detectron2.data.samplers import RepeatFactorTrainingSampler
from detectron2.utils.comm import get_world_size
def add_weighted_training_sampler_default_configs(cfg: CfgNode):
"""
The CfgNode under cfg.DATASETS.TRAIN_REPEAT_FACTOR should be a list of
tuples (dataset_name, scalar-repeat-factor) specifying upsampled frequencies
for each dataset when using RepeatFactorTrainingSampler. An example looks like:
DATASETS:
TRAIN:
- "train_1"
- "train_2"
- "small_train_3"
TEST: ...
TRAIN_REPEAT_FACTOR:
- ["small_train_3", 2.5]
"""
cfg.DATASETS.TRAIN_REPEAT_FACTOR = []
def get_train_datasets_repeat_factors(cfg: CfgNode) -> Dict[str, float]:
repeat_factors = cfg.DATASETS.TRAIN_REPEAT_FACTOR
assert all(len(tup) == 2 for tup in repeat_factors)
name_to_weight = defaultdict(lambda: 1, dict(repeat_factors))
# The sampling weights map should only contain datasets in train config
unrecognized = set(name_to_weight.keys()) - set(cfg.DATASETS.TRAIN)
assert not unrecognized, f"unrecognized datasets: {unrecognized}"
logger = logging.getLogger(__name__)
logger.info(f"Found repeat factors: {list(name_to_weight.items())}")
# pyre-fixme[7]: Expected `Dict[str, float]` but got `DefaultDict[typing.Any, int]`.
return name_to_weight
def build_weighted_detection_train_loader(cfg: CfgNode, mapper=None):
dataset_repeat_factors = get_train_datasets_repeat_factors(cfg)
# OrderedDict to guarantee order of values() consistent with repeat factors
dataset_name_to_dicts = OrderedDict(
{
name: get_detection_dataset_dicts(
[name],
filter_empty=cfg.DATALOADER.FILTER_EMPTY_ANNOTATIONS,
min_keypoints=cfg.MODEL.ROI_KEYPOINT_HEAD.MIN_KEYPOINTS_PER_IMAGE
if cfg.MODEL.KEYPOINT_ON
else 0,
proposal_files=cfg.DATASETS.PROPOSAL_FILES_TRAIN
if cfg.MODEL.LOAD_PROPOSALS
else None,
)
for name in cfg.DATASETS.TRAIN
}
)
# Repeat factor for every sample in the dataset
repeat_factors = [
[dataset_repeat_factors[dsname]] * len(dataset_name_to_dicts[dsname])
for dsname in cfg.DATASETS.TRAIN
]
repeat_factors = list(itertools.chain.from_iterable(repeat_factors))
dataset_dicts = dataset_name_to_dicts.values()
dataset_dicts = list(itertools.chain.from_iterable(dataset_dicts))
dataset = DatasetFromList(dataset_dicts, copy=False)
if mapper is None:
mapper = DatasetMapper(cfg, True)
dataset = MapDataset(dataset, mapper)
logger = logging.getLogger(__name__)
logger.info(
"Using WeightedTrainingSampler with repeat_factors={}".format(
cfg.DATASETS.TRAIN_REPEAT_FACTOR
)
)
sampler = RepeatFactorTrainingSampler(torch.tensor(repeat_factors))
return build_batch_data_loader(
dataset,
sampler,
cfg.SOLVER.IMS_PER_BATCH,
aspect_ratio_grouping=cfg.DATALOADER.ASPECT_RATIO_GROUPING,
num_workers=cfg.DATALOADER.NUM_WORKERS,
)
def build_clip_grouping_data_loader(dataset, sampler, total_batch_size, num_workers=0):
"""
Build a batched dataloader for training with video clips.
Args:
dataset (torch.utils.data.Dataset): map-style PyTorch dataset. Can be indexed.
sampler (torch.utils.data.sampler.Sampler): a sampler that produces indices
total_batch_size (int): total batch size across GPUs.
num_workers (int): number of parallel data loading workers
Returns:
iterable[list]. Length of each list is the batch size of the current
GPU. Each element in the list comes from the dataset.
"""
world_size = get_world_size()
assert (
total_batch_size > 0 and total_batch_size % world_size == 0
), "Total batch size ({}) must be divisible by the number of gpus ({}).".format(
total_batch_size, world_size
)
batch_size = total_batch_size // world_size
data_loader = torch.utils.data.DataLoader(
dataset,
sampler=sampler,
num_workers=num_workers,
batch_sampler=None,
collate_fn=operator.itemgetter(0), # don't batch, but yield individual elements
worker_init_fn=worker_init_reset_seed,
) # yield individual mapped dict
return ClipLengthGroupedDataset(data_loader, batch_size)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment