├── docs ├── .gitignore ├── requirements.txt ├── source │ ├── setup.rst │ ├── modules.rst │ ├── jaclearn.mldash.rst │ ├── jaclearn.nlp.sng_parser.rst │ ├── jactorch.nn.sync_batchnorm.rst │ ├── jactf.rst │ ├── jacinle.storage.rst │ ├── jactorch.models.rst │ ├── jacinle.jit.rst │ ├── jacinle.web.rst │ ├── jaclearn.models.rst │ ├── jaclearn.datasets.rst │ ├── jaclearn.rl.engines.rst │ ├── jaclearn.nlp.graph.rst │ ├── jaclearn.logic.rst │ ├── jaclearn.nlp.rst │ ├── jaclearn.logic.propositional.rst │ ├── jactf.utils.rst │ ├── jactorch.cuda.rst │ ├── jacinle.random.rst │ ├── jaclearn.math.rst │ ├── jacinle.logging.rst │ ├── jacinle.jit.cext.rst │ ├── jactorch.transforms.rst │ ├── jacinle.web.app.rst │ ├── jacinle.jit.cython.rst │ ├── jaclearn.rl.envs.nintendo.rst │ ├── jactorch.nn.prroi_pool.rst │ ├── jaclearn.rl.envs.simple.rst │ ├── jaclearn.logic.decision_tree.rst │ ├── jaclearn.rl.engines.mujoco.rst │ ├── jaclearn.models.naive_bayes.rst │ ├── jacinle.rst │ ├── jaclearn.rst │ ├── jaclearn.data.rst │ ├── jaclearn.rl.algo.rst │ ├── jactorch.transforms.vision.rst │ ├── jactorch.nn.losses.rst │ ├── jaclearn.rl.envs.maze.rst │ ├── jacinle.web.session.rst │ ├── jactorch.models.vision.rst │ ├── jaclearn.rl.simulator.rst │ ├── jactorch.transforms.bbox.rst │ ├── jactorch.transforms.coor.rst │ ├── jactorch.transforms.image.rst │ ├── jactorch.nn.gumbel_softmax.rst │ ├── jactorch.data.rst │ ├── jactorch.data.dataloader.rst │ ├── jacinle.config.rst │ ├── jaclearn.vision.coco.rst │ ├── jaclearn.rl.envs.rst │ ├── jactorch.nn.neural_logic.modules.rst │ ├── jactorch.quickstart.rst │ ├── index.rst │ ├── jactorch.nn.neural_logic.rst │ ├── jacinle.comm.distrib.rst │ ├── jacinle.nd.rst │ ├── jactorch.rst │ ├── jaclearn.logic.propositional.logic_induction.rst │ ├── jaclearn.rl.rst │ ├── jacinle.cli.rst │ ├── jactorch.train.rst │ ├── jacinle.image.rst │ ├── jactorch.utils.rst │ ├── jaclearn.vision.rst │ ├── jactorch.graph.rst │ ├── jaclearn.vision.coco.pycocotools.rst │ ├── jactorch.nn.cnn.rst │ ├── jacinle.storage.kv.rst │ ├── jaclearn.dataflow.rst │ ├── jaclearn.imageaug.rst │ ├── jaclearn.nlp.tree.rst │ ├── jactorch.transforms.vision.functional.rst │ ├── jacinle.io.rst │ ├── jaclearn.datasets.image_classification.rst │ ├── jaclearn.embedding.rst │ ├── jactorch.data.collate.rst │ ├── jaclearn.nlp.graph.dependency_visualizer.rst │ ├── jacinle.comm.rst │ ├── jaclearn.visualize.rst │ ├── jactorch.optim.rst │ ├── jactorch.vision.rst │ └── jactorch.parallel.rst └── Makefile ├── bin ├── jac-docs-server ├── jac-inspect-file ├── jac-name-server ├── jac-format-header ├── jac-service-name-server ├── jac-debug ├── jac-crun ├── jac-cdebug ├── jac-mldash ├── jac-run ├── jac-script.sh ├── jac-update ├── jac-export-init └── _jac-init.sh ├── jaclearn ├── vision │ ├── coco │ │ ├── .gitignore │ │ ├── src │ │ │ └── .gitignore │ │ ├── pycocotools │ │ │ └── __init__.py │ │ ├── travis.sh │ │ ├── mask_utils.py │ │ ├── __init__.py │ │ └── setup.py │ ├── __init__.py │ ├── graph_cut.py │ ├── graph_cut_inpaint.py │ └── patch_match.py ├── logic │ ├── propositional │ │ ├── logic_induction │ │ │ ├── .gitignore │ │ │ ├── travis.sh │ │ │ ├── setup.py │ │ │ └── logic_induction.pxd │ │ └── __init__.py │ ├── __init__.py │ └── decision_tree │ │ └── __init__.py ├── __init__.py ├── rl │ ├── __init__.py │ ├── algo │ │ ├── __init__.py │ │ └── advantage.py │ ├── envs │ │ ├── __init__.py │ │ ├── maze │ │ │ └── __init__.py │ │ ├── nintendo │ │ │ └── __init__.py │ │ └── simple │ │ │ ├── __init__.py │ │ │ └── move_right.py │ ├── engines │ │ ├── __init__.py │ │ └── mujoco │ │ │ └── __init__.py │ └── simulator │ │ ├── __init__.py │ │ └── pack.py ├── data │ ├── __init__.py │ └── stat.py ├── dataflow │ └── __init__.py ├── datasets │ ├── __init__.py │ └── image_classification │ │ ├── __init__.py │ │ ├── mnist.py │ │ └── svhn.py ├── imageaug │ ├── __init__.py │ └── cblk.py ├── embedding │ ├── __init__.py │ └── constant.py ├── math │ └── __init__.py ├── models │ ├── __init__.py │ └── naive_bayes │ │ └── __init__.py ├── nlp │ ├── graph │ │ ├── __init__.py │ │ └── dependency_visualizer │ │ │ ├── __init__.py │ │ │ └── utils.py │ ├── __init__.py │ ├── tree │ │ └── __init__.py │ └── sng_parser │ │ └── __init__.py ├── mldash │ └── __init__.py └── visualize │ └── __init__.py ├── examples ├── html-table │ ├── .gitignore │ └── gen.py ├── dependency-visualizer │ ├── .gitignore │ └── example.py ├── torch-jacvision │ └── i_image.png ├── web-starter │ ├── app │ │ ├── __init__.py │ │ ├── templates │ │ │ └── index.html │ │ └── index.py │ └── main.py ├── cython │ └── csrc │ │ └── loop.c ├── utils-ipdb │ └── main.py ├── comm-service-nameserver │ ├── client.py │ ├── server.py │ └── README.md ├── learn-logic │ └── propositional-induction.py ├── comm-distrib │ ├── in.py │ ├── out.py │ └── in_benchmark.py ├── utils-defaults │ └── default_args.py ├── kv-lmdb │ ├── lmdb-single.py │ ├── lmdb-multi-read.py │ └── lmdb-multi.py ├── python-starter │ └── script.py ├── configs │ └── test-configs-envrion2.py ├── comm-cs │ ├── client.py │ └── server.py ├── comm-service │ ├── server.py │ └── client.py ├── torch-dataloader │ └── syncable_dataset.py └── comm-broadcast-gather │ ├── gather.py │ └── broadcast.py ├── docs2 ├── .gitignore ├── source │ ├── _static │ │ ├── overview.png │ │ └── custom.css │ ├── api.rst │ └── _templates │ │ └── class.rst ├── requirements.txt ├── Makefile └── make.bat ├── requirements-optional.txt ├── .gitattributes ├── jactorch ├── nn │ ├── prroi_pool │ │ ├── .gitignore │ │ ├── __init__.py │ │ └── functional.py │ ├── neural_logic │ │ ├── modules │ │ │ └── __init__.py │ │ └── __init__.py │ ├── losses │ │ └── __init__.py │ ├── gumbel_softmax │ │ ├── __init__.py │ │ └── softmax.py │ ├── cnn │ │ └── __init__.py │ ├── functional.py │ ├── __init__.py │ ├── container.py │ ├── linear.py │ ├── sync_batchnorm │ │ └── __init__.py │ └── simple.py ├── data │ ├── __init__.py │ ├── dataloader │ │ └── __init__.py │ └── collate │ │ ├── __init__.py │ │ └── utils.py ├── models │ ├── __init__.py │ └── vision │ │ └── __init__.py ├── transforms │ ├── __init__.py │ ├── vision │ │ ├── functional │ │ │ └── __init__.py │ │ └── __init__.py │ ├── bbox │ │ └── __init__.py │ ├── coor │ │ └── __init__.py │ └── image │ │ ├── __init__.py │ │ ├── transforms.py │ │ └── functional.py ├── cuda │ ├── __init__.py │ └── copy.py ├── parallel │ └── __init__.py ├── utils │ ├── __init__.py │ ├── grad.py │ ├── unittest.py │ └── init.py ├── train │ ├── __init__.py │ └── utils.py ├── quickstart │ └── __init__.py ├── graph │ └── __init__.py ├── optim │ ├── __init__.py │ ├── quickaccess.py │ └── custom_optimizer_base.py ├── vision │ ├── __init__.py │ ├── _utils.py │ ├── geometry.py │ └── peak.py ├── functional │ ├── clustering.py │ ├── __init__.py │ ├── probability.py │ └── linalg.py ├── cli.py └── serve │ └── service.py ├── requirements.txt ├── jacinle ├── cli │ └── __init__.py ├── comm │ ├── __init__.py │ └── distrib │ │ ├── __init__.py │ │ └── _configs.py ├── config │ ├── __init__.py │ └── g.py ├── jit │ ├── __init__.py │ ├── cext │ │ └── __init__.py │ └── cython │ │ └── __init__.py ├── storage │ ├── __init__.py │ ├── kv │ │ ├── __init__.py │ │ └── mem.py │ └── unsafe_queue.py ├── utils │ ├── __init__.py │ ├── uid.py │ ├── exception.py │ ├── deprecated.py │ ├── init.py │ ├── context.py │ ├── value_scheduler.py │ └── vendor.py ├── concurrency │ ├── __init__.py │ ├── future.py │ ├── process.py │ └── queue.py ├── random │ └── __init__.py ├── image │ ├── __init__.py │ └── imgio.py ├── nd │ └── __init__.py ├── io │ └── __init__.py └── web │ └── __init__.py ├── jactf ├── utils │ ├── __init__.py │ └── init.py └── __init__.py ├── vendors └── pytorch_reservoir │ ├── travis.sh │ └── pytorch_reservoir.py ├── .vim-template:.py ├── tests └── test-utils-debug.py ├── jacinle.yml ├── scripts ├── service-name-server.py ├── name-server.py └── inspect-file.py ├── pyproject.toml ├── LICENSE └── .gitmodules /docs/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | -------------------------------------------------------------------------------- /bin/jac-docs-server: -------------------------------------------------------------------------------- 1 | jac-script.sh -------------------------------------------------------------------------------- /bin/jac-inspect-file: -------------------------------------------------------------------------------- 1 | jac-script.sh -------------------------------------------------------------------------------- /bin/jac-name-server: -------------------------------------------------------------------------------- 1 | jac-script.sh -------------------------------------------------------------------------------- /bin/jac-format-header: -------------------------------------------------------------------------------- 1 | jac-script.sh -------------------------------------------------------------------------------- /bin/jac-service-name-server: -------------------------------------------------------------------------------- 1 | jac-script.sh -------------------------------------------------------------------------------- /jaclearn/vision/coco/.gitignore: -------------------------------------------------------------------------------- 1 | *.c 2 | -------------------------------------------------------------------------------- /examples/html-table/.gitignore: -------------------------------------------------------------------------------- 1 | /generated 2 | -------------------------------------------------------------------------------- /docs2/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | source/reference/ 3 | -------------------------------------------------------------------------------- /jaclearn/vision/coco/src/.gitignore: -------------------------------------------------------------------------------- 1 | !/maskApi.c 2 | -------------------------------------------------------------------------------- /requirements-optional.txt: -------------------------------------------------------------------------------- 1 | peewee 2 | lmdb 3 | 4 | -------------------------------------------------------------------------------- /examples/dependency-visualizer/.gitignore: -------------------------------------------------------------------------------- 1 | /index.html 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sh text eol=lf 2 | jac-* text eol=lf 3 | 4 | -------------------------------------------------------------------------------- /docs2/source/_static/overview.png: -------------------------------------------------------------------------------- 1 | ../../../_assets/overview.png -------------------------------------------------------------------------------- /jactorch/nn/prroi_pool/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | /_prroi_pooling 3 | -------------------------------------------------------------------------------- /docs2/requirements.txt: -------------------------------------------------------------------------------- 1 | -r ../requirements.txt 2 | pydata_sphinx_theme 3 | -------------------------------------------------------------------------------- /jaclearn/vision/coco/pycocotools/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'tylin' 2 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | -r ../requirements.txt 2 | pymemcache 3 | gym 4 | tornado 5 | -------------------------------------------------------------------------------- /jaclearn/logic/propositional/logic_induction/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /logic_induction.cpp 3 | /*.so 4 | -------------------------------------------------------------------------------- /examples/torch-jacvision/i_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vacancy/Jacinle/HEAD/examples/torch-jacvision/i_image.png -------------------------------------------------------------------------------- /docs/source/setup.rst: -------------------------------------------------------------------------------- 1 | setup module 2 | ============ 3 | 4 | .. automodule:: setup 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Cython 2 | pkgconfig 3 | tabulate 4 | ipdb 5 | pyyaml 6 | tqdm 7 | pyzmq 8 | numpy 9 | scipy 10 | scikit-learn 11 | matplotlib 12 | -------------------------------------------------------------------------------- /bin/jac-debug: -------------------------------------------------------------------------------- 1 | #!/bin/bash -E 2 | 3 | 4 | JACROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )" 5 | 6 | export JAC_DEBUG=1 7 | $JACROOT/bin/jac-run "$@" 8 | 9 | -------------------------------------------------------------------------------- /bin/jac-crun: -------------------------------------------------------------------------------- 1 | #!/bin/bash -E 2 | 3 | JACROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )" 4 | 5 | export CUDA_VISIBLE_DEVICES=$1 && shift 6 | $JACROOT/bin/jac-run "$@" 7 | 8 | -------------------------------------------------------------------------------- /docs/source/modules.rst: -------------------------------------------------------------------------------- 1 | Jacinle 2 | ======= 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | 8 | jacinle 9 | jaclearn 10 | jactf 11 | jactorch 12 | setup 13 | -------------------------------------------------------------------------------- /docs/source/jaclearn.mldash.rst: -------------------------------------------------------------------------------- 1 | jaclearn.mldash package 2 | ======================= 3 | 4 | .. automodule:: jaclearn.mldash 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /bin/jac-cdebug: -------------------------------------------------------------------------------- 1 | #!/bin/bash -E 2 | 3 | JACROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )" 4 | 5 | export JAC_DEBUG=1 6 | export CUDA_VISIBLE_DEVICES=$1 && shift 7 | $JACROOT/bin/jac-run "$@" 8 | 9 | -------------------------------------------------------------------------------- /docs/source/jaclearn.nlp.sng_parser.rst: -------------------------------------------------------------------------------- 1 | jaclearn.nlp.sng\_parser package 2 | ================================ 3 | 4 | .. automodule:: jaclearn.nlp.sng_parser 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /bin/jac-mldash: -------------------------------------------------------------------------------- 1 | #!/bin/bash -E 2 | 3 | JACROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )" 4 | 5 | source $JACROOT/bin/_jac-init.sh $JACROOT 6 | 7 | exec python3 $JACROOT/vendors/JacMLDash/scripts/web-server.py "$@" 8 | 9 | -------------------------------------------------------------------------------- /docs/source/jactorch.nn.sync_batchnorm.rst: -------------------------------------------------------------------------------- 1 | jactorch.nn.sync\_batchnorm package 2 | =================================== 3 | 4 | .. automodule:: jactorch.nn.sync_batchnorm 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /bin/jac-run: -------------------------------------------------------------------------------- 1 | #!/bin/bash -E 2 | 3 | JACROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )" 4 | 5 | source $JACROOT/bin/_jac-init.sh $JACROOT 6 | 7 | if [[ $1 == *.py ]]; then 8 | exec python "$@" && exit 9 | fi 10 | exec "$@" 11 | 12 | -------------------------------------------------------------------------------- /docs/source/jactf.rst: -------------------------------------------------------------------------------- 1 | jactf package 2 | ============= 3 | 4 | .. automodule:: jactf 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jactf.utils 16 | -------------------------------------------------------------------------------- /bin/jac-script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -E 2 | 3 | JACROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )" 4 | SCRIPT=$( basename ${BASH_SOURCE[0]} ) 5 | SCRIPT=${SCRIPT:4} 6 | 7 | source $JACROOT/bin/_jac-init.sh $JACROOT 8 | exec python3 "$JACROOT/scripts/$SCRIPT.py" "$@" 9 | 10 | -------------------------------------------------------------------------------- /jacinle/cli/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jacinle/comm/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/22/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/15/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/rl/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/17/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jactf/utils/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/01/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jacinle/config/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jacinle/jit/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/06/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jacinle/storage/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jacinle/utils/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/data/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/dataflow/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/imageaug/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/rl/algo/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/17/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/rl/envs/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/17/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jactorch/data/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/01/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jactorch/models/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/31/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /bin/jac-update: -------------------------------------------------------------------------------- 1 | #!/bin/bash -E 2 | 3 | JACROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )" 4 | CUR=`pwd` 5 | 6 | cd $JACROOT 7 | echo "Updating Jacinle" 8 | git pull --recurse-submodules 9 | echo "Updating Submodules" 10 | git submodule update --init --recursive 11 | cd $CUR 12 | 13 | -------------------------------------------------------------------------------- /jacinle/concurrency/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jacinle/storage/kv/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/embedding/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/24/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/logic/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/16/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jaclearn/math/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/16/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jaclearn/models/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 06/01/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jaclearn/rl/envs/maze/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/17/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/vision/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/06/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jaclearn/vision/coco/travis.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # File : travis.sh 3 | # Author : Jiayuan Mao 4 | # Email : maojiayuan@gmail.com 5 | # 6 | # This file is part of Jacinle. 7 | # Distributed under terms of the MIT license. 8 | 9 | python3 setup.py build_ext --inplace 10 | rm -rf build 11 | 12 | -------------------------------------------------------------------------------- /jactorch/transforms/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/03/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/nlp/graph/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 08/22/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jaclearn/rl/engines/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/16/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jaclearn/rl/envs/nintendo/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/17/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /jaclearn/rl/envs/simple/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/17/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /vendors/pytorch_reservoir/travis.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # travis.sh 4 | # Copyright (C) 2019 Jiayuan Mao 5 | # 6 | # Distributed under terms of the MIT license. 7 | # 8 | 9 | cd torch_sampling 10 | CFLAGS=-stdlib=libc++ python setup.py build_ext --inplace 11 | cd .. 12 | 13 | -------------------------------------------------------------------------------- /examples/web-starter/app/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 10/23/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jaclearn/rl/engines/mujoco/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/16/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jactorch/nn/neural_logic/modules/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 06/09/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /.vim-template:.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : %FFILE% 4 | # Author : %USER% 5 | # Email : %MAIL% 6 | # Date : %MONTH%/%DAY%/%YEAR% 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the %LICENSE% license. 10 | 11 | """ 12 | %HERE% 13 | """ 14 | -------------------------------------------------------------------------------- /docs/source/jacinle.storage.rst: -------------------------------------------------------------------------------- 1 | jacinle.storage package 2 | ======================= 3 | 4 | .. automodule:: jacinle.storage 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jacinle.storage.kv 16 | -------------------------------------------------------------------------------- /jaclearn/logic/decision_tree/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/16/2022 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jaclearn/logic/propositional/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/16/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /docs/source/jactorch.models.rst: -------------------------------------------------------------------------------- 1 | jactorch.models package 2 | ======================= 3 | 4 | .. automodule:: jactorch.models 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jactorch.models.vision 16 | -------------------------------------------------------------------------------- /jaclearn/datasets/image_classification/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | -------------------------------------------------------------------------------- /docs/source/jacinle.jit.rst: -------------------------------------------------------------------------------- 1 | jacinle.jit package 2 | =================== 3 | 4 | .. automodule:: jacinle.jit 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jacinle.jit.cext 16 | jacinle.jit.cython 17 | -------------------------------------------------------------------------------- /docs/source/jacinle.web.rst: -------------------------------------------------------------------------------- 1 | jacinle.web package 2 | =================== 3 | 4 | .. automodule:: jacinle.web 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jacinle.web.app 16 | jacinle.web.session 17 | -------------------------------------------------------------------------------- /docs/source/jaclearn.models.rst: -------------------------------------------------------------------------------- 1 | jaclearn.models package 2 | ======================= 3 | 4 | .. automodule:: jaclearn.models 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.models.naive_bayes 16 | -------------------------------------------------------------------------------- /jaclearn/logic/propositional/logic_induction/travis.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # File : travis.sh 3 | # Author : Jiayuan Mao 4 | # Email : maojiayuan@gmail.com 5 | # 6 | # This file is part of Jacinle. 7 | # Distributed under terms of the MIT license. 8 | 9 | python3 setup.py build_ext --inplace 10 | rm -rf build 11 | 12 | -------------------------------------------------------------------------------- /jactorch/cuda/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/24/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .copy import * 12 | -------------------------------------------------------------------------------- /jactorch/transforms/vision/functional/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 12/14/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | -------------------------------------------------------------------------------- /jactorch/nn/losses/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/01/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .losses import * 12 | -------------------------------------------------------------------------------- /jacinle/jit/cext/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/04/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .travis import * 12 | 13 | -------------------------------------------------------------------------------- /jaclearn/nlp/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 07/04/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | """ 12 | JacNLP package. 13 | """ 14 | -------------------------------------------------------------------------------- /jactorch/parallel/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 05/09/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .data_parallel import * 12 | -------------------------------------------------------------------------------- /docs/source/jaclearn.datasets.rst: -------------------------------------------------------------------------------- 1 | jaclearn.datasets package 2 | ========================= 3 | 4 | .. automodule:: jaclearn.datasets 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.datasets.image_classification 16 | -------------------------------------------------------------------------------- /docs/source/jaclearn.rl.engines.rst: -------------------------------------------------------------------------------- 1 | jaclearn.rl.engines package 2 | =========================== 3 | 4 | .. automodule:: jaclearn.rl.engines 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.rl.engines.mujoco 16 | -------------------------------------------------------------------------------- /jacinle/jit/cython/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/06/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .jit_compile import * 12 | 13 | -------------------------------------------------------------------------------- /jactorch/nn/gumbel_softmax/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/01/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .softmax import * 12 | -------------------------------------------------------------------------------- /jactorch/transforms/bbox/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/03/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .transforms import * 12 | -------------------------------------------------------------------------------- /jactorch/transforms/coor/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/03/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .transforms import * 12 | -------------------------------------------------------------------------------- /jactorch/transforms/image/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/03/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .transforms import * 12 | -------------------------------------------------------------------------------- /jactorch/transforms/vision/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 12/14/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .transforms import * 12 | -------------------------------------------------------------------------------- /docs/source/jaclearn.nlp.graph.rst: -------------------------------------------------------------------------------- 1 | jaclearn.nlp.graph package 2 | ========================== 3 | 4 | .. automodule:: jaclearn.nlp.graph 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.nlp.graph.dependency_visualizer 16 | -------------------------------------------------------------------------------- /jactorch/utils/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/25/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .meta import * 12 | from .grad import * 13 | -------------------------------------------------------------------------------- /docs/source/jaclearn.logic.rst: -------------------------------------------------------------------------------- 1 | jaclearn.logic package 2 | ====================== 3 | 4 | .. automodule:: jaclearn.logic 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.logic.decision_tree 16 | jaclearn.logic.propositional 17 | -------------------------------------------------------------------------------- /jacinle/random/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .rng import * 12 | from ._lazy_bind import * 13 | -------------------------------------------------------------------------------- /docs/source/jaclearn.nlp.rst: -------------------------------------------------------------------------------- 1 | jaclearn.nlp package 2 | ==================== 3 | 4 | .. automodule:: jaclearn.nlp 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.nlp.graph 16 | jaclearn.nlp.sng_parser 17 | jaclearn.nlp.tree 18 | -------------------------------------------------------------------------------- /jactorch/models/vision/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/31/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .vgg import * 12 | from .resnet import * 13 | -------------------------------------------------------------------------------- /bin/jac-export-init: -------------------------------------------------------------------------------- 1 | #!/bin/bash -E 2 | 3 | JACROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/../ && pwd )" 4 | export PYTHONPATH=$JACROOT:./:$PYTHONPATH 5 | export JAC_INIT_VERBOSE=0 6 | fname=`JAC_IMPORT_ALL=FALSE python3 $JACROOT/bin/_jac-init-gen.py` 7 | 8 | echo export PYTHONPATH=$JACROOT:./:\$PYTHONPATH 9 | cat $fname 10 | 11 | rm -f $fname 12 | 13 | -------------------------------------------------------------------------------- /bin/_jac-init.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # _jac-init.sh 4 | # Copyright (C) 2019 Jiayuan Mao 5 | # 6 | # Distributed under terms of the MIT license. 7 | # 8 | 9 | JACROOT=$1 10 | 11 | export PYTHONPATH=$JACROOT:./:$PYTHONPATH 12 | fname=`JAC_IMPORT_ALL=FALSE python3 $JACROOT/bin/_jac-init-gen.py` 13 | source $fname 14 | rm -f $fname 15 | 16 | -------------------------------------------------------------------------------- /examples/cython/csrc/loop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File : loop.c 3 | * Author : Jiayuan Mao 4 | * Email : maojiayuan@gmail.com 5 | * Date : 04/06/2019 6 | * 7 | * Distributed under terms of the MIT license. 8 | */ 9 | 10 | 11 | long c_loop(long n) { 12 | long s; 13 | for (long i = 0; i < n; ++i) { 14 | s += i; 15 | } 16 | return s 17 | } 18 | 19 | -------------------------------------------------------------------------------- /jactorch/train/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 05/09/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .env import * 12 | from .monitor import * 13 | from .utils import * 14 | -------------------------------------------------------------------------------- /jacinle/image/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | 12 | from .codecs import * 13 | from .imgio import * 14 | from .imgproc import * 15 | -------------------------------------------------------------------------------- /jactf/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/24/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jactf.utils.init import init_main 12 | 13 | init_main() 14 | 15 | del init_main 16 | -------------------------------------------------------------------------------- /docs/source/jaclearn.logic.propositional.rst: -------------------------------------------------------------------------------- 1 | jaclearn.logic.propositional package 2 | ==================================== 3 | 4 | .. automodule:: jaclearn.logic.propositional 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.logic.propositional.logic_induction 16 | -------------------------------------------------------------------------------- /jaclearn/mldash/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 09/07/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | 12 | from mldash.client import MLDashClient 13 | 14 | __all__ = ['MLDashClient'] 15 | -------------------------------------------------------------------------------- /jaclearn/nlp/tree/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 07/04/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .node import * 12 | from .traversal import * 13 | from .ptb import * 14 | 15 | -------------------------------------------------------------------------------- /jaclearn/vision/graph_cut.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : graph_cut.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/07/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from pygco import cut_general_graph, cut_grid_graph, cut_grid_graph_simple 12 | 13 | -------------------------------------------------------------------------------- /jactorch/nn/cnn/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/05/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .layers import * 12 | from .conv import * 13 | from .coord_conv import * 14 | 15 | -------------------------------------------------------------------------------- /jactorch/quickstart/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .models import * 12 | from .train import * 13 | from .inference import * 14 | -------------------------------------------------------------------------------- /docs/source/jactf.utils.rst: -------------------------------------------------------------------------------- 1 | jactf.utils package 2 | =================== 3 | 4 | .. automodule:: jactf.utils 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactf.utils.init module 13 | ----------------------- 14 | 15 | .. automodule:: jactf.utils.init 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /jacinle/comm/distrib/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/16/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | 12 | from .controller import * 13 | from .name_server import * 14 | from .pipe import * 15 | -------------------------------------------------------------------------------- /jacinle/nd/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/24/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .batch import * 12 | from .indexing import * 13 | from .meta import * 14 | from .shape import * 15 | -------------------------------------------------------------------------------- /jacinle/io/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .common import * 12 | from .fs import * 13 | from .network import * 14 | from .pretty import * 15 | 16 | -------------------------------------------------------------------------------- /docs/source/jactorch.cuda.rst: -------------------------------------------------------------------------------- 1 | jactorch.cuda package 2 | ===================== 3 | 4 | .. automodule:: jactorch.cuda 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.cuda.copy module 13 | ------------------------- 14 | 15 | .. automodule:: jactorch.cuda.copy 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /jaclearn/vision/graph_cut_inpaint.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : graph_cut_inpaint.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 05/12/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from pygco_inpaint import cut_simple, cut_simple_vh, cut_from_graph, cut_inpaint 12 | 13 | -------------------------------------------------------------------------------- /docs/source/jacinle.random.rst: -------------------------------------------------------------------------------- 1 | jacinle.random package 2 | ====================== 3 | 4 | .. automodule:: jacinle.random 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.random.rng module 13 | ------------------------- 14 | 15 | .. automodule:: jacinle.random.rng 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /jaclearn/nlp/graph/dependency_visualizer/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 08/22/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .render import DependencyVisualizer, visualize_list, visualize_simple_svg 12 | 13 | -------------------------------------------------------------------------------- /jaclearn/visualize/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .box import * 12 | from .imgrid import * 13 | from .imshow import * 14 | from .plot import * 15 | 16 | -------------------------------------------------------------------------------- /docs/source/jaclearn.math.rst: -------------------------------------------------------------------------------- 1 | jaclearn.math package 2 | ===================== 3 | 4 | .. automodule:: jaclearn.math 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.math.rotation module 13 | ----------------------------- 14 | 15 | .. automodule:: jaclearn.math.rotation 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /jacinle/web/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 10/23/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | """A simple wrapper around tornado for simple web applications. See `examples/web-starter` for a simple example.""" 12 | -------------------------------------------------------------------------------- /jactorch/graph/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/24/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .context import * 12 | from .nn_env import * 13 | from .parameter import * 14 | from .variable import * 15 | 16 | -------------------------------------------------------------------------------- /jactorch/nn/neural_logic/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/28/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .modules.neural_logic import * 12 | 13 | from .layer import * 14 | from .recurrent_layer import * 15 | -------------------------------------------------------------------------------- /jaclearn/models/naive_bayes/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/04/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from sklearn.naive_bayes import GaussianNB, MultinomialNB, BernoulliNB 12 | from .hybrid_nb import * 13 | 14 | -------------------------------------------------------------------------------- /jaclearn/vision/patch_match.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : patch_match.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/09/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from patch_match import inpaint, inpaint_regularity 12 | 13 | __all__ = ['inpaint', 'inpaint_regularity'] 14 | 15 | -------------------------------------------------------------------------------- /docs/source/jacinle.logging.rst: -------------------------------------------------------------------------------- 1 | jacinle.logging package 2 | ======================= 3 | 4 | .. automodule:: jacinle.logging 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.logging.logger module 13 | ----------------------------- 14 | 15 | .. automodule:: jacinle.logging.logger 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs/source/jacinle.jit.cext.rst: -------------------------------------------------------------------------------- 1 | jacinle.jit.cext package 2 | ======================== 3 | 4 | .. automodule:: jacinle.jit.cext 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.jit.cext.travis module 13 | ------------------------------ 14 | 15 | .. automodule:: jacinle.jit.cext.travis 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs/source/jactorch.transforms.rst: -------------------------------------------------------------------------------- 1 | jactorch.transforms package 2 | =========================== 3 | 4 | .. automodule:: jactorch.transforms 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jactorch.transforms.bbox 16 | jactorch.transforms.coor 17 | jactorch.transforms.image 18 | jactorch.transforms.vision 19 | -------------------------------------------------------------------------------- /docs/source/jacinle.web.app.rst: -------------------------------------------------------------------------------- 1 | jacinle.web.app package 2 | ======================= 3 | 4 | .. automodule:: jacinle.web.app 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.web.app.application module 13 | ---------------------------------- 14 | 15 | .. automodule:: jacinle.web.app.application 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /jactorch/optim/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/24/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .custom_optimizer_base import * 12 | from .accum_grad import * 13 | from .weight_decay import * 14 | from .optimizer_group import * 15 | 16 | -------------------------------------------------------------------------------- /examples/web-starter/app/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Home 6 | 7 | 8 |

Hello World

9 |

You have visited this site for {{ nr_visited }} times.

10 |
11 | {% for k, v in headers.items() %}- {{ k }}: {{ v }}
12 | {% end %}
13 |     
14 | 15 | 16 | -------------------------------------------------------------------------------- /jaclearn/vision/coco/mask_utils.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : mask_utils.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/06/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .pycocotools.mask import iou, merge, encode, decode, area, toBbox 12 | 13 | __all__ = ['iou', 'merge', 'encode', 'decode', 'area', 'toBbox'] 14 | -------------------------------------------------------------------------------- /jactorch/data/dataloader/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/09/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import torch 12 | 13 | if torch.__version__ < '0.3.1': 14 | from .dataloader_torch030 import * 15 | else: 16 | from .dataloader import * 17 | -------------------------------------------------------------------------------- /docs/source/jacinle.jit.cython.rst: -------------------------------------------------------------------------------- 1 | jacinle.jit.cython package 2 | ========================== 3 | 4 | .. automodule:: jacinle.jit.cython 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.jit.cython.jit\_compile module 13 | -------------------------------------- 14 | 15 | .. automodule:: jacinle.jit.cython.jit_compile 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /jaclearn/embedding/constant.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : constant.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/22/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | # universal 12 | EBD_PAD = EBD_ALL_ZEROS = '' 13 | EBD_UNKNOWN = '' 14 | 15 | # word embedding 16 | EBD_BOS = '' 17 | EBD_EOS = '' 18 | 19 | -------------------------------------------------------------------------------- /jactorch/nn/functional.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : functional.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/01/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .cnn.functional import * 12 | from .gumbel_softmax.functional import * 13 | from .losses.functional import * 14 | from .prroi_pool.functional import * 15 | 16 | -------------------------------------------------------------------------------- /examples/utils-ipdb/main.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : main.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 09/11/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.utils.debug import decorate_exception_hook 12 | 13 | 14 | @decorate_exception_hook 15 | def some_func(x): 16 | return 1 / x 17 | 18 | 19 | some_func(0) 20 | -------------------------------------------------------------------------------- /jaclearn/vision/coco/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 07/20/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.jit.cext import auto_travis 12 | auto_travis(__file__) 13 | 14 | from .pycocotools.coco import COCO 15 | from .pycocotools.cocoeval import COCOeval 16 | -------------------------------------------------------------------------------- /jactorch/vision/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/04/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .conv import * 12 | from .gradient import * 13 | from .morphology import * 14 | from .smooth import * 15 | from .peak import * 16 | 17 | from .geometry import * 18 | 19 | -------------------------------------------------------------------------------- /docs/source/jaclearn.rl.envs.nintendo.rst: -------------------------------------------------------------------------------- 1 | jaclearn.rl.envs.nintendo package 2 | ================================= 3 | 4 | .. automodule:: jaclearn.rl.envs.nintendo 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.rl.envs.nintendo.mario module 13 | -------------------------------------- 14 | 15 | .. automodule:: jaclearn.rl.envs.nintendo.mario 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs/source/jactorch.nn.prroi_pool.rst: -------------------------------------------------------------------------------- 1 | jactorch.nn.prroi\_pool package 2 | =============================== 3 | 4 | .. automodule:: jactorch.nn.prroi_pool 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.nn.prroi\_pool.functional module 13 | ----------------------------------------- 14 | 15 | .. automodule:: jactorch.nn.prroi_pool.functional 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs/source/jaclearn.rl.envs.simple.rst: -------------------------------------------------------------------------------- 1 | jaclearn.rl.envs.simple package 2 | =============================== 3 | 4 | .. automodule:: jaclearn.rl.envs.simple 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.rl.envs.simple.move\_right module 13 | ------------------------------------------ 14 | 15 | .. automodule:: jaclearn.rl.envs.simple.move_right 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs2/source/_static/custom.css: -------------------------------------------------------------------------------- 1 | /* 2 | * custom.css 3 | * Copyright (C) 2022 Jiayuan Mao 4 | * 5 | * Distributed under terms of the MIT license. 6 | */ 7 | 8 | .bd-sidebar a.reference { 9 | overflow-wrap: break-word; 10 | } 11 | 12 | h1 { 13 | overflow-wrap: break-word; 14 | } 15 | .bd-main .bd-content .bd-article-container { 16 | max-width: 100%; 17 | } 18 | .bd-page-width { 19 | max-width: 100%; 20 | } 21 | .readme-image { 22 | width: 100%; 23 | max-width: 1440px; 24 | } -------------------------------------------------------------------------------- /docs/source/jaclearn.logic.decision_tree.rst: -------------------------------------------------------------------------------- 1 | jaclearn.logic.decision\_tree package 2 | ===================================== 3 | 4 | .. automodule:: jaclearn.logic.decision_tree 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.logic.decision\_tree.rule module 13 | ----------------------------------------- 14 | 15 | .. automodule:: jaclearn.logic.decision_tree.rule 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs/source/jaclearn.rl.engines.mujoco.rst: -------------------------------------------------------------------------------- 1 | jaclearn.rl.engines.mujoco package 2 | ================================== 3 | 4 | .. automodule:: jaclearn.rl.engines.mujoco 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.rl.engines.mujoco.gym\_recorder module 13 | ----------------------------------------------- 14 | 15 | .. automodule:: jaclearn.rl.engines.mujoco.gym_recorder 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /tests/test-utils-debug.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : test-utils-debug.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 09/11/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.utils.debug import decorate_exception_hook 12 | 13 | 14 | @decorate_exception_hook 15 | def some_func(x): 16 | return 1 / x 17 | 18 | 19 | if __name__ == '__main__': 20 | some_func(0) 21 | 22 | -------------------------------------------------------------------------------- /docs/source/jaclearn.models.naive_bayes.rst: -------------------------------------------------------------------------------- 1 | jaclearn.models.naive\_bayes package 2 | ==================================== 3 | 4 | .. automodule:: jaclearn.models.naive_bayes 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.models.naive\_bayes.hybrid\_nb module 13 | ---------------------------------------------- 14 | 15 | .. automodule:: jaclearn.models.naive_bayes.hybrid_nb 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs/source/jacinle.rst: -------------------------------------------------------------------------------- 1 | jacinle package 2 | =============== 3 | 4 | .. automodule:: jacinle 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jacinle.cli 16 | jacinle.comm 17 | jacinle.concurrency 18 | jacinle.config 19 | jacinle.image 20 | jacinle.io 21 | jacinle.jit 22 | jacinle.logging 23 | jacinle.nd 24 | jacinle.random 25 | jacinle.storage 26 | jacinle.utils 27 | jacinle.web 28 | -------------------------------------------------------------------------------- /jaclearn/data/stat.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : stat.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/16/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | __all__ = ['stat_histogram'] 12 | 13 | 14 | def stat_histogram(name, value, markers, value_format='{}'): 15 | histo = dict() 16 | for m in markers: 17 | histo[('{}/>=' + value_format).format(name, m)] = int(value >= m) 18 | return histo 19 | 20 | -------------------------------------------------------------------------------- /docs/source/jaclearn.rst: -------------------------------------------------------------------------------- 1 | jaclearn package 2 | ================ 3 | 4 | .. automodule:: jaclearn 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.data 16 | jaclearn.dataflow 17 | jaclearn.datasets 18 | jaclearn.embedding 19 | jaclearn.imageaug 20 | jaclearn.logic 21 | jaclearn.math 22 | jaclearn.mldash 23 | jaclearn.models 24 | jaclearn.nlp 25 | jaclearn.rl 26 | jaclearn.vision 27 | jaclearn.visualize 28 | -------------------------------------------------------------------------------- /docs/source/jaclearn.data.rst: -------------------------------------------------------------------------------- 1 | jaclearn.data package 2 | ===================== 3 | 4 | .. automodule:: jaclearn.data 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.data.sampler module 13 | ---------------------------- 14 | 15 | .. automodule:: jaclearn.data.sampler 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.data.stat module 21 | ------------------------- 22 | 23 | .. automodule:: jaclearn.data.stat 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /docs2/source/api.rst: -------------------------------------------------------------------------------- 1 | .. 2 | DO NOT DELETE THIS FILE! It contains the all-important `.. autosummary::` directive with `:recursive:` option, without 3 | which API documentation wouldn't get extracted from docstrings by the `sphinx.ext.autosummary` engine. It is hidden 4 | (not declared in any toctree) to remove an unnecessary intermediate page; index.rst instead points directly to the 5 | package page. DO NOT REMOVE THIS FILE! 6 | 7 | .. autosummary:: 8 | :toctree: reference 9 | :template: base.rst 10 | :recursive: 11 | 12 | jacinle 13 | jaclearn 14 | jactf 15 | jactorch 16 | 17 | -------------------------------------------------------------------------------- /examples/comm-service-nameserver/client.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : client.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/11/2025 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.comm.service import SocketClient 12 | 13 | 14 | def main(): 15 | client = SocketClient('my-service/add', use_name_server=True, use_simple=True, verbose=False) 16 | client.initialize() 17 | 18 | print(client.add(1, 2)) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | 24 | -------------------------------------------------------------------------------- /docs/source/jaclearn.rl.algo.rst: -------------------------------------------------------------------------------- 1 | jaclearn.rl.algo package 2 | ======================== 3 | 4 | .. automodule:: jaclearn.rl.algo 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.rl.algo.advantage module 13 | --------------------------------- 14 | 15 | .. automodule:: jaclearn.rl.algo.advantage 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.rl.algo.math module 21 | ---------------------------- 22 | 23 | .. automodule:: jaclearn.rl.algo.math 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /jactorch/data/collate/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/09/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .collate_v2 import VarLengthCollateV2 12 | from .collate_v3 import VarLengthCollateV3 13 | from .utils import user_scattered_collate, VarLengthCollateMode 14 | 15 | import torch 16 | 17 | if torch.__version__ <= '0.3.1': 18 | from .collate_v1 import VarLengthCollateV1 19 | VarLengthCollate = VarLengthCollateV1 20 | 21 | -------------------------------------------------------------------------------- /jactorch/nn/prroi_pool/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 05/25/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.utils.vendor import has_vendor, requires_vendors 12 | 13 | __all__ = ['PrRoIPool2D'] 14 | 15 | 16 | if has_vendor('prroi_pool'): 17 | from prroi_pool import PrRoIPool2D 18 | else: 19 | from jacinle.utils.meta import make_dummy_func 20 | PrRoIPool2D = requires_vendors('prroi_pool')(make_dummy_func()) 21 | 22 | -------------------------------------------------------------------------------- /docs/source/jactorch.transforms.vision.rst: -------------------------------------------------------------------------------- 1 | jactorch.transforms.vision package 2 | ================================== 3 | 4 | .. automodule:: jactorch.transforms.vision 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jactorch.transforms.vision.functional 16 | 17 | Submodules 18 | ---------- 19 | 20 | jactorch.transforms.vision.transforms module 21 | -------------------------------------------- 22 | 23 | .. automodule:: jactorch.transforms.vision.transforms 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /examples/learn-logic/propositional-induction.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : propositional-induction.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/16/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import numpy as np 12 | from jaclearn.logic.propositional.logic_induction import search 13 | 14 | inputs = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype='uint8') 15 | outputs = np.array([[0], [1], [1], [0]], dtype='uint8') 16 | input_names = ['x', 'y'] 17 | print(search(inputs, outputs, input_names)) 18 | 19 | -------------------------------------------------------------------------------- /docs/source/jactorch.nn.losses.rst: -------------------------------------------------------------------------------- 1 | jactorch.nn.losses package 2 | ========================== 3 | 4 | .. automodule:: jactorch.nn.losses 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.nn.losses.functional module 13 | ------------------------------------ 14 | 15 | .. automodule:: jactorch.nn.losses.functional 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.nn.losses.losses module 21 | -------------------------------- 22 | 23 | .. automodule:: jactorch.nn.losses.losses 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /jacinle/utils/uid.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : uid.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 12/21/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import time 12 | import uuid 13 | 14 | __all__ = ['gen_time_string', 'gen_uuid4'] 15 | 16 | 17 | def gen_time_string() -> str: 18 | """Generate a time string with format: %Y%m%d-%H%M%S-%f.""" 19 | return time.strftime('%Y-%m-%d-%H-%M-%S') 20 | 21 | 22 | def gen_uuid4() -> str: 23 | """Generate a UUID4 string.""" 24 | return uuid.uuid4().hex 25 | 26 | -------------------------------------------------------------------------------- /jactorch/nn/prroi_pool/functional.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : functional.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 05/25/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.utils.vendor import has_vendor, requires_vendors 12 | 13 | __all__ = ['prroi_pool2d'] 14 | 15 | 16 | if has_vendor('prroi_pool'): 17 | from prroi_pool.functional import prroi_pool2d 18 | else: 19 | from jacinle.utils.meta import make_dummy_func 20 | prroi_pool2d = requires_vendors('prroi_pool')(make_dummy_func()) 21 | 22 | -------------------------------------------------------------------------------- /docs/source/jaclearn.rl.envs.maze.rst: -------------------------------------------------------------------------------- 1 | jaclearn.rl.envs.maze package 2 | ============================= 3 | 4 | .. automodule:: jaclearn.rl.envs.maze 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.rl.envs.maze.maze module 13 | --------------------------------- 14 | 15 | .. automodule:: jaclearn.rl.envs.maze.maze 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.rl.envs.maze.taxi module 21 | --------------------------------- 22 | 23 | .. automodule:: jaclearn.rl.envs.maze.taxi 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /jactorch/utils/grad.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : grad.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 05/08/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import functools 12 | 13 | import torch 14 | 15 | __all__ = ['no_grad_func'] 16 | 17 | 18 | def no_grad_func(func): 19 | """A decorator to disable gradient calculation for a function.""" 20 | @functools.wraps(func) 21 | def new_func(*args, **kwargs): 22 | with torch.no_grad(): 23 | return func(*args, **kwargs) 24 | return new_func 25 | -------------------------------------------------------------------------------- /docs/source/jacinle.web.session.rst: -------------------------------------------------------------------------------- 1 | jacinle.web.session package 2 | =========================== 3 | 4 | .. automodule:: jacinle.web.session 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.web.session.memcached module 13 | ------------------------------------ 14 | 15 | .. automodule:: jacinle.web.session.memcached 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jacinle.web.session.session module 21 | ---------------------------------- 22 | 23 | .. automodule:: jacinle.web.session.session 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /docs/source/jactorch.models.vision.rst: -------------------------------------------------------------------------------- 1 | jactorch.models.vision package 2 | ============================== 3 | 4 | .. automodule:: jactorch.models.vision 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.models.vision.resnet module 13 | ------------------------------------ 14 | 15 | .. automodule:: jactorch.models.vision.resnet 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.models.vision.vgg module 21 | --------------------------------- 22 | 23 | .. automodule:: jactorch.models.vision.vgg 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /docs/source/jaclearn.rl.simulator.rst: -------------------------------------------------------------------------------- 1 | jaclearn.rl.simulator package 2 | ============================= 3 | 4 | .. automodule:: jaclearn.rl.simulator 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.rl.simulator.controller module 13 | --------------------------------------- 14 | 15 | .. automodule:: jaclearn.rl.simulator.controller 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.rl.simulator.pack module 21 | --------------------------------- 22 | 23 | .. automodule:: jaclearn.rl.simulator.pack 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /examples/comm-distrib/in.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : in.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/03/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import time 12 | 13 | from jacinle.comm.distrib import DistribInputPipe, control 14 | from jacinle.utils.printing import stprint 15 | 16 | 17 | def main(): 18 | q = DistribInputPipe('jacinle.test') 19 | with control(pipes=[q]): 20 | for i in range(10): 21 | stprint(q.get()) 22 | time.sleep(1) 23 | 24 | 25 | if __name__ == '__main__': 26 | main() 27 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = Jacinle 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /jactorch/vision/_utils.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : _utils.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/07/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import functools 12 | import torch 13 | import torch.cuda as cuda 14 | 15 | 16 | def auto_device(func): 17 | @functools.wraps(func) 18 | def wrapped(tensor, *args, **kwargs): 19 | if tensor.device.type == 'cuda': 20 | with cuda.device(tensor.device): 21 | return func(tensor, *args, **kwargs) 22 | return func(tensor, *args, **kwargs) 23 | return wrapped 24 | 25 | -------------------------------------------------------------------------------- /docs/source/jactorch.transforms.bbox.rst: -------------------------------------------------------------------------------- 1 | jactorch.transforms.bbox package 2 | ================================ 3 | 4 | .. automodule:: jactorch.transforms.bbox 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.transforms.bbox.functional module 13 | ------------------------------------------ 14 | 15 | .. automodule:: jactorch.transforms.bbox.functional 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.transforms.bbox.transforms module 21 | ------------------------------------------ 22 | 23 | .. automodule:: jactorch.transforms.bbox.transforms 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /docs/source/jactorch.transforms.coor.rst: -------------------------------------------------------------------------------- 1 | jactorch.transforms.coor package 2 | ================================ 3 | 4 | .. automodule:: jactorch.transforms.coor 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.transforms.coor.functional module 13 | ------------------------------------------ 14 | 15 | .. automodule:: jactorch.transforms.coor.functional 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.transforms.coor.transforms module 21 | ------------------------------------------ 22 | 23 | .. automodule:: jactorch.transforms.coor.transforms 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /examples/utils-defaults/default_args.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : default_args.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 12/18/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.utils.defaults import ARGDEF, default_args 12 | 13 | 14 | @default_args 15 | def inner(a, b, *args, c='default_c', d='default_d'): 16 | print(a, b, c, d, args) 17 | 18 | 19 | def outer(b, *args, c, d=ARGDEF): 20 | inner('called by outer', b, *args, c=c, d=d) 21 | 22 | 23 | if __name__ == '__main__': 24 | from IPython import embed; embed() 25 | outer('value_b', c='value_c') 26 | 27 | -------------------------------------------------------------------------------- /examples/web-starter/app/index.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : index.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 10/23/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | from jacinle.web.app import route, JacRequestHandler 11 | 12 | @route(r'/') 13 | class IndexHandler(JacRequestHandler): 14 | def get(self): 15 | nr_visited = 0 16 | if self.session is not None: 17 | nr_visited = self.session.get('nr_visited', 0) 18 | self.session['nr_visited'] = nr_visited + 1 19 | self.render('index.html', nr_visited=nr_visited, headers=self.request.headers) 20 | 21 | -------------------------------------------------------------------------------- /docs/source/jactorch.transforms.image.rst: -------------------------------------------------------------------------------- 1 | jactorch.transforms.image package 2 | ================================= 3 | 4 | .. automodule:: jactorch.transforms.image 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.transforms.image.functional module 13 | ------------------------------------------- 14 | 15 | .. automodule:: jactorch.transforms.image.functional 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.transforms.image.transforms module 21 | ------------------------------------------- 22 | 23 | .. automodule:: jactorch.transforms.image.transforms 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /docs/source/jactorch.nn.gumbel_softmax.rst: -------------------------------------------------------------------------------- 1 | jactorch.nn.gumbel\_softmax package 2 | =================================== 3 | 4 | .. automodule:: jactorch.nn.gumbel_softmax 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.nn.gumbel\_softmax.functional module 13 | --------------------------------------------- 14 | 15 | .. automodule:: jactorch.nn.gumbel_softmax.functional 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.nn.gumbel\_softmax.softmax module 21 | ------------------------------------------ 22 | 23 | .. automodule:: jactorch.nn.gumbel_softmax.softmax 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /jacinle/config/g.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : g.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 05/12/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | """A simple global dict-like objects. 12 | 13 | Example: 14 | 15 | .. code-block:: python 16 | 17 | from jacinle.config.g import g 18 | 19 | g.configfile = 'config.yaml' 20 | g.project_name = 'Jacinle' 21 | g.project_version = 1 22 | 23 | .. rubric:: Variables 24 | 25 | .. autosummary:: 26 | :toctree: 27 | 28 | g 29 | 30 | """ 31 | 32 | from jacinle.utils.container import g 33 | 34 | __all__ = ['g'] 35 | 36 | -------------------------------------------------------------------------------- /docs/source/jactorch.data.rst: -------------------------------------------------------------------------------- 1 | jactorch.data package 2 | ===================== 3 | 4 | .. automodule:: jactorch.data 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jactorch.data.collate 16 | jactorch.data.dataloader 17 | 18 | Submodules 19 | ---------- 20 | 21 | jactorch.data.dataset module 22 | ---------------------------- 23 | 24 | .. automodule:: jactorch.data.dataset 25 | :members: 26 | :undoc-members: 27 | :show-inheritance: 28 | 29 | jactorch.data.layout module 30 | --------------------------- 31 | 32 | .. automodule:: jactorch.data.layout 33 | :members: 34 | :undoc-members: 35 | :show-inheritance: 36 | -------------------------------------------------------------------------------- /docs/source/jactorch.data.dataloader.rst: -------------------------------------------------------------------------------- 1 | jactorch.data.dataloader package 2 | ================================ 3 | 4 | .. automodule:: jactorch.data.dataloader 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.data.dataloader.dataloader module 13 | ------------------------------------------ 14 | 15 | .. automodule:: jactorch.data.dataloader.dataloader 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.data.dataloader.dataloader\_torch030 module 21 | ---------------------------------------------------- 22 | 23 | .. automodule:: jactorch.data.dataloader.dataloader_torch030 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /jacinle.yml: -------------------------------------------------------------------------------- 1 | vendors: 2 | ReservoirSample-PyTorch: 3 | root: vendors/pytorch_reservoir 4 | AdvancedIndexing-PyTorch: 5 | root: vendors/AdvancedIndexing-PyTorch 6 | SynchronizedBatchNorm-PyTorch: 7 | root: vendors/Synchronized-BatchNorm-PyTorch 8 | PreciseRoIPooling-PyTorch: 9 | root: vendors/PreciseRoIPooling/pytorch 10 | SceneGraphParser: 11 | root: vendors/SceneGraphParser 12 | JacMLDash: 13 | root: vendors/JacMLDash 14 | PyGCO: 15 | root: vendors/PyGCO 16 | PyPatchMatch: 17 | root: vendors/PyPatchMatch 18 | KMeans-PyTorch: 19 | root: vendors/pytorch_kmeans/kmeans_pytorch 20 | Einshape: 21 | root: vendors/pytorch_einshape/einshape 22 | 23 | -------------------------------------------------------------------------------- /jactf/utils/init.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : init.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/01/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import os 12 | 13 | 14 | def tune_tensorflow(): 15 | os.environ['TF_ENABLE_WINOGRAD_NONFUSED'] = '1' # issue#9339 16 | os.environ['TF_AUTOTUNE_THRESHOLD'] = '3' # use more warm-up 17 | 18 | 19 | def register_rng(): 20 | import tensorflow 21 | from jacinle.random.rng import global_rng_registry 22 | global_rng_registry.register('tf', lambda: tensorflow.set_random_seed) 23 | 24 | 25 | def init_main(): 26 | tune_tensorflow() 27 | register_rng() 28 | -------------------------------------------------------------------------------- /examples/kv-lmdb/lmdb-single.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : lmdb-single.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/17/2023 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.storage.kv.lmdb import LMDBKVStore 12 | 13 | 14 | def main(): 15 | kv = LMDBKVStore('/tmp/test_1.lmdb', readonly=False) 16 | 17 | with kv.transaction(): 18 | kv['a'] = 1 19 | kv['b'] = 2 20 | 21 | assert 'a' in kv and kv['a'] == 1 22 | assert 'b' in kv and kv['b'] == 2 23 | assert 'c' not in kv 24 | 25 | for k in kv.keys(): 26 | print(k, kv[k]) 27 | 28 | 29 | if __name__ == '__main__': 30 | main() 31 | 32 | -------------------------------------------------------------------------------- /examples/python-starter/script.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : script.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 10/25/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import os.path as osp 12 | 13 | import jacinle.io as io 14 | 15 | from jacinle.cli.argument import JacArgumentParser 16 | from jacinle.logging import get_logger 17 | from jacinle.utils.tqdm import tqdm, tqdm_gofor, get_current_tqdm 18 | 19 | logger = get_logger(__file__) 20 | 21 | parser = JacArgumentParser() 22 | args = parser.parse_args() 23 | 24 | 25 | def main(): 26 | from IPython import embed; embed() 27 | 28 | 29 | if __name__ == '__main__': 30 | main() 31 | 32 | -------------------------------------------------------------------------------- /docs/source/jacinle.config.rst: -------------------------------------------------------------------------------- 1 | jacinle.config package 2 | ====================== 3 | 4 | .. automodule:: jacinle.config 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.config.environ module 13 | ----------------------------- 14 | 15 | .. automodule:: jacinle.config.environ 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jacinle.config.environ\_v2 module 21 | --------------------------------- 22 | 23 | .. automodule:: jacinle.config.environ_v2 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jacinle.config.g module 29 | ----------------------- 30 | 31 | .. automodule:: jacinle.config.g 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | -------------------------------------------------------------------------------- /docs/source/jaclearn.vision.coco.rst: -------------------------------------------------------------------------------- 1 | jaclearn.vision.coco package 2 | ============================ 3 | 4 | .. automodule:: jaclearn.vision.coco 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.vision.coco.pycocotools 16 | 17 | Submodules 18 | ---------- 19 | 20 | jaclearn.vision.coco.mask\_utils module 21 | --------------------------------------- 22 | 23 | .. automodule:: jaclearn.vision.coco.mask_utils 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jaclearn.vision.coco.setup module 29 | --------------------------------- 30 | 31 | .. automodule:: jaclearn.vision.coco.setup 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | -------------------------------------------------------------------------------- /examples/comm-distrib/out.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : out.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/03/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import time 12 | 13 | import numpy as np 14 | 15 | from jacinle.comm.distrib import DistribOutputPipe, control 16 | 17 | 18 | def main(): 19 | q = DistribOutputPipe('jacinle.test') 20 | with control(pipes=[q]): 21 | while True: 22 | data = {'msg': 'hello', 'current': time.time(), 'data': np.zeros(shape=(128, 224, 224, 3), dtype='float32')} 23 | print('RFlow sending', data['current']) 24 | q.put(data) 25 | 26 | 27 | if __name__ == '__main__': 28 | main() 29 | -------------------------------------------------------------------------------- /examples/configs/test-configs-envrion2.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : test-configs-envrion2.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 10/17/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.config.environ_v2 import configs, def_configs, set_configs 12 | 13 | with set_configs(): 14 | configs.model.hidden_dim = 10 15 | configs.train.learning_rate = 10 16 | configs.train.beta = 10 17 | 18 | with def_configs(): 19 | configs.model.hidden_dim = 1 20 | configs.train.learning_rate = 10 21 | configs.train.weight_decay = 0 22 | 23 | 24 | configs.print() 25 | print('Undefined configs:') 26 | print(*configs.find_undefined_values(), sep='\n') 27 | -------------------------------------------------------------------------------- /docs/source/jaclearn.rl.envs.rst: -------------------------------------------------------------------------------- 1 | jaclearn.rl.envs package 2 | ======================== 3 | 4 | .. automodule:: jaclearn.rl.envs 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.rl.envs.maze 16 | jaclearn.rl.envs.nintendo 17 | jaclearn.rl.envs.simple 18 | 19 | Submodules 20 | ---------- 21 | 22 | jaclearn.rl.envs.gym module 23 | --------------------------- 24 | 25 | .. automodule:: jaclearn.rl.envs.gym 26 | :members: 27 | :undoc-members: 28 | :show-inheritance: 29 | 30 | jaclearn.rl.envs.gym\_adapter module 31 | ------------------------------------ 32 | 33 | .. automodule:: jaclearn.rl.envs.gym_adapter 34 | :members: 35 | :undoc-members: 36 | :show-inheritance: 37 | -------------------------------------------------------------------------------- /docs/source/jactorch.nn.neural_logic.modules.rst: -------------------------------------------------------------------------------- 1 | jactorch.nn.neural\_logic.modules package 2 | ========================================= 3 | 4 | .. automodule:: jactorch.nn.neural_logic.modules 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.nn.neural\_logic.modules.dimension module 13 | -------------------------------------------------- 14 | 15 | .. automodule:: jactorch.nn.neural_logic.modules.dimension 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.nn.neural\_logic.modules.neural\_logic module 21 | ------------------------------------------------------ 22 | 23 | .. automodule:: jactorch.nn.neural_logic.modules.neural_logic 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /examples/dependency-visualizer/example.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : example.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 08/22/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import os.path as osp 12 | from jaclearn.nlp.graph.dependency_visualizer import visualize_simple_svg 13 | 14 | 15 | def main(): 16 | svg = visualize_simple_svg('a b c', [(0, 1, 'tag1'), (1, 2)]) 17 | 18 | from jaclearn.nlp.graph.dependency_visualizer.templates import TPL_PAGE 19 | with open('./index.html', 'w') as f: 20 | f.write(TPL_PAGE.format(lang='en', dir='ltr', content=svg)) 21 | print(osp.realpath('./index.html')) 22 | 23 | 24 | if __name__ == '__main__': 25 | main() 26 | -------------------------------------------------------------------------------- /jactorch/nn/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/25/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .container import * 12 | from .embedding import * 13 | from .linear import * 14 | from .normalization import * 15 | from .probability import * 16 | from .quickaccess import * 17 | from .residual import * 18 | from .rnn_layers import * 19 | from .rnn_utils import * 20 | from .simple import * 21 | from .word_embedding import * 22 | 23 | from .cnn import * 24 | from .gumbel_softmax import * 25 | from .neural_logic import * 26 | from .prroi_pool import * 27 | from .sync_batchnorm import * 28 | from .losses import * 29 | 30 | -------------------------------------------------------------------------------- /examples/comm-cs/client.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : client.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/19/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import time 12 | import sys 13 | import uuid 14 | 15 | from jacinle.comm.cs import ClientPipe 16 | 17 | 18 | def main(): 19 | client = ClientPipe('client' + uuid.uuid4().hex[:8], conn_info=sys.argv[1:3]) 20 | print('Identity: {}.'.format(client.identity)) 21 | with client.activate(): 22 | in_ = dict(a=1, b=2) 23 | out = client.query('calc', in_) 24 | print('Success: input={}, output={}'.format(in_, out)) 25 | time.sleep(1) 26 | 27 | 28 | if __name__ == '__main__': 29 | main() 30 | -------------------------------------------------------------------------------- /jactorch/nn/container.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : container.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/09/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import torch 12 | import torch.nn as nn 13 | 14 | __all__ = ['SequentialN'] 15 | 16 | 17 | class SequentialN(nn.Sequential): 18 | def forward(self, *inputs, return_all=False): 19 | all_values = [inputs] 20 | for module in self._modules.values(): 21 | if torch.is_tensor(inputs): 22 | inputs = [inputs] 23 | inputs = module(*inputs) 24 | all_values.append(inputs) 25 | if return_all: 26 | return inputs, all_values 27 | return inputs 28 | -------------------------------------------------------------------------------- /scripts/service-name-server.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : service-name-server.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import argparse 12 | 13 | from jacinle.comm.service_name_server import SimpleNameServer 14 | from jacinle.logging import get_logger 15 | 16 | logger = get_logger(__file__) 17 | 18 | parser = argparse.ArgumentParser() 19 | parser.add_argument('-p', '--port', dest='port', default=SimpleNameServer.DEFAULT_PORT) 20 | args = parser.parse_args() 21 | 22 | 23 | if __name__ == '__main__': 24 | logger.critical('Starting name server at {}.'.format(args.port)) 25 | SimpleNameServer().serve_socket(tcp_port=args.port) 26 | 27 | -------------------------------------------------------------------------------- /examples/comm-cs/server.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : server.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/19/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import time 12 | from jacinle.comm.cs import ServerPipe 13 | 14 | 15 | def answer(pipe, identifier, inp): 16 | out = inp['a'] + inp['b'] 17 | pipe.send(identifier, dict(out=out)) 18 | 19 | 20 | def main(): 21 | server = ServerPipe('server') 22 | server.dispatcher.register('calc', answer) 23 | with server.activate(): 24 | print('Client command:') 25 | print('jac-run client.py', *server.conn_info) 26 | while True: 27 | time.sleep(1) 28 | 29 | 30 | if __name__ == '__main__': 31 | main() 32 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["hatchling"] 3 | build-backend = "hatchling.build" 4 | 5 | [project] 6 | name = "jacinle" 7 | version = "1.0.4" 8 | authors = [ 9 | { name="Jiayuan Mao", email="maojiayuan@gmail.com" }, 10 | ] 11 | description = "Jacinle" 12 | readme = "README.md" 13 | requires-python = ">=3.8" 14 | classifiers = [ 15 | "Programming Language :: Python :: 3", 16 | "Operating System :: OS Independent", 17 | "License :: OSI Approved :: MIT License", 18 | ] 19 | keywords = [''] 20 | dependencies = ['Cython', 'pkgconfig', 'tabulate', 'ipdb', 'pyyaml', 'tqdm', 'pyzmq', 'numpy', 'scipy', 'scikit-learn', 'matplotlib'] 21 | license = "MIT" 22 | license-files = ["LICEN[CS]E*"] 23 | 24 | [project.urls] 25 | Homepage = "https://github.com/vacancy/Jacinle" 26 | Issues = "https://github.com/vacancy/Jacinle/issues" 27 | 28 | -------------------------------------------------------------------------------- /docs/source/jactorch.quickstart.rst: -------------------------------------------------------------------------------- 1 | jactorch.quickstart package 2 | =========================== 3 | 4 | .. automodule:: jactorch.quickstart 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.quickstart.inference module 13 | ------------------------------------ 14 | 15 | .. automodule:: jactorch.quickstart.inference 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.quickstart.models module 21 | --------------------------------- 22 | 23 | .. automodule:: jactorch.quickstart.models 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.quickstart.train module 29 | -------------------------------- 30 | 31 | .. automodule:: jactorch.quickstart.train 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. Jacinle documentation master file, created by 2 | sphinx-quickstart on Sat Apr 21 16:51:41 2018. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | ============ 7 | Jacinle 8 | ============ 9 | 10 | Jacinle is a personal python toolbox. It contains a range of utility functions for python development, including project configuration, file IO, image processing, inter-process communication, etc. 11 | 12 | Note 13 | =============== 14 | Comming soon. 15 | 16 | Package Reference 17 | ================= 18 | 19 | .. toctree:: 20 | :maxdepth: 1 21 | 22 | jacinle 23 | jaclearn 24 | jactf 25 | jactorch 26 | 27 | 28 | Indices and tables 29 | ================== 30 | 31 | * :ref:`genindex` 32 | * :ref:`modindex` 33 | * :ref:`search` 34 | 35 | -------------------------------------------------------------------------------- /docs/source/jactorch.nn.neural_logic.rst: -------------------------------------------------------------------------------- 1 | jactorch.nn.neural\_logic package 2 | ================================= 3 | 4 | .. automodule:: jactorch.nn.neural_logic 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jactorch.nn.neural_logic.modules 16 | 17 | Submodules 18 | ---------- 19 | 20 | jactorch.nn.neural\_logic.layer module 21 | -------------------------------------- 22 | 23 | .. automodule:: jactorch.nn.neural_logic.layer 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.nn.neural\_logic.recurrent\_layer module 29 | ------------------------------------------------- 30 | 31 | .. automodule:: jactorch.nn.neural_logic.recurrent_layer 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | -------------------------------------------------------------------------------- /jactorch/functional/clustering.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : cluster.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/25/2022 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | """Clustering functions.""" 12 | 13 | import torch 14 | from jacinle.utils.vendor import requires_vendors 15 | 16 | __all__ = ['kmeans'] 17 | 18 | 19 | @requires_vendors('kmeans_pytorch') 20 | def kmeans(data: torch.Tensor, nr_clusters: int, nr_iterations: int = 20, distance: str = 'euclidean', device=None, verbose=False): 21 | if device is None: 22 | device = data.device 23 | 24 | from kmeans_pytorch import kmeans 25 | return kmeans(X=data, num_clusters=nr_clusters, distance=distance, device=device, tqdm_flag=verbose, iter_limit=nr_iterations) 26 | 27 | -------------------------------------------------------------------------------- /docs/source/jacinle.comm.distrib.rst: -------------------------------------------------------------------------------- 1 | jacinle.comm.distrib package 2 | ============================ 3 | 4 | .. automodule:: jacinle.comm.distrib 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.comm.distrib.controller module 13 | -------------------------------------- 14 | 15 | .. automodule:: jacinle.comm.distrib.controller 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jacinle.comm.distrib.name\_server module 21 | ---------------------------------------- 22 | 23 | .. automodule:: jacinle.comm.distrib.name_server 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jacinle.comm.distrib.pipe module 29 | -------------------------------- 30 | 31 | .. automodule:: jacinle.comm.distrib.pipe 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | -------------------------------------------------------------------------------- /docs2/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: clean help Makefile 16 | 17 | clean: 18 | rm -rf $(SOURCEDIR)/reference 19 | rm -rf $(BUILDDIR)/html/* 20 | 21 | # Catch-all target: route all unknown targets to Sphinx using the new 22 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 23 | %: Makefile 24 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 25 | rsync -avP --delete $(BUILDDIR)/html droplet.jiayuanm.com:~/jacinle_docs/ 26 | -------------------------------------------------------------------------------- /jactorch/functional/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/24/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | """Functional APIs for JacTorch. By default, you should just access functions with ``jactorch.*``. Or, if you want to be 12 | explicit about the functions, you can import the specific function from ``jactorch.functional.*``.""" 13 | 14 | from .arith import * 15 | from .clustering import * 16 | from .grad import * 17 | from .indexing import * 18 | from .kernel import * 19 | from .linalg import * 20 | from .loglinear import * 21 | from .masking import * 22 | from .probability import * 23 | from .quantization import * 24 | from .range import * 25 | from .sampling import * 26 | from .shape import * 27 | 28 | -------------------------------------------------------------------------------- /jaclearn/nlp/sng_parser/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 07/04/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.utils.vendor import has_vendor, requires_vendors 12 | 13 | __all__ = ['tprint', 'Parser', 'get_default_parser', 'parse'] 14 | 15 | 16 | if has_vendor('sng_parser'): 17 | from sng_parser import tprint, Parser, get_default_parser, parse 18 | else: 19 | from jacinle.utils.meta import make_dummy_func 20 | tprint = requires_vendors('sng_parser')(make_dummy_func()) 21 | Parser = requires_vendors('sng_parser')(make_dummy_func()) 22 | get_default_parser = requires_vendors('sng_parser')(make_dummy_func()) 23 | parse = requires_vendors('sng_parser')(make_dummy_func()) 24 | 25 | -------------------------------------------------------------------------------- /docs/source/jacinle.nd.rst: -------------------------------------------------------------------------------- 1 | jacinle.nd package 2 | ================== 3 | 4 | .. automodule:: jacinle.nd 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.nd.batch module 13 | ----------------------- 14 | 15 | .. automodule:: jacinle.nd.batch 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jacinle.nd.indexing module 21 | -------------------------- 22 | 23 | .. automodule:: jacinle.nd.indexing 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jacinle.nd.meta module 29 | ---------------------- 30 | 31 | .. automodule:: jacinle.nd.meta 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jacinle.nd.shape module 37 | ----------------------- 38 | 39 | .. automodule:: jacinle.nd.shape 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /jacinle/utils/exception.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : exception.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 12/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | __all__ = ['format_exc'] 12 | 13 | 14 | def format_exc(ei): 15 | """Format an exception info tuple into a string. Useful in context managers.""" 16 | 17 | import io 18 | import traceback 19 | 20 | sio = io.StringIO() 21 | tb = ei[2] 22 | # See issues #9427, #1553375. Commented out for now. 23 | # if getattr(self, 'fullstack', False): 24 | # traceback.print_stack(tb.tb_frame.f_back, file=sio) 25 | traceback.print_exception(ei[0], ei[1], tb, None, sio) 26 | s = sio.getvalue() 27 | sio.close() 28 | if s[-1:] == "\n": 29 | s = s[:-1] 30 | return s 31 | 32 | -------------------------------------------------------------------------------- /jaclearn/rl/simulator/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/23/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | 12 | from .controller import * 13 | from .pack import * 14 | 15 | 16 | __quit_action__ = 32767 17 | 18 | 19 | def automake(name, *args, **kwargs): 20 | if name.startswith('gym.'): 21 | name = name[4:] 22 | from ..envs.gym import GymRLEnv 23 | return GymRLEnv(name, *args, **kwargs) 24 | elif name.startswith('jacinle.'): 25 | raise NotImplementedError() 26 | 27 | name = name[8:] 28 | from .. import custom 29 | assert hasattr(custom, name), 'Custom RLEnviron {} not found.'.format(name) 30 | return getattr(custom, name)(*args, **kwargs) 31 | -------------------------------------------------------------------------------- /docs/source/jactorch.rst: -------------------------------------------------------------------------------- 1 | jactorch package 2 | ================ 3 | 4 | .. automodule:: jactorch 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jactorch.cuda 16 | jactorch.data 17 | jactorch.functional 18 | jactorch.graph 19 | jactorch.models 20 | jactorch.nn 21 | jactorch.optim 22 | jactorch.parallel 23 | jactorch.quickstart 24 | jactorch.train 25 | jactorch.transforms 26 | jactorch.utils 27 | jactorch.vision 28 | 29 | Submodules 30 | ---------- 31 | 32 | jactorch.cli module 33 | ------------------- 34 | 35 | .. automodule:: jactorch.cli 36 | :members: 37 | :undoc-members: 38 | :show-inheritance: 39 | 40 | jactorch.io module 41 | ------------------ 42 | 43 | .. automodule:: jactorch.io 44 | :members: 45 | :undoc-members: 46 | :show-inheritance: 47 | -------------------------------------------------------------------------------- /docs/source/jaclearn.logic.propositional.logic_induction.rst: -------------------------------------------------------------------------------- 1 | jaclearn.logic.propositional.logic\_induction package 2 | ===================================================== 3 | 4 | .. automodule:: jaclearn.logic.propositional.logic_induction 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.logic.propositional.logic\_induction.logic\_induction module 13 | --------------------------------------------------------------------- 14 | 15 | .. automodule:: jaclearn.logic.propositional.logic_induction.logic_induction 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.logic.propositional.logic\_induction.setup module 21 | ---------------------------------------------------------- 22 | 23 | .. automodule:: jaclearn.logic.propositional.logic_induction.setup 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | -------------------------------------------------------------------------------- /jactorch/functional/probability.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : probability.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/04/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | """Probability distributions related functions.""" 12 | 13 | __all__ = ['normalize_prob', 'check_prob_normalization'] 14 | 15 | 16 | def normalize_prob(a, dim=-1): 17 | """Perform 1-norm along the specific dimension.""" 18 | return a / a.sum(dim=dim, keepdim=True) 19 | 20 | 21 | def check_prob_normalization(p, dim=-1, atol=1e-5): 22 | """Check if the probability is normalized along a specific dimension.""" 23 | tot = p.sum(dim=dim) 24 | cond = (tot > 1 - atol) * (tot < 1 + atol) 25 | cond = cond.prod() 26 | assert int(cond.data.cpu().numpy()) == 1, 'Probability normalization check failed.' 27 | -------------------------------------------------------------------------------- /docs/source/jaclearn.rl.rst: -------------------------------------------------------------------------------- 1 | jaclearn.rl package 2 | =================== 3 | 4 | .. automodule:: jaclearn.rl 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.rl.algo 16 | jaclearn.rl.engines 17 | jaclearn.rl.envs 18 | jaclearn.rl.simulator 19 | 20 | Submodules 21 | ---------- 22 | 23 | jaclearn.rl.env module 24 | ---------------------- 25 | 26 | .. automodule:: jaclearn.rl.env 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | jaclearn.rl.proxy module 32 | ------------------------ 33 | 34 | .. automodule:: jaclearn.rl.proxy 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | jaclearn.rl.space module 40 | ------------------------ 41 | 42 | .. automodule:: jaclearn.rl.space 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | -------------------------------------------------------------------------------- /examples/comm-service/server.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : server.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/19/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.cli.argument import JacArgumentParser 12 | from jacinle.comm.service import Service 13 | 14 | 15 | class MyService(Service): 16 | def call(self, inp): 17 | out = inp['a'] + inp['b'] 18 | print('Server string: {} {}.'.format(inp['a'], inp['b'])) 19 | return dict(out=out) 20 | 21 | 22 | def main(): 23 | parser = JacArgumentParser() 24 | parser.add_argument('--simple', action='store_true') 25 | args = parser.parse_args() 26 | 27 | s = MyService() 28 | s.serve_socket(tcp_port=[31001, 31002], use_simple=args.simple) 29 | 30 | 31 | if __name__ == '__main__': 32 | main() 33 | -------------------------------------------------------------------------------- /docs/source/jacinle.cli.rst: -------------------------------------------------------------------------------- 1 | jacinle.cli package 2 | =================== 3 | 4 | .. automodule:: jacinle.cli 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.cli.argument module 13 | --------------------------- 14 | 15 | .. automodule:: jacinle.cli.argument 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jacinle.cli.device module 21 | ------------------------- 22 | 23 | .. automodule:: jacinle.cli.device 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jacinle.cli.git module 29 | ---------------------- 30 | 31 | .. automodule:: jacinle.cli.git 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jacinle.cli.keyboard module 37 | --------------------------- 38 | 39 | .. automodule:: jacinle.cli.keyboard 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /docs2/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs2/source/_templates/class.rst: -------------------------------------------------------------------------------- 1 | {{ fullname | escape | underline}} 2 | 3 | .. currentmodule:: {{ module }} 4 | 5 | .. autoclass:: {{ objname }} 6 | :members: 7 | :show-inheritance: 8 | :inherited-members: str, list, set, frozenset, dict, Module 9 | :undoc-members: 10 | :special-members: __call__, __add__, __mul__, __div__, __floordiv__ 11 | 12 | {% block methods %} 13 | {% if methods %} 14 | .. rubric:: {{ _('Methods') }} 15 | 16 | .. autosummary:: 17 | {% for item in methods %} 18 | {%- if not item.startswith('_') %} 19 | ~{{ name }}.{{ item }} 20 | {%- endif -%} 21 | {%- endfor %} 22 | {% endif %} 23 | {% endblock %} 24 | 25 | {% block attributes %} 26 | {% if attributes %} 27 | .. rubric:: {{ _('Attributes') }} 28 | 29 | .. autosummary:: 30 | {% for item in attributes %} 31 | ~{{ name }}.{{ item }} 32 | {%- endfor %} 33 | {% endif %} 34 | {% endblock %} 35 | -------------------------------------------------------------------------------- /docs/source/jactorch.train.rst: -------------------------------------------------------------------------------- 1 | jactorch.train package 2 | ====================== 3 | 4 | .. automodule:: jactorch.train 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.train.env module 13 | ------------------------- 14 | 15 | .. automodule:: jactorch.train.env 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.train.monitor module 21 | ----------------------------- 22 | 23 | .. automodule:: jactorch.train.monitor 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.train.tb module 29 | ------------------------ 30 | 31 | .. automodule:: jactorch.train.tb 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jactorch.train.utils module 37 | --------------------------- 38 | 39 | .. automodule:: jactorch.train.utils 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /examples/comm-service/client.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : client.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/19/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import time 12 | 13 | from jacinle.cli.argument import JacArgumentParser 14 | from jacinle.comm.service import SocketClient 15 | 16 | 17 | def main(): 18 | parser = JacArgumentParser() 19 | parser.add_argument('--simple', action='store_true') 20 | args = parser.parse_args() 21 | 22 | client = SocketClient('client', ['tcp://127.0.0.1:31001', 'tcp://127.0.0.1:31002'], use_simple=args.simple) 23 | with client.activate(): 24 | inp = dict(a=1, b=2) 25 | out = client.call(inp) 26 | print('Success: input={}, output={}'.format(inp, out)) 27 | time.sleep(1) 28 | 29 | 30 | if __name__ == '__main__': 31 | main() 32 | -------------------------------------------------------------------------------- /docs/source/jacinle.image.rst: -------------------------------------------------------------------------------- 1 | jacinle.image package 2 | ===================== 3 | 4 | .. automodule:: jacinle.image 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.image.backend module 13 | ---------------------------- 14 | 15 | .. automodule:: jacinle.image.backend 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jacinle.image.codecs module 21 | --------------------------- 22 | 23 | .. automodule:: jacinle.image.codecs 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jacinle.image.imgio module 29 | -------------------------- 30 | 31 | .. automodule:: jacinle.image.imgio 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jacinle.image.imgproc module 37 | ---------------------------- 38 | 39 | .. automodule:: jacinle.image.imgproc 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /docs/source/jactorch.utils.rst: -------------------------------------------------------------------------------- 1 | jactorch.utils package 2 | ====================== 3 | 4 | .. automodule:: jactorch.utils 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.utils.grad module 13 | -------------------------- 14 | 15 | .. automodule:: jactorch.utils.grad 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.utils.init module 21 | -------------------------- 22 | 23 | .. automodule:: jactorch.utils.init 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.utils.meta module 29 | -------------------------- 30 | 31 | .. automodule:: jactorch.utils.meta 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jactorch.utils.unittest module 37 | ------------------------------ 38 | 39 | .. automodule:: jactorch.utils.unittest 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /examples/kv-lmdb/lmdb-multi-read.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : lmdb-multi-read.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/17/2023 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.storage.kv.lmdb import LMDBKVStore 12 | 13 | 14 | def main(): 15 | kv = LMDBKVStore('/tmp/test_2.lmdb', readonly=True, max_dbs=128) 16 | 17 | assert 'a' in kv and kv['a'] == 1 18 | assert 'b' in kv and kv['b'] == 2 19 | assert 'c' not in kv 20 | assert 'd' not in kv 21 | 22 | assert kv.has('c', db='sub') and kv.get('c', db='sub') == 3 23 | assert kv.has('d', db='sub') and kv.get('d', db='sub') == 4 24 | 25 | for k in kv.keys(): 26 | print(k, kv[k]) 27 | 28 | for k in kv.keys(db='sub'): 29 | print('sub', k, kv.get(k, db='sub')) 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | 35 | -------------------------------------------------------------------------------- /jacinle/utils/deprecated.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : deprecated.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/21/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import functools 12 | 13 | from jacinle.logging import get_logger 14 | 15 | logger = get_logger(__file__) 16 | 17 | __all__ = ['deprecated'] 18 | 19 | 20 | def deprecated(func): 21 | """A helper decorator to mark a function as deprecated. It will result in a warning being emitted when the function is used (each function is only warned once).""" 22 | @functools.wraps(func) 23 | def new_func(*args, **kwargs): 24 | if func not in deprecated.logged: 25 | deprecated.logged.add(func) 26 | logger.warning(func.__doc__) 27 | return func(*args, **kwargs) 28 | return new_func 29 | 30 | 31 | deprecated.logged = set() 32 | 33 | -------------------------------------------------------------------------------- /jaclearn/vision/coco/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, Extension 2 | import numpy as np 3 | 4 | # To compile and install locally run "python setup.py build_ext --inplace" 5 | # To install library to Python site-packages run "python setup.py build_ext install" 6 | 7 | ext_modules = [ 8 | Extension( 9 | 'pycocotools._mask', 10 | sources=['src/maskApi.c', 'pycocotools/_mask.pyx'], 11 | include_dirs = [np.get_include(), 'src'], 12 | extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'], 13 | ) 14 | ] 15 | 16 | if __name__ == '__main__': 17 | setup( 18 | name='pycocotools', 19 | packages=['pycocotools'], 20 | package_dir = {'pycocotools': 'pycocotools'}, 21 | install_requires=[ 22 | 'setuptools>=18.0', 23 | 'cython>=0.27.3', 24 | 'matplotlib>=2.1.0' 25 | ], 26 | version='2.0', 27 | ext_modules= ext_modules 28 | ) 29 | 30 | -------------------------------------------------------------------------------- /docs/source/jaclearn.vision.rst: -------------------------------------------------------------------------------- 1 | jaclearn.vision package 2 | ======================= 3 | 4 | .. automodule:: jaclearn.vision 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jaclearn.vision.coco 16 | 17 | Submodules 18 | ---------- 19 | 20 | jaclearn.vision.graph\_cut module 21 | --------------------------------- 22 | 23 | .. automodule:: jaclearn.vision.graph_cut 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jaclearn.vision.graph\_cut\_inpaint module 29 | ------------------------------------------ 30 | 31 | .. automodule:: jaclearn.vision.graph_cut_inpaint 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jaclearn.vision.patch\_match module 37 | ----------------------------------- 38 | 39 | .. automodule:: jaclearn.vision.patch_match 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /vendors/pytorch_reservoir/pytorch_reservoir.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/11/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import sys 12 | import os.path as osp 13 | from jacinle.jit.cext import auto_travis 14 | from jacinle.utils.cache import cached_result 15 | 16 | 17 | @cached_result 18 | def _load_extension(): 19 | auto_travis(__file__) 20 | sys.path.insert(0, osp.join(osp.dirname(__file__), 'torch_sampling')) 21 | import torch_sampling 22 | sys.path = sys.path[1:] 23 | return torch_sampling 24 | 25 | 26 | # TODO(Jiayuan Mao @ 04/11): add the signature. 27 | def choice(*args, **kwargs): 28 | return _load_extension().choice(*args, **kwargs) 29 | 30 | 31 | def reservoir_sampling(*args, **kwargs): 32 | return _load_extension().reservoir_sampling(*args, **kwargs) 33 | 34 | -------------------------------------------------------------------------------- /docs/source/jactorch.graph.rst: -------------------------------------------------------------------------------- 1 | jactorch.graph package 2 | ====================== 3 | 4 | .. automodule:: jactorch.graph 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.graph.context module 13 | ----------------------------- 14 | 15 | .. automodule:: jactorch.graph.context 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.graph.nn\_env module 21 | ----------------------------- 22 | 23 | .. automodule:: jactorch.graph.nn_env 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.graph.parameter module 29 | ------------------------------- 30 | 31 | .. automodule:: jactorch.graph.parameter 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jactorch.graph.variable module 37 | ------------------------------ 38 | 39 | .. automodule:: jactorch.graph.variable 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /jactorch/functional/linalg.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : linalg.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/04/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | """Linear algebra functions.""" 12 | 13 | __all__ = ['normalize'] 14 | 15 | 16 | def normalize(tensor, p=2, dim=-1, eps=1e-8): 17 | r""" 18 | Normalize the input along a specific dimension. 19 | 20 | .. math:: 21 | tensor = \frac{tensor}{\max(\lVert tensor \rVert_p, \epsilon)} 22 | 23 | Args: 24 | tensor (Tensor): input. 25 | p (int): the exponent value in the norm formulation. Default: 2. 26 | dim (int): the dimension of the normalization. 27 | eps (float): eps for numerical stability. 28 | 29 | Returns: 30 | Tensor: normalized input. 31 | 32 | """ 33 | return tensor / tensor.norm(p, dim=dim, keepdim=True).clamp(min=eps) 34 | -------------------------------------------------------------------------------- /jactorch/optim/quickaccess.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : quickaccess.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/28/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import torch.optim as optim 12 | import jactorch.optim as jacoptim 13 | 14 | 15 | def get_optimizer(optimizer, model, *args, **kwargs): 16 | if isinstance(optimizer, (optim.Optimizer, jacoptim.CustomizedOptimizer)): 17 | return optimizer 18 | 19 | if type(optimizer) is str: 20 | try: 21 | optimizer = getattr(optim, optimizer) 22 | except AttributeError: 23 | try: 24 | optimizer = getattr(jacoptim, optimizer) 25 | except AttributeError: 26 | raise ValueError('Unknown optimizer type: {}.'.format(optimizer)) 27 | 28 | return optimizer(filter(lambda p: p.requires_grad, model.parameters()), *args, **kwargs) 29 | -------------------------------------------------------------------------------- /docs/source/jaclearn.vision.coco.pycocotools.rst: -------------------------------------------------------------------------------- 1 | jaclearn.vision.coco.pycocotools package 2 | ======================================== 3 | 4 | .. automodule:: jaclearn.vision.coco.pycocotools 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.vision.coco.pycocotools.coco module 13 | -------------------------------------------- 14 | 15 | .. automodule:: jaclearn.vision.coco.pycocotools.coco 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.vision.coco.pycocotools.cocoeval module 21 | ------------------------------------------------ 22 | 23 | .. automodule:: jaclearn.vision.coco.pycocotools.cocoeval 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jaclearn.vision.coco.pycocotools.mask module 29 | -------------------------------------------- 30 | 31 | .. automodule:: jaclearn.vision.coco.pycocotools.mask 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | -------------------------------------------------------------------------------- /docs/source/jactorch.nn.cnn.rst: -------------------------------------------------------------------------------- 1 | jactorch.nn.cnn package 2 | ======================= 3 | 4 | .. automodule:: jactorch.nn.cnn 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.nn.cnn.conv module 13 | --------------------------- 14 | 15 | .. automodule:: jactorch.nn.cnn.conv 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.nn.cnn.coord\_conv module 21 | ---------------------------------- 22 | 23 | .. automodule:: jactorch.nn.cnn.coord_conv 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.nn.cnn.functional module 29 | --------------------------------- 30 | 31 | .. automodule:: jactorch.nn.cnn.functional 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jactorch.nn.cnn.layers module 37 | ----------------------------- 38 | 39 | .. automodule:: jactorch.nn.cnn.layers 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /docs/source/jacinle.storage.kv.rst: -------------------------------------------------------------------------------- 1 | jacinle.storage.kv package 2 | ========================== 3 | 4 | .. automodule:: jacinle.storage.kv 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.storage.kv.kv module 13 | ---------------------------- 14 | 15 | .. automodule:: jacinle.storage.kv.kv 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jacinle.storage.kv.lmdb module 21 | ------------------------------ 22 | 23 | .. automodule:: jacinle.storage.kv.lmdb 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jacinle.storage.kv.mem module 29 | ----------------------------- 30 | 31 | .. automodule:: jacinle.storage.kv.mem 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jacinle.storage.kv.memcached module 37 | ----------------------------------- 38 | 39 | .. automodule:: jacinle.storage.kv.memcached 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /jactorch/transforms/image/transforms.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : transforms.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 10/27/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from . import functional as F 12 | 13 | __all__ = ['Pad', 'PadMultipleOf'] 14 | 15 | 16 | class Pad(object): 17 | def __init__(self, padding, mode='constant', fill=0): 18 | self.padding = padding 19 | self.mode = mode 20 | self.fill = fill 21 | 22 | def __call__(self, img): 23 | return F.pad(img, self.padding, mode=self.mode, fill=self.fill) 24 | 25 | 26 | class PadMultipleOf(object): 27 | def __init__(self, multiple, mode='constant', fill=0): 28 | self.multiple = multiple 29 | self.mode = mode 30 | self.fill = fill 31 | 32 | def __call__(self, img): 33 | return F.pad_multiple_of(img, self.multiple, mode=self.mode, fill=self.fill) 34 | -------------------------------------------------------------------------------- /jactorch/vision/geometry.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : geometry.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/04/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import torch 12 | import jactorch 13 | import torch.nn.functional as F 14 | 15 | __all__ = ['gen_voronoi'] 16 | 17 | 18 | def gen_voronoi(centers, height, width): 19 | range_y = torch.arange(height, device=centers.device) 20 | range_x = torch.arange(width, device=centers.device) 21 | y, x = jactorch.meshgrid(range_y, range_x, dim=0) 22 | y, x = y.reshape(-1), x.reshape(-1) 23 | coords = torch.stack([y, x], dim=1).float() 24 | coords, centers = jactorch.meshgrid(coords, centers, dim=0) 25 | dis = (coords[:, :, 0] - centers[:, :, 1]) ** 2 + (coords[:, :, 1] - centers[:, :, 0]) ** 2 26 | assignment = dis.argmin(1) 27 | return dis.view((height, width, -1)), assignment.view((height, width)) 28 | 29 | -------------------------------------------------------------------------------- /docs/source/jaclearn.dataflow.rst: -------------------------------------------------------------------------------- 1 | jaclearn.dataflow package 2 | ========================= 3 | 4 | .. automodule:: jaclearn.dataflow 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.dataflow.batch module 13 | ------------------------------ 14 | 15 | .. automodule:: jaclearn.dataflow.batch 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.dataflow.collections module 21 | ------------------------------------ 22 | 23 | .. automodule:: jaclearn.dataflow.collections 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jaclearn.dataflow.dataflow module 29 | --------------------------------- 30 | 31 | .. automodule:: jaclearn.dataflow.dataflow 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jaclearn.dataflow.utils module 37 | ------------------------------ 38 | 39 | .. automodule:: jaclearn.dataflow.utils 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /docs/source/jaclearn.imageaug.rst: -------------------------------------------------------------------------------- 1 | jaclearn.imageaug package 2 | ========================= 3 | 4 | .. automodule:: jaclearn.imageaug 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.imageaug.cblk module 13 | ----------------------------- 14 | 15 | .. automodule:: jaclearn.imageaug.cblk 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.imageaug.executor module 21 | --------------------------------- 22 | 23 | .. automodule:: jaclearn.imageaug.executor 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jaclearn.imageaug.photography module 29 | ------------------------------------ 30 | 31 | .. automodule:: jaclearn.imageaug.photography 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jaclearn.imageaug.shape module 37 | ------------------------------ 38 | 39 | .. automodule:: jaclearn.imageaug.shape 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /docs/source/jaclearn.nlp.tree.rst: -------------------------------------------------------------------------------- 1 | jaclearn.nlp.tree package 2 | ========================= 3 | 4 | .. automodule:: jaclearn.nlp.tree 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.nlp.tree.constituency module 13 | ------------------------------------- 14 | 15 | .. automodule:: jaclearn.nlp.tree.constituency 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.nlp.tree.node module 21 | ----------------------------- 22 | 23 | .. automodule:: jaclearn.nlp.tree.node 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jaclearn.nlp.tree.ptb module 29 | ---------------------------- 30 | 31 | .. automodule:: jaclearn.nlp.tree.ptb 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jaclearn.nlp.tree.traversal module 37 | ---------------------------------- 38 | 39 | .. automodule:: jaclearn.nlp.tree.traversal 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /jacinle/image/imgio.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : imgio.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import os.path as osp 12 | 13 | from . import backend 14 | from .imgproc import dimshuffle 15 | 16 | 17 | __all__ = ['imread', 'imwrite', 'imshow'] 18 | 19 | 20 | def imread(path, *, shuffle=False): 21 | if not osp.exists(path): 22 | return None 23 | i = backend.imread(path) 24 | if i is None: 25 | return None 26 | if shuffle: 27 | return dimshuffle(i, 'channel_first') 28 | return i 29 | 30 | 31 | def imwrite(path, img, *, shuffle=False): 32 | if shuffle: 33 | img = dimshuffle(img, 'channel_last') 34 | backend.imwrite(path, img) 35 | 36 | 37 | def imshow(title, img, *, shuffle=False): 38 | if shuffle: 39 | img = dimshuffle(img, 'channel_last') 40 | backend.imshow(title, img) 41 | -------------------------------------------------------------------------------- /jactorch/nn/linear.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : linear.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/10/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import torch.nn as nn 12 | 13 | from jactorch.functional import concat_shape 14 | 15 | __all__ = ['AnyDimLinear'] 16 | 17 | 18 | class AnyDimLinear(nn.Linear): 19 | def __init__(self, in_features, out_features, hidden_dim=-1, bias=True): 20 | super().__init__(in_features, out_features, bias=bias) 21 | self.hidden_dim = hidden_dim 22 | 23 | def forward(self, input): 24 | input = input.transpose(self.hidden_dim, -1) 25 | other_dims = input.size()[:-1] 26 | input = input.contiguous().view(-1, self.in_features) 27 | output = super().forward(input) 28 | output = output.view(concat_shape(other_dims, -1)) 29 | output = output.transpose(self.hidden_dim, -1) 30 | return output 31 | 32 | -------------------------------------------------------------------------------- /jactorch/utils/unittest.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : unittest.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/27/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import unittest 12 | 13 | import numpy as np 14 | from torch.autograd import Variable 15 | 16 | 17 | def _as_numpy(v): 18 | if isinstance(v, np.ndarray): 19 | return v 20 | if isinstance(v, Variable): 21 | v = v.data 22 | return v.cpu().numpy() 23 | 24 | 25 | class TorchTestCase(unittest.TestCase): 26 | def assertTensorClose(self, a, b, atol=1e-3, rtol=1e-3): 27 | npa, npb = _as_numpy(a), _as_numpy(b) 28 | self.assertTrue( 29 | np.allclose(npa, npb, atol=atol), 30 | 'Tensor close check failed\n{}\n{}\nadiff={}, rdiff={}'.format( 31 | a, b, np.abs(npa - npb).max(), np.abs((npa - npb) / np.fmax(npa, 1e-5)).max() 32 | ) 33 | ) 34 | -------------------------------------------------------------------------------- /jacinle/storage/kv/mem.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : mem.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .base import KVStoreBase 12 | 13 | 14 | class MemKVStore(KVStoreBase): 15 | """A simple in-memory key-value store.""" 16 | 17 | def __init__(self, readonly=False): 18 | super().__init__(readonly=readonly) 19 | self._store = dict() 20 | 21 | def _has(self, key): 22 | return key in self._store 23 | 24 | def _get(self, key, default): 25 | return self._store.get(key, default) 26 | 27 | def _put(self, key, value, replace): 28 | if not replace: 29 | self._store.setdefault(key, value) 30 | else: 31 | self._store[key] = value 32 | 33 | def _erase(self, key): 34 | return self._store.pop(key) 35 | 36 | def _keys(self): 37 | return self._store.keys() 38 | -------------------------------------------------------------------------------- /docs/source/jactorch.transforms.vision.functional.rst: -------------------------------------------------------------------------------- 1 | jactorch.transforms.vision.functional package 2 | ============================================= 3 | 4 | .. automodule:: jactorch.transforms.vision.functional 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.transforms.vision.functional.bbox module 13 | ------------------------------------------------- 14 | 15 | .. automodule:: jactorch.transforms.vision.functional.bbox 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.transforms.vision.functional.coor module 21 | ------------------------------------------------- 22 | 23 | .. automodule:: jactorch.transforms.vision.functional.coor 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.transforms.vision.functional.image module 29 | -------------------------------------------------- 30 | 31 | .. automodule:: jactorch.transforms.vision.functional.image 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | -------------------------------------------------------------------------------- /jactorch/utils/init.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : init.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/01/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | 12 | def register_rng(): 13 | from jacinle.random.rng import global_rng_registry, global_rng_state_registry 14 | 15 | try: 16 | import torch 17 | # This will also automatically initialize cuda seeds. 18 | global_rng_registry.register('torch', lambda: torch.manual_seed) 19 | global_rng_state_registry.register('torch', lambda: (torch.get_rng_state, torch.set_rng_state)) 20 | 21 | if torch.cuda.is_available(): 22 | global_rng_registry.register('torch_cuda', lambda: torch.cuda.manual_seed_all) 23 | global_rng_state_registry.register('torch_cuda', lambda: (torch.cuda.get_rng_state_all, torch.cuda.set_rng_state_all)) 24 | 25 | except ImportError: 26 | pass 27 | 28 | 29 | def init_main(): 30 | register_rng() 31 | -------------------------------------------------------------------------------- /docs/source/jacinle.io.rst: -------------------------------------------------------------------------------- 1 | jacinle.io package 2 | ================== 3 | 4 | .. automodule:: jacinle.io 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jacinle.io.common module 13 | ------------------------ 14 | 15 | .. automodule:: jacinle.io.common 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jacinle.io.fs module 21 | -------------------- 22 | 23 | .. automodule:: jacinle.io.fs 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jacinle.io.network module 29 | ------------------------- 30 | 31 | .. automodule:: jacinle.io.network 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jacinle.io.pretty module 37 | ------------------------ 38 | 39 | .. automodule:: jacinle.io.pretty 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | 44 | jacinle.io.tempfile module 45 | -------------------------- 46 | 47 | .. automodule:: jacinle.io.tempfile 48 | :members: 49 | :undoc-members: 50 | :show-inheritance: 51 | -------------------------------------------------------------------------------- /docs/source/jaclearn.datasets.image_classification.rst: -------------------------------------------------------------------------------- 1 | jaclearn.datasets.image\_classification package 2 | =============================================== 3 | 4 | .. automodule:: jaclearn.datasets.image_classification 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.datasets.image\_classification.cifar module 13 | ---------------------------------------------------- 14 | 15 | .. automodule:: jaclearn.datasets.image_classification.cifar 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.datasets.image\_classification.mnist module 21 | ---------------------------------------------------- 22 | 23 | .. automodule:: jaclearn.datasets.image_classification.mnist 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jaclearn.datasets.image\_classification.svhn module 29 | --------------------------------------------------- 30 | 31 | .. automodule:: jaclearn.datasets.image_classification.svhn 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | -------------------------------------------------------------------------------- /scripts/name-server.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : name-server.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/18/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import argparse 12 | 13 | from jacinle.comm.distrib.name_server import _configs as configs 14 | from jacinle.comm.distrib.name_server import run_name_server 15 | from jacinle.logging import get_logger 16 | 17 | logger = get_logger(__file__) 18 | 19 | parser = argparse.ArgumentParser() 20 | parser.add_argument('-s', '--host', dest='host', default=configs.NS_CTL_HOST) 21 | parser.add_argument('-p', '--port', dest='port', default=configs.NS_CTL_PORT) 22 | parser.add_argument('--protocal', dest='protocal', default=configs.NS_CTL_PROTOCAL) 23 | args = parser.parse_args() 24 | 25 | 26 | if __name__ == '__main__': 27 | logger.critical('Starting name server at {}://{}:{}.'.format(args.protocal, args.host, args.port)) 28 | run_name_server(host=args.host, port=args.port, protocal=args.protocal) 29 | -------------------------------------------------------------------------------- /jacinle/concurrency/future.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : future.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import threading 12 | 13 | __all__ = ['FutureResult'] 14 | 15 | 16 | class FutureResult(object): 17 | """A thread-safe future implementation. Used only as one-to-one pipe.""" 18 | 19 | def __init__(self): 20 | self._result = None 21 | self._lock = threading.Lock() 22 | self._cond = threading.Condition(self._lock) 23 | 24 | def put(self, result): 25 | with self._lock: 26 | assert self._result is None, 'Previous result has\'t been fetched.' 27 | self._result = result 28 | self._cond.notify() 29 | 30 | def get(self): 31 | with self._lock: 32 | if self._result is None: 33 | self._cond.wait() 34 | 35 | res = self._result 36 | self._result = None 37 | return res 38 | -------------------------------------------------------------------------------- /jaclearn/datasets/image_classification/mnist.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : mnist.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import os.path as osp 12 | 13 | import gzip 14 | import pickle 15 | 16 | from jacinle.io.network import download 17 | 18 | __all__ = ['load_mnist'] 19 | 20 | 21 | def load_mnist( 22 | data_dir, 23 | data_file='mnist.pkl.gz', 24 | origin='http://www.iro.umontreal.ca/~lisa/deep/data/mnist/mnist.pkl.gz'): 25 | 26 | dataset = osp.join(data_dir, data_file) 27 | 28 | if (not osp.isfile(dataset)) and data_file == 'mnist.pkl.gz': 29 | download(origin, data_dir, data_file) 30 | 31 | # Load the dataset 32 | with gzip.open(dataset, 'rb') as f: 33 | try: 34 | train_set, valid_set, test_set = pickle.load(f, encoding='latin1') 35 | except: 36 | train_set, valid_set, test_set = pickle.load(f) 37 | return train_set, valid_set, test_set 38 | -------------------------------------------------------------------------------- /docs/source/jaclearn.embedding.rst: -------------------------------------------------------------------------------- 1 | jaclearn.embedding package 2 | ========================== 3 | 4 | .. automodule:: jaclearn.embedding 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.embedding.constant module 13 | ---------------------------------- 14 | 15 | .. automodule:: jaclearn.embedding.constant 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.embedding.embedding\_utils module 21 | ------------------------------------------ 22 | 23 | .. automodule:: jaclearn.embedding.embedding_utils 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jaclearn.embedding.visualize\_tb module 29 | --------------------------------------- 30 | 31 | .. automodule:: jaclearn.embedding.visualize_tb 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jaclearn.embedding.word\_embedding module 37 | ----------------------------------------- 38 | 39 | .. automodule:: jaclearn.embedding.word_embedding 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /jaclearn/logic/propositional/logic_induction/setup.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : setup.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/16/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from setuptools import setup, Extension 12 | import numpy as np 13 | 14 | # To compile and install locally run "python setup.py build_ext --inplace" 15 | # To install library to Python site-packages run "python setup.py build_ext install" 16 | 17 | ext_modules = [ 18 | Extension( 19 | 'logic_induction', 20 | sources=['csrc/logic_induction_impl.cc', 'logic_induction.pyx'], 21 | include_dirs = [np.get_include(), 'src'], 22 | language='c++', 23 | extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c++14', '-Ofast'], 24 | ) 25 | ] 26 | 27 | if __name__ == '__main__': 28 | setup( 29 | name='logic_induction', 30 | packages=['logic_induction'], 31 | version='1.0', 32 | ext_modules=ext_modules 33 | ) 34 | 35 | 36 | -------------------------------------------------------------------------------- /docs/source/jactorch.data.collate.rst: -------------------------------------------------------------------------------- 1 | jactorch.data.collate package 2 | ============================= 3 | 4 | .. automodule:: jactorch.data.collate 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.data.collate.collate\_v1 module 13 | ---------------------------------------- 14 | 15 | .. automodule:: jactorch.data.collate.collate_v1 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.data.collate.collate\_v2 module 21 | ---------------------------------------- 22 | 23 | .. automodule:: jactorch.data.collate.collate_v2 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.data.collate.collate\_v3 module 29 | ---------------------------------------- 30 | 31 | .. automodule:: jactorch.data.collate.collate_v3 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jactorch.data.collate.utils module 37 | ---------------------------------- 38 | 39 | .. automodule:: jactorch.data.collate.utils 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | -------------------------------------------------------------------------------- /examples/kv-lmdb/lmdb-multi.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : lmdb-multi.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/17/2023 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.storage.kv.lmdb import LMDBKVStore 12 | 13 | 14 | def main(): 15 | kv = LMDBKVStore('/tmp/test_2.lmdb', readonly=False, max_dbs=128) 16 | 17 | with kv.transaction(): 18 | kv['a'] = 1 19 | kv['b'] = 2 20 | 21 | kv.put('c', 3, db='sub') 22 | kv.put('d', 4, db='sub') 23 | 24 | assert 'a' in kv and kv['a'] == 1 25 | assert 'b' in kv and kv['b'] == 2 26 | assert 'c' not in kv 27 | assert 'd' not in kv 28 | 29 | assert kv.has('c', db='sub') and kv.get('c', db='sub') == 3 30 | assert kv.has('d', db='sub') and kv.get('d', db='sub') == 4 31 | 32 | for k in kv.keys(): 33 | print(k, kv[k]) 34 | 35 | for k in kv.keys(db='sub'): 36 | print('sub', k, kv.get(k, db='sub')) 37 | 38 | 39 | if __name__ == '__main__': 40 | main() 41 | 42 | -------------------------------------------------------------------------------- /docs/source/jaclearn.nlp.graph.dependency_visualizer.rst: -------------------------------------------------------------------------------- 1 | jaclearn.nlp.graph.dependency\_visualizer package 2 | ================================================= 3 | 4 | .. automodule:: jaclearn.nlp.graph.dependency_visualizer 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.nlp.graph.dependency\_visualizer.render module 13 | ------------------------------------------------------- 14 | 15 | .. automodule:: jaclearn.nlp.graph.dependency_visualizer.render 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.nlp.graph.dependency\_visualizer.templates module 21 | ---------------------------------------------------------- 22 | 23 | .. automodule:: jaclearn.nlp.graph.dependency_visualizer.templates 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jaclearn.nlp.graph.dependency\_visualizer.utils module 29 | ------------------------------------------------------ 30 | 31 | .. automodule:: jaclearn.nlp.graph.dependency_visualizer.utils 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | -------------------------------------------------------------------------------- /examples/comm-service-nameserver/server.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : server.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/11/2025 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.comm.service import Service 12 | 13 | 14 | class MyService(Service): 15 | def __init__(self, name): 16 | super().__init__() 17 | self.name = name 18 | self.endpoints = dict() 19 | 20 | def serve_socket(self): 21 | super().serve_socket(self.name, use_simple=True, register_name_server=True, verbose=True) 22 | 23 | def register_endpoint(self, name, func): 24 | self.endpoints[name] = func 25 | 26 | def call(self, name, *args, **kwargs): 27 | return self.endpoints[name](*args, **kwargs) 28 | 29 | 30 | def main(): 31 | def add(a, b): 32 | return a + b 33 | 34 | service = MyService('my-service/add') 35 | service.register_endpoint('add', add) 36 | service.serve_socket() 37 | 38 | 39 | if __name__ == '__main__': 40 | main() 41 | 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Jiayuan Mao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /jaclearn/nlp/graph/dependency_visualizer/utils.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : utils.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 08/22/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | 12 | def minify_html(html): 13 | """Perform a template-specific, rudimentary HTML minification for displaCy. 14 | Disclaimer: NOT a general-purpose solution, only removes indentation and 15 | newlines. 16 | html (unicode): Markup to minify. 17 | RETURNS (unicode): "Minified" HTML. 18 | """ 19 | return html.strip().replace(" ", "").replace("\n", "") 20 | 21 | 22 | def escape_html(text): 23 | """Replace <, >, &, " with their HTML encoded representation. Intended to 24 | prevent HTML errors in rendered displaCy markup. 25 | text (unicode): The original text. 26 | RETURNS (unicode): Equivalent text to be safely used within HTML. 27 | """ 28 | text = text.replace("&", "&") 29 | text = text.replace("<", "<") 30 | text = text.replace(">", ">") 31 | text = text.replace('"', """) 32 | return text 33 | 34 | -------------------------------------------------------------------------------- /scripts/inspect-file.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : inspect-file.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/16/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import jacinle 12 | import jacinle.io as io 13 | 14 | parser = jacinle.JacArgumentParser() 15 | parser.add_argument('filename', nargs='+') 16 | parser.add_argument('--stprint', action='store_true') 17 | parser.add_argument('--stprint-depth', type=int, default=3) 18 | args = parser.parse_args() 19 | 20 | 21 | def main(): 22 | for i, filename in enumerate(args.filename): 23 | globals()[f'f{i + 1}'] = io.load(filename) 24 | 25 | if args.stprint: 26 | for i in range(len(args.filename)): 27 | print(f'File {i + 1}:') 28 | jacinle.stprint(globals()[f'f{i + 1}'], max_depth=args.stprint_depth) 29 | else: 30 | for i in range(len(args.filename)): 31 | print(f'File {i + 1}: {args.filename[i]} loaded as `f{i + 1}`') 32 | print() 33 | from IPython import embed; embed() 34 | 35 | 36 | if __name__ == '__main__': 37 | main() 38 | 39 | -------------------------------------------------------------------------------- /jacinle/utils/init.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : init.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/25/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import os 12 | import sys 13 | from jacinle.utils.env import jac_is_debug, jac_getenv 14 | 15 | 16 | def release_syslim(): 17 | if jac_getenv('SYSLIM', default='n', type='bool'): 18 | sys.setrecursionlimit(1000000) 19 | try: 20 | import resource 21 | slim = 65536 * 1024 22 | resource.setrlimit(resource.RLIMIT_STACK, (slim, slim)) 23 | except (ImportError, ValueError): # the resource package is not available on Windows 24 | pass 25 | 26 | 27 | def tune_opencv(): 28 | os.environ['OPENCV_OPENCL_RUNTIME'] = '' 29 | 30 | 31 | def enable_ipdb(): 32 | if jac_is_debug(): 33 | if jac_getenv('IMPORT_ALL', 'true', 'bool'): 34 | from jacinle.utils.debug import hook_exception_ipdb 35 | hook_exception_ipdb() 36 | 37 | 38 | def init_main(): 39 | release_syslim() 40 | tune_opencv() 41 | enable_ipdb() 42 | 43 | -------------------------------------------------------------------------------- /docs/source/jacinle.comm.rst: -------------------------------------------------------------------------------- 1 | jacinle.comm package 2 | ==================== 3 | 4 | .. automodule:: jacinle.comm 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Subpackages 10 | ----------- 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | jacinle.comm.distrib 16 | 17 | Submodules 18 | ---------- 19 | 20 | jacinle.comm.broadcast module 21 | ----------------------------- 22 | 23 | .. automodule:: jacinle.comm.broadcast 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jacinle.comm.cs module 29 | ---------------------- 30 | 31 | .. automodule:: jacinle.comm.cs 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jacinle.comm.echo module 37 | ------------------------ 38 | 39 | .. automodule:: jacinle.comm.echo 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | 44 | jacinle.comm.gather module 45 | -------------------------- 46 | 47 | .. automodule:: jacinle.comm.gather 48 | :members: 49 | :undoc-members: 50 | :show-inheritance: 51 | 52 | jacinle.comm.service module 53 | --------------------------- 54 | 55 | .. automodule:: jacinle.comm.service 56 | :members: 57 | :undoc-members: 58 | :show-inheritance: 59 | -------------------------------------------------------------------------------- /docs/source/jaclearn.visualize.rst: -------------------------------------------------------------------------------- 1 | jaclearn.visualize package 2 | ========================== 3 | 4 | .. automodule:: jaclearn.visualize 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jaclearn.visualize.box module 13 | ----------------------------- 14 | 15 | .. automodule:: jaclearn.visualize.box 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jaclearn.visualize.html\_table module 21 | ------------------------------------- 22 | 23 | .. automodule:: jaclearn.visualize.html_table 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jaclearn.visualize.imgrid module 29 | -------------------------------- 30 | 31 | .. automodule:: jaclearn.visualize.imgrid 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jaclearn.visualize.imshow module 37 | -------------------------------- 38 | 39 | .. automodule:: jaclearn.visualize.imshow 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | 44 | jaclearn.visualize.plot module 45 | ------------------------------ 46 | 47 | .. automodule:: jaclearn.visualize.plot 48 | :members: 49 | :undoc-members: 50 | :show-inheritance: 51 | -------------------------------------------------------------------------------- /jactorch/cli.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : cli.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/23/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import os 12 | import os.path as osp 13 | import sys 14 | 15 | import jacinle.io as io 16 | from jacinle.cli.git import git_revision_hash 17 | 18 | __alL__ = ['escape_desc_name', 'ensure_path', 'dump_metainfo'] 19 | 20 | 21 | def escape_desc_name(filename): 22 | basename = osp.basename(filename) 23 | if basename.endswith('.py'): 24 | basename = basename[:-3] 25 | name = basename.replace('.', '_') 26 | return name 27 | 28 | 29 | def ensure_path(path): 30 | if not osp.exists(path): 31 | print('Creating directory: "{}".'.format(path)) 32 | os.makedirs(path, exist_ok=True) 33 | return path 34 | 35 | 36 | def dump_metainfo(metainfo=None, **kwargs): 37 | if metainfo is None: 38 | metainfo = {} 39 | metainfo.update(kwargs) 40 | metainfo.setdefault('_cmd', ' '.join(sys.argv)) 41 | metainfo.setdefault('_git', git_revision_hash()) 42 | return io.dumps_json(metainfo, compressed=False) 43 | 44 | -------------------------------------------------------------------------------- /examples/comm-distrib/in_benchmark.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : in_benchmark.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/05/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import time 12 | import itertools 13 | 14 | from threading import Thread 15 | 16 | from jacinle.comm.distrib import control, DistribInputPipe 17 | 18 | 19 | counter = itertools.count() 20 | 21 | 22 | def recv_thread(): 23 | q = DistribInputPipe('jacinle.test') 24 | with control(pipes=[q]): 25 | while True: 26 | q.get() 27 | next(counter) 28 | 29 | 30 | def main(): 31 | current = next(counter) 32 | prob_interval = 1 33 | 34 | Thread(target=recv_thread, daemon=True).start() 35 | 36 | while True: 37 | previous = current 38 | current = next(counter) 39 | now = time.strftime('%Y-%m-%d %H:%M:%S') 40 | nr_packs = current - previous - 1 41 | pps = nr_packs / prob_interval 42 | print('RFlow benchmark: timestamp={}, pps={}.'.format(now, pps)) 43 | time.sleep(prob_interval) 44 | 45 | 46 | if __name__ == '__main__': 47 | main() 48 | -------------------------------------------------------------------------------- /jactorch/serve/service.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : service.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 12/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import torch.backends.cudnn as cudnn 12 | 13 | import jactorch.io as torchio 14 | 15 | from jacinle.logging import get_logger 16 | from jacinle.comm.service import Service 17 | 18 | logger = get_logger(__file__) 19 | 20 | __all__ = ['TorchService'] 21 | 22 | 23 | class TorchService(Service): 24 | def load_model(self, desc, load, use_gpu, gpu_parallel=False, gpu_ids=None, cudnn_benchmark=False, args=None, **kwargs): 25 | model = desc.make_model(args, **kwargs) 26 | 27 | if use_gpu: 28 | model.cuda() 29 | if gpu_parallel: 30 | from jactorch.parallel import JacDataParallel 31 | model = JacDataParallel(model, device_ids=gpu_ids).cuda() 32 | cudnn.benchmark = cudnn_benchmark 33 | 34 | if torchio.load_weights(model, load): 35 | logger.critical('Loaded weights from pretrained model: "{}".'.format(load)) 36 | model.eval() 37 | 38 | return model 39 | 40 | -------------------------------------------------------------------------------- /docs/source/jactorch.optim.rst: -------------------------------------------------------------------------------- 1 | jactorch.optim package 2 | ====================== 3 | 4 | .. automodule:: jactorch.optim 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.optim.accum\_grad module 13 | --------------------------------- 14 | 15 | .. automodule:: jactorch.optim.accum_grad 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.optim.custom\_optimizer module 21 | --------------------------------------- 22 | 23 | .. automodule:: jactorch.optim.custom_optimizer 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.optim.optimizer\_group module 29 | -------------------------------------- 30 | 31 | .. automodule:: jactorch.optim.optimizer_group 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jactorch.optim.quickaccess module 37 | --------------------------------- 38 | 39 | .. automodule:: jactorch.optim.quickaccess 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | 44 | jactorch.optim.weight\_decay module 45 | ----------------------------------- 46 | 47 | .. automodule:: jactorch.optim.weight_decay 48 | :members: 49 | :undoc-members: 50 | :show-inheritance: 51 | -------------------------------------------------------------------------------- /jacinle/concurrency/process.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : process.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import multiprocessing 12 | import os 13 | 14 | from jacinle.config.environ import update_env 15 | from jacinle.logging import get_logger 16 | from jacinle.random.rng import gen_seed, reset_global_seed 17 | 18 | logger = get_logger(__file__) 19 | 20 | __all__ = ['JacProcess'] 21 | 22 | 23 | class JacProcess(multiprocessing.Process): 24 | def __init__(self, *args, extra_env=None, seed=None, **kwargs): 25 | super().__init__(*args, **kwargs) 26 | if seed is None: 27 | seed = gen_seed() 28 | self._extra_env = extra_env 29 | self._seed = seed 30 | 31 | def run(self): 32 | if self._extra_env is not None: 33 | update_env(self._extra_env) 34 | reset_global_seed(self._seed) 35 | logger.critical('JacEnvBox pid={} (ppid={}) rng_seed={}.'.format(os.getpid(), os.getppid(), self._seed)) 36 | super().run() 37 | 38 | def __call__(self): 39 | self.start() 40 | self.join() 41 | -------------------------------------------------------------------------------- /jactorch/nn/sync_batchnorm/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : __init__.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/27/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.utils.vendor import has_vendor, requires_vendors 12 | 13 | __all__ = [ 14 | 'SynchronizedBatchNorm1d', 'SynchronizedBatchNorm2d', 'SynchronizedBatchNorm3d', 15 | 'patch_sync_batchnorm', 'convert_sync_batchnorm' 16 | ] 17 | 18 | 19 | if has_vendor('sync_batchnorm'): 20 | from sync_batchnorm import SynchronizedBatchNorm1d, SynchronizedBatchNorm2d, SynchronizedBatchNorm3d 21 | from sync_batchnorm import patch_sync_batchnorm, convert_model as convert_sync_batchnorm 22 | else: 23 | from jacinle.utils.meta import make_dummy_func 24 | SynchronizedBatchNorm1d = requires_vendors('sync_batchnorm')(make_dummy_func()) 25 | SynchronizedBatchNorm2d = requires_vendors('sync_batchnorm')(make_dummy_func()) 26 | SynchronizedBatchNorm3d = requires_vendors('sync_batchnorm')(make_dummy_func()) 27 | patch_sync_batchnorm = requires_vendors('sync_batchnorm')(make_dummy_func()) 28 | convert_sync_batchnorm = requires_vendors('sync_batchnorm')(make_dummy_func()) 29 | 30 | -------------------------------------------------------------------------------- /jaclearn/imageaug/cblk.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : cblk.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.image import imgproc 12 | 13 | from . import shape as shape_augment 14 | from . import photography as photography_augment 15 | 16 | __all__ = ['fbaug'] 17 | 18 | 19 | def fbaug(img, target_shape=(224, 224), is_training=True, area_range=0.08, aspect_ratio=(3/4, 4/3)): 20 | if is_training: 21 | img = shape_augment.random_size_crop(img, target_shape, area_range=area_range, aspect_ratio=aspect_ratio) 22 | img = photography_augment.color_augment_pack(img, brightness=0.4, contrast=0.4, saturation=0.4) 23 | img = photography_augment.lighting_augment(img, 0.1) 24 | img = shape_augment.horizontal_flip_augment(img, 0.5) 25 | img = imgproc.clip(img).astype('uint8') 26 | return img 27 | else: 28 | h, w = img.shape[:2] 29 | 30 | # 1. scale the image 31 | scale = 256 / min(h, w) 32 | img = imgproc.resize_scale(img, scale) 33 | 34 | # 2. center crop 224x244 patch from the image 35 | return imgproc.center_crop(img, target_shape) 36 | -------------------------------------------------------------------------------- /examples/comm-service-nameserver/README.md: -------------------------------------------------------------------------------- 1 | # Service Example with Name Server 2 | 3 | This repository contains an example implementation of a simple server-client system using the `jacinle.comm.service` module. The system consists of: 4 | 5 | - A **server** (`server.py`) that provides a remote procedure call (RPC) service for adding numbers. 6 | - A **client** (`client.py`) that connects to the server and invokes the `add` function remotely. 7 | - A **name server** for service discovery. 8 | 9 | ## Running the Name Server 10 | To use the name server, set the following environment variable: 11 | 12 | ```sh 13 | export JAC_SNS_HOST=YOUR_NAME_SERVER_HOST 14 | ``` 15 | 16 | To start a name server yourself, run: 17 | 18 | ```sh 19 | jac-service-name-server 20 | ``` 21 | 22 | ## Run the Service Server 23 | 24 | To start the server, run: 25 | 26 | ```sh 27 | python server.py 28 | ``` 29 | 30 | This will: 31 | - Register the service under the name `my-service/add`. 32 | - Start a socket-based communication service. 33 | 34 | ## Running the Client 35 | 36 | To invoke the `add` function remotely, run: 37 | 38 | ```sh 39 | python client.py 40 | ``` 41 | 42 | The client will: 43 | - Connect to the name server to resolve `my-service/add`. 44 | - Call the `add` function with parameters `(1, 2)`. 45 | - Print the result (`3`). 46 | 47 | -------------------------------------------------------------------------------- /jaclearn/logic/propositional/logic_induction/logic_induction.pxd: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : logic_induction.pxd 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/16/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | # distutils: language = c++ 12 | 13 | from libcpp.vector cimport vector 14 | from libcpp.string cimport string 15 | 16 | cdef extern from "csrc/logic_induction.h": 17 | cdef enum LogicFormType: 18 | CONJUNCTION_TYPE, DISJUNCTION_TYPE, GENERAL_TYPE 19 | 20 | cdef enum LogicFormOutputFormat: 21 | DEFAULT_FORMAT, LISP_FORMAT 22 | 23 | cdef cppclass LogicInductionConfig: 24 | LogicFormType type 25 | LogicFormOutputFormat output_format 26 | size_t nr_examples 27 | size_t nr_input_variables 28 | size_t nr_output_variables 29 | size_t depth 30 | double coverage 31 | 32 | cdef cppclass LogicInductionContext: 33 | LogicInductionConfig *config 34 | unsigned char *inputs 35 | unsigned char *outputs 36 | vector[string] input_names 37 | 38 | cdef cppclass LogicInduction: 39 | LogicInduction(LogicInductionConfig *, LogicInductionContext *) except + 40 | string search() 41 | 42 | -------------------------------------------------------------------------------- /jactorch/optim/custom_optimizer_base.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : custom_optimizer_base.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/27/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | __all__ = ['CustomizedOptimizer'] 12 | 13 | 14 | class CustomizedOptimizer(object): 15 | """Base class for all customized optimizers.""" 16 | 17 | @property 18 | def state(self): 19 | """The state of the optimizer.""" 20 | raise NotImplementedError() 21 | 22 | @property 23 | def param_groups(self): 24 | """The parameter groups of the optimizer.""" 25 | raise NotImplementedError() 26 | 27 | def state_dict(self): 28 | """A dictionary that contains the state of the optimizer.""" 29 | raise NotImplementedError() 30 | 31 | def load_state_dict(self, state_dict): 32 | """Load the state of the optimizer from a dictionary.""" 33 | raise NotImplementedError() 34 | 35 | def zero_grad(self): 36 | """Clear the gradients of all optimized parameters.""" 37 | raise NotImplementedError() 38 | 39 | def step(self, closure=None): 40 | """Performs a single optimization step.""" 41 | raise NotImplementedError() 42 | -------------------------------------------------------------------------------- /examples/torch-dataloader/syncable_dataset.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : syncable_dataset.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 08/26/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import time 12 | import threading 13 | from torch.utils.data.dataset import Dataset 14 | from jactorch.data.dataloader import JacDataLoader 15 | 16 | 17 | class SyncableDataset(Dataset): 18 | def __init__(self): 19 | self.lock = threading.Lock() 20 | self.global_index = 1 21 | 22 | def on_recv(self, data): 23 | with self.lock: 24 | self.global_index = data['global_index'] 25 | 26 | def __getitem__(self, index): 27 | time.sleep(0.6) 28 | with self.lock: 29 | return (index, self.global_index) 30 | 31 | def __len__(self): 32 | return 20 33 | 34 | 35 | def main(): 36 | dataset = SyncableDataset() 37 | dataloader = JacDataLoader(dataset, batch_size=1, shuffle=False, num_workers=2, worker_recv_fn=dataset.on_recv) 38 | 39 | for i, value in enumerate(dataloader): 40 | print(i, value) 41 | if i == 9: 42 | dataloader.send_to_worker({'global_index': 10086}) 43 | 44 | 45 | if __name__ == '__main__': 46 | main() 47 | -------------------------------------------------------------------------------- /docs/source/jactorch.vision.rst: -------------------------------------------------------------------------------- 1 | jactorch.vision package 2 | ======================= 3 | 4 | .. automodule:: jactorch.vision 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.vision.conv module 13 | --------------------------- 14 | 15 | .. automodule:: jactorch.vision.conv 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.vision.geometry module 21 | ------------------------------- 22 | 23 | .. automodule:: jactorch.vision.geometry 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.vision.gradient module 29 | ------------------------------- 30 | 31 | .. automodule:: jactorch.vision.gradient 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jactorch.vision.morphology module 37 | --------------------------------- 38 | 39 | .. automodule:: jactorch.vision.morphology 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | 44 | jactorch.vision.peak module 45 | --------------------------- 46 | 47 | .. automodule:: jactorch.vision.peak 48 | :members: 49 | :undoc-members: 50 | :show-inheritance: 51 | 52 | jactorch.vision.smooth module 53 | ----------------------------- 54 | 55 | .. automodule:: jactorch.vision.smooth 56 | :members: 57 | :undoc-members: 58 | :show-inheritance: 59 | -------------------------------------------------------------------------------- /jactorch/nn/simple.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : simple.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 07/13/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import torch 12 | import torch.nn as nn 13 | 14 | __all__ = ['Identity', 'TorchApplyRecorderMixin', 'AutoResetParametersMixin'] 15 | 16 | 17 | class Identity(nn.Module): 18 | def forward(self, *args): 19 | if len(args) == 1: 20 | return args[0] 21 | return args 22 | 23 | 24 | class TorchApplyRecorderMixin(nn.Module): 25 | def __init__(self): 26 | super().__init__() 27 | self._apply_recorder_indicator = nn.Parameter( 28 | torch.tensor(0, dtype=torch.float32, device=torch.device('cpu')) 29 | ) 30 | self._apply_recorder_indicator.requires_grad = False 31 | 32 | @property 33 | def dtype(self): 34 | return self._apply_recorder_indicator.dtype 35 | 36 | @property 37 | def device(self): 38 | return self._apply_recorder_indicator.device 39 | 40 | 41 | class AutoResetParametersMixin(object): 42 | def reset_parameters(self): 43 | for module in self.modules(): 44 | if id(module) != id(self) and hasattr(module, 'reset_parameters'): 45 | module.reset_parameters() 46 | 47 | -------------------------------------------------------------------------------- /jaclearn/rl/envs/simple/move_right.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : move_right.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/17/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import numpy as np 12 | 13 | from ...env import SimpleRLEnvBase 14 | from ...space import DiscreteActionSpace 15 | 16 | __all__ = ['MoveRightEnv'] 17 | 18 | 19 | class MoveRightEnv(SimpleRLEnvBase): 20 | def __init__(self, size=10): 21 | super().__init__() 22 | self._size = size 23 | self._pos = None 24 | 25 | def _get_action_space(self): 26 | return DiscreteActionSpace(2, ['MOVE_LEFT', 'MOVE_RIGHT']) 27 | 28 | def _get_current_state(self): 29 | assert 0 <= self._pos < self._size 30 | 31 | state = np.zeros(self._size) 32 | state[self._pos] = 1 33 | return state 34 | 35 | def _action(self, action): 36 | if action == 1: 37 | self._pos += 1 38 | reward = 1 39 | else: 40 | self._pos = max(0, self._pos - 1) 41 | reward = -1 42 | is_over = self._pos >= self._size - 1 43 | return reward, is_over 44 | 45 | def _restart(self, pos=0, *args, **kwargs): 46 | self._pos = pos 47 | 48 | def _finish(self, *args, **kwargs): 49 | pass -------------------------------------------------------------------------------- /examples/comm-broadcast-gather/gather.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : gather.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/16/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import time 12 | import multiprocessing as mp 13 | 14 | from jacinle.comm.gather import make_gather_pair 15 | from jacinle.utils.meta import map_exec_method 16 | 17 | 18 | def mainloop_pull(pipe): 19 | with pipe.activate(): 20 | while True: 21 | msg = pipe.recv() 22 | print('Received: worker_id=#{}, msg={}.'.format(msg['worker_id'], msg)) 23 | 24 | 25 | def mainloop_push(worker_id, pipe): 26 | print('Initialized: worker_id=#{}.'.format(worker_id)) 27 | with pipe.activate(): 28 | while True: 29 | msg = dict(text='Hello world!', time=time.strftime('%H:%M:%S'), worker_id=worker_id) 30 | pipe.send(msg) 31 | print('Sent: msg={}.'.format(msg)) 32 | time.sleep(1) 33 | 34 | 35 | def main(): 36 | pull, pushs = make_gather_pair('jaincle-test', nr_workers=4, mode='ipc') 37 | push_procs = [mp.Process(target=mainloop_push, args=(i, p)) for i, p in enumerate(pushs)] 38 | map_exec_method('start', push_procs) 39 | 40 | mainloop_pull(pull) 41 | 42 | 43 | if __name__ == '__main__': 44 | main() 45 | -------------------------------------------------------------------------------- /jactorch/vision/peak.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : peak.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/07/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | """ 12 | Extracting peaks from feature maps: inspired by `skimage.features.peak`. 13 | """ 14 | 15 | import torch 16 | from .smooth import maximum_smooth 17 | 18 | __all__ = ['peak_local_max'] 19 | 20 | 21 | def _get_high_intensity_peaks(is_peak, nr_peaks, feature_maps): 22 | peaks = torch.nonzero(is_peak) 23 | if nr_peaks is not None: 24 | # TODO(Jiayuan Mao @ 04/07): select the top-K peaks. 25 | raise NotImplementedError() 26 | return is_peak, peaks 27 | 28 | 29 | def peak_local_max(feature_maps, radius, exclude_border=True): 30 | if type(exclude_border) is bool: 31 | if exclude_border: 32 | exclude_border = radius 33 | else: 34 | exclude_border = 0 35 | 36 | max_fmaps = maximum_smooth(feature_maps, 2 * radius + 1) 37 | is_peak = max_fmaps == feature_maps 38 | 39 | if exclude_border > 0: 40 | is_peak[..., :exclude_border, :] = 0 41 | is_peak[..., -exclude_border:, :] = 0 42 | is_peak[..., :, :exclude_border] = 0 43 | is_peak[..., :, -exclude_border:] = 0 44 | 45 | return _get_high_intensity_peaks(is_peak, None, None) 46 | 47 | -------------------------------------------------------------------------------- /jactorch/transforms/image/functional.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : functional.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 10/29/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from PIL import Image 12 | import numpy as np 13 | 14 | from torchvision.transforms import functional as TF 15 | 16 | 17 | def pad(img, padding, mode='constant', fill=0): 18 | if isinstance(padding, int): 19 | padding = (padding, padding, padding, padding) 20 | elif len(padding) == 2: 21 | padding = (padding[0], padding[1], padding[0], padding[1]) 22 | else: 23 | assert len(padding) == 4 24 | 25 | if mode == 'constant': 26 | img_new = TF.pad(img, padding, fill=fill) 27 | else: 28 | np_padding = ((padding[1], padding[3]), (padding[0], padding[2]), (0, 0)) 29 | img_new = Image.fromarray(np.pad( 30 | np.array(img), np_padding, mode=mode 31 | )) 32 | 33 | return img_new 34 | 35 | 36 | def pad_multiple_of(img, multiple, mode='constant', fill=0): 37 | h, w = img.height, img.width 38 | hh = h - h % multiple + multiple * int(h % multiple != 0) 39 | ww = w - w % multiple + multiple * int(w % multiple != 0) 40 | if h != hh or w != ww: 41 | return pad(img, (0, 0, ww - w, hh - h), mode=mode, fill=fill) 42 | return img 43 | 44 | -------------------------------------------------------------------------------- /jaclearn/rl/algo/advantage.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : advantage.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/17/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from .math import discount_cumsum, compute_gae 12 | 13 | __all__ = ['AdvantageComputerBase', 'DiscountedAdvantageComputer', 'GAEComputer'] 14 | 15 | 16 | class AdvantageComputerBase(object): 17 | def __call__(self, data): 18 | self._compute(data) 19 | 20 | def _compute(self, data): 21 | raise NotImplementedError() 22 | 23 | 24 | class DiscountedAdvantageComputer(AdvantageComputerBase): 25 | def __init__(self, gamma): 26 | self._gamma = gamma 27 | 28 | def _compute(self, data): 29 | return_ = discount_cumsum(data['reward'], self._gamma) 30 | advantage = return_ - data['value'] 31 | 32 | data['return_'] = return_ 33 | data['advantage'] = advantage 34 | 35 | 36 | class GAEComputer(AdvantageComputerBase): 37 | def __init__(self, gamma, lambda_): 38 | self._gamma = gamma 39 | self._lambda = lambda_ 40 | 41 | def _compute(self, data): 42 | return_ = discount_cumsum(data['reward'], self._gamma) 43 | advantage = compute_gae(data['reward'], data['value'], 0, self._gamma, self._lambda) 44 | 45 | data['return_'] = return_ 46 | data['advantage'] = advantage 47 | -------------------------------------------------------------------------------- /jacinle/utils/context.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : context.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 12/31/16 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | __all__ = ['EmptyContext', 'KeyboardInterruptContext', 'SaverContext'] 12 | 13 | 14 | class EmptyContext(object): 15 | """An empty context manager that does nothing.""" 16 | 17 | def __enter__(self): 18 | return 19 | 20 | def __exit__(self, exc_type, exc_val, exc_tb): 21 | return 22 | 23 | 24 | class KeyboardInterruptContext(object): 25 | """A context manager that catches KeyboardInterrupt and does nothing.""" 26 | 27 | def __enter__(self): 28 | return 29 | 30 | def __exit__(self, exc_type, exc_val, exc_tb): 31 | if isinstance(exc_val, KeyboardInterrupt): 32 | return True 33 | 34 | 35 | class SaverContext(object): 36 | """Save some information before entering the context. Restore the information after. 37 | 38 | Inspired by: https://github.com/caelan/pybullet-planning/blob/master/pybullet_tools/utils.py 39 | """ 40 | 41 | def __enter__(self): 42 | self.save() 43 | return self 44 | 45 | def __exit__(self, exc_type, exc_val, exc_tb): 46 | self.restore() 47 | 48 | def save(self): 49 | pass 50 | 51 | def restore(self): 52 | raise NotImplementedError() 53 | 54 | -------------------------------------------------------------------------------- /jacinle/utils/value_scheduler.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : value_scheduler.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 07/18/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | __all__ = ['ValueScheduler', 'MonotonicSchedulerBase', 'LinearScheduler'] 12 | 13 | 14 | class ValueScheduler(object): 15 | """Essentially, define y = f(x), where x is a discrete, bounded variable.""" 16 | def get(self, x): 17 | raise NotImplementedError() 18 | 19 | 20 | class ConstantScheduler(ValueScheduler): 21 | def __init__(self, value): 22 | self.value = value 23 | 24 | def get(self, x): 25 | return self.value 26 | 27 | 28 | class MonotonicSchedulerBase(ValueScheduler): 29 | def __init__(self, begin, begin_value, end, end_value): 30 | super().__init__() 31 | self.begin = begin 32 | self.begin_value = begin_value 33 | self.end = end 34 | self.end_value = end_value 35 | 36 | def get(self, x): 37 | raise NotImplementedError() 38 | 39 | 40 | class LinearScheduler(MonotonicSchedulerBase): 41 | def get(self, x): 42 | if x < self.begin: 43 | return self.begin_value 44 | elif x > self.end: 45 | return self.end_value 46 | return self.begin_value + (self.end_value - self.begin_value) / (self.end - self.begin) * (x - self.begin) 47 | 48 | -------------------------------------------------------------------------------- /jactorch/data/collate/utils.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : utils.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/09/2020 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import torch 12 | from jacinle.utils.enum import JacEnum 13 | 14 | 15 | def use_shared_memory(): 16 | if torch.__version__ < '1.1': 17 | import torch.utils.data.dataloader as torchdl 18 | return torchdl._use_shared_memory 19 | elif torch.__version__ < '1.2': 20 | import torch.utils.data._utils.collate as torch_collate 21 | return torch_collate._use_shared_memory 22 | else: 23 | return torch.utils.data.get_worker_info() is not None 24 | 25 | 26 | numpy_type_map = { 27 | 'float64': torch.DoubleTensor, 28 | 'float32': torch.FloatTensor, 29 | 'float16': torch.HalfTensor, 30 | 'int64': torch.LongTensor, 31 | 'int32': torch.IntTensor, 32 | 'int16': torch.ShortTensor, 33 | 'int8': torch.CharTensor, 34 | 'uint8': torch.ByteTensor, 35 | } 36 | 37 | 38 | def user_scattered_collate(batch): 39 | """ 40 | A helper function indicating that no collation needs to be done. 41 | """ 42 | return batch 43 | 44 | 45 | class VarLengthCollateMode(JacEnum): 46 | SKIP = 'skip' 47 | CONCAT = 'concat' 48 | PAD = 'pad' 49 | PAD2D = 'pad2d' 50 | PADIMAGE = 'padimage' 51 | STACK = 'stack' 52 | 53 | -------------------------------------------------------------------------------- /jacinle/comm/distrib/_configs.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : _configs.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/22/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | NS_CTL_PROTOCAL = 'tcp' 12 | NS_CTL_HOST = '*' 13 | NS_CTL_PORT = '43521' 14 | NS_HEARTBEAT_INTERVAL = 3 15 | NS_CLEANUP_WAIT = 10 16 | 17 | CTL_CTL_SND_COUNTDOWN = 5 18 | CTL_CTL_HWM = 5 19 | CTL_DAT_SND_COUNTDOWN = 5 20 | CTL_DAT_HWM = 5 21 | 22 | CTL_DAT_PROTOCAL = 'tcp' 23 | CTL_DAT_HOST = '*' 24 | 25 | 26 | class Actions: 27 | NS_REGISTER_CTL_REQ = 'ns-register-ctl-req' 28 | NS_REGISTER_CTL_REP = 'ns-register-ctl-rep' 29 | 30 | NS_REGISTER_OUTPUTS_REQ = 'ns-register-outputs-req' 31 | NS_REGISTER_OUTPUTS_REP = 'ns-register-outputs-rep' 32 | 33 | NS_HEARTBEAT_REQ = 'ns-heartbeat-req' 34 | NS_HEARTBEAT_REP = 'ns-heartbeat-rep' 35 | 36 | NS_REGISTER_INPUTS_REQ = 'ns-register-inputs-req' 37 | NS_REGISTER_INPUTS_REP = 'ns-register-inputs-rep' 38 | 39 | NS_NOTIFY_OPEN_REQ = 'ctl-notify-open-req' 40 | NS_NOTIFY_OPEN_REP = 'ctl-notify-open-rep' 41 | 42 | NS_NOTIFY_CLOSE_REQ = 'ctl-notify-close-req' 43 | NS_NOTIFY_CLOSE_REP = 'ctl-notify-close-rep' 44 | 45 | CTL_CONNECT_REQ = 'ctl-connect-req' 46 | CTL_CONNECT_REP = 'ctl-connect-rep' 47 | 48 | CTL_CONNECTED_REQ = 'ctl-connected-req' 49 | CTL_CONNECTED_REP = 'ctl-connected-rep' 50 | -------------------------------------------------------------------------------- /jactorch/nn/gumbel_softmax/softmax.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : softmax.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/01/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import torch.nn as nn 12 | 13 | from .functional import gumbel_softmax, greedy_softmax, general_softmax, SoftmaxImplmentation 14 | 15 | __all__ = ['SoftmaxImplmentation', 'GumbelSoftmax', 'GeneralSoftmax'] 16 | 17 | 18 | class GumbelSoftmax(nn.Module): 19 | def __init__(self, dim=-1, tau=1.0, hard=False, eps=1e-10): 20 | super().__init__() 21 | self.dim = dim 22 | self.tau = tau 23 | self.hard = hard 24 | self.eps = eps 25 | 26 | def forward(self, logits, mask=None): 27 | if self.training: 28 | return gumbel_softmax(logits, dim=self.dim, tau=self.tau, hard=self.hard, mask=mask, eps=self.eps) 29 | else: 30 | return greedy_softmax(logits, dim=self.dim, mask=mask) 31 | 32 | 33 | class GeneralSoftmax(nn.Module): 34 | def __init__(self, dim=-1, tau=1.0, impl='standard'): 35 | super().__init__() 36 | self.dim = dim 37 | self.tau = tau 38 | self.impl = SoftmaxImplmentation.from_string(impl) 39 | 40 | def forward(self, logits, mask=None): 41 | return general_softmax(logits, dim=self.dim, tau=self.tau, impl=self.impl, mask=mask, training=self.training) 42 | 43 | -------------------------------------------------------------------------------- /examples/html-table/gen.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : gen.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 05/05/2021 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import imageio 12 | from PIL import Image 13 | from jaclearn.visualize.html_table import HTMLTableColumnDesc, HTMLTableVisualizer 14 | 15 | a = Image.fromarray(imageio.imread('imageio:chelsea.png')) 16 | b = Image.fromarray(imageio.imread('imageio:astronaut.png')) 17 | 18 | 19 | vis = HTMLTableVisualizer('generated', 'Visualization') 20 | with vis.html(): 21 | with vis.table('Table Name', [ 22 | HTMLTableColumnDesc(identifier='column1', name='ID', type='code'), 23 | HTMLTableColumnDesc(identifier='column2', name='Image', type='image'), 24 | HTMLTableColumnDesc(identifier='column3', name='Frames (Image)', type='frames'), 25 | HTMLTableColumnDesc(identifier='column4', name='Frames (Text)', type='frames'), 26 | HTMLTableColumnDesc(identifier='column5', name='Additional Information', type='code') 27 | ]): 28 | vis.row(column1=1, column2=a, column3=[ 29 | {'image': a, 'info': 'imageio:chelsea.png'}, 30 | {'image': b, 'info': 'imageio:astronaut.png'}, 31 | ], column4=[ 32 | {'text': '12345', 'info': 'text info 1'}, 33 | {'text': '67890', 'info': 'text info 2'}, 34 | ], column5='Some string') 35 | 36 | 37 | -------------------------------------------------------------------------------- /examples/comm-broadcast-gather/broadcast.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : broadcast.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 02/16/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import time 12 | import multiprocessing as mp 13 | 14 | from jacinle.comm.broadcast import make_broadcast_pair 15 | from jacinle.utils.meta import map_exec_method 16 | 17 | 18 | def mainloop_push(pipe): 19 | with pipe.activate(): 20 | while True: 21 | msg = dict(text='Hello world!', time=time.strftime('%H:%M:%S')) 22 | pipe.send(msg) 23 | print('Sent: msg={}.'.format(msg)) 24 | time.sleep(1) 25 | 26 | 27 | def mainloop_pull(worker_id, pipe): 28 | print('Initialized: worker_id=#{}.'.format(worker_id)) 29 | try: 30 | with pipe.activate(): 31 | while True: 32 | msg = pipe.recv() 33 | print('Received: worker_id=#{}, msg={}.'.format(worker_id, msg)) 34 | except: 35 | import traceback 36 | traceback.print_exc() 37 | raise 38 | 39 | 40 | def main(): 41 | push, pulls = make_broadcast_pair('jaincle-test', nr_workers=1, mode='ipc') 42 | pull_procs = [mp.Process(target=mainloop_pull, args=(i, p)) for i, p in enumerate(pulls)] 43 | map_exec_method('start', pull_procs) 44 | 45 | mainloop_push(push) 46 | 47 | 48 | if __name__ == '__main__': 49 | main() 50 | -------------------------------------------------------------------------------- /examples/web-starter/main.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : main.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 10/23/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.logging import get_logger 12 | from jacinle.web.app import make_app 13 | 14 | import tornado.ioloop 15 | 16 | logger = get_logger(__file__) 17 | 18 | 19 | def main(): 20 | app = make_app([ 21 | 'app.index' 22 | ], { 23 | 'gzip': True, 24 | 'debug': False, 25 | 'xsrf_cookies': True, 26 | 27 | 'static_path': 'static', 28 | 'template_path': 'app/templates', 29 | 30 | "cookie_secret": "20f42d0ae6548e88cf9788e725b298bd", 31 | "session_secret": "3cdcb1f00803b6e78ab50b466a40b9977db396840c28307f428b25e2277f1bcc", 32 | "frontend_secret": "asdjikfh98234uf9pidwja09f9adsjp9fd6840c28307f428b25e2277f1bcc", 33 | 34 | "cookie_prefix": 'jac_', 35 | 36 | # 'session_engine': 'off', 37 | 'session_engine': 'in-memory', 38 | # 'session_engine': 'memcached', 39 | "session_timeout": 60 * 30, 40 | 41 | "memcached_host": "127.0.0.1", 42 | "memcached_port": "11211", 43 | }) 44 | app.listen(8081, xheaders=True) 45 | 46 | logger.critical('Mainloop started.') 47 | loop = tornado.ioloop.IOLoop.current() 48 | loop.start() 49 | 50 | 51 | if __name__ == '__main__': 52 | main() 53 | 54 | -------------------------------------------------------------------------------- /docs/source/jactorch.parallel.rst: -------------------------------------------------------------------------------- 1 | jactorch.parallel package 2 | ========================= 3 | 4 | .. automodule:: jactorch.parallel 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | 9 | Submodules 10 | ---------- 11 | 12 | jactorch.parallel.comm module 13 | ----------------------------- 14 | 15 | .. automodule:: jactorch.parallel.comm 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | jactorch.parallel.data\_parallel module 21 | --------------------------------------- 22 | 23 | .. automodule:: jactorch.parallel.data_parallel 24 | :members: 25 | :undoc-members: 26 | :show-inheritance: 27 | 28 | jactorch.parallel.dict\_gather module 29 | ------------------------------------- 30 | 31 | .. automodule:: jactorch.parallel.dict_gather 32 | :members: 33 | :undoc-members: 34 | :show-inheritance: 35 | 36 | jactorch.parallel.replicate module 37 | ---------------------------------- 38 | 39 | .. automodule:: jactorch.parallel.replicate 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | 44 | jactorch.parallel.replication\_callback module 45 | ---------------------------------------------- 46 | 47 | .. automodule:: jactorch.parallel.replication_callback 48 | :members: 49 | :undoc-members: 50 | :show-inheritance: 51 | 52 | jactorch.parallel.user\_scattered module 53 | ---------------------------------------- 54 | 55 | .. automodule:: jactorch.parallel.user_scattered 56 | :members: 57 | :undoc-members: 58 | :show-inheritance: 59 | -------------------------------------------------------------------------------- /jacinle/utils/vendor.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : vendor.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 05/25/2019 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import importlib 12 | import functools 13 | from jacinle.logging import get_logger 14 | 15 | logger = get_logger(__file__) 16 | 17 | __all__ = ['has_vendor', 'requires_vendors'] 18 | 19 | 20 | def has_vendor(vendor): 21 | """Check if the module is available.""" 22 | try: 23 | importlib.import_module(vendor) 24 | except ImportError as e: 25 | return False 26 | return True 27 | 28 | 29 | def requires_vendors(*vendors): 30 | """Decorator to check if the module is available. If not, raises an error when the function is called.""" 31 | def wrapper(func): 32 | checked_vendors = False 33 | 34 | @functools.wraps(func) 35 | def wrapped(*args, **kwargs): 36 | nonlocal checked_vendors 37 | if not checked_vendors: 38 | for v in vendors: 39 | try: 40 | importlib.import_module(v) 41 | except ImportError as e: 42 | raise ImportError('Cannot import {}. Make sure you have it as a vendor for Jacinle.'.format(v)) from e 43 | checked_vendors = True 44 | 45 | return func(*args, **kwargs) 46 | 47 | return wrapped 48 | return wrapper 49 | 50 | -------------------------------------------------------------------------------- /jactorch/cuda/copy.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : copy.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/24/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import collections 12 | 13 | import torch 14 | 15 | __all__ = ['async_copy_to'] 16 | 17 | 18 | def async_copy_to(obj, dev, main_stream=None): 19 | """ 20 | Copy an object to a specific device asynchronizedly. If the param `main_stream` is provided, 21 | the copy stream will be synchronized with the main one. 22 | 23 | Args: 24 | obj (Iterable[Tensor] or Tensor): a structure (e.g., a list or a dict) containing pytorch tensors. 25 | dev (int): the target device. 26 | main_stream (stream): the main stream to be synchronized. 27 | 28 | Returns: 29 | a deep copy of the data structure, with each tensor copied to the device. 30 | 31 | """ 32 | # Adapted from: https://github.com/pytorch/pytorch/blob/master/torch/nn/parallel/_functions.py 33 | if torch.is_tensor(obj): 34 | v = obj.cuda(dev, non_blocking=True) 35 | if main_stream is not None: 36 | v.record_stream(main_stream) 37 | return v 38 | elif isinstance(obj, collections.abc.Mapping): 39 | return {k: async_copy_to(o, dev, main_stream) for k, o in obj.items()} 40 | elif isinstance(obj, (tuple, list)): 41 | return [async_copy_to(o, dev, main_stream) for o in obj] 42 | else: 43 | return obj 44 | -------------------------------------------------------------------------------- /jactorch/train/utils.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : utils.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 03/03/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.utils.deprecated import deprecated 12 | from jactorch.graph.parameter import mark_freezed as gmark_freezed, mark_unfreezed as gmark_unfreezed 13 | 14 | __all__ = ['mark_freezed', 'mark_unfreezed', 'set_learning_rate', 'decay_learning_rate'] 15 | 16 | 17 | @deprecated 18 | def mark_freezed(model): 19 | """DEPRECATED(Jiayuan Mao): jactorch.train.utils.mark_freezed has been deprecated and will be removed by 07/16/2022; 20 | please use jactorch.graph.parameter.mark_freezed instead.""" 21 | return gmark_freezed(model) 22 | 23 | 24 | @deprecated 25 | def mark_unfreezed(model): 26 | """DEPRECATED(Jiayuan Mao): jactorch.train.utils.mark_unfreezed has been deprecated and will be removed by 07/16/2022; 27 | please use jactorch.graph.parameter.mark_unfreezed instead.""" 28 | return gmark_unfreezed(model) 29 | 30 | 31 | def set_learning_rate(optimizer, lr: float): 32 | """Set the learning rate of the optimizer.""" 33 | for param_group in optimizer.param_groups: 34 | param_group['lr'] = lr 35 | 36 | 37 | def decay_learning_rate(optimizer, decay: float): 38 | """Decay the learning rate of the optimizer by a factor of decay.""" 39 | for param_group in optimizer.param_groups: 40 | param_group['lr'] *= decay 41 | 42 | -------------------------------------------------------------------------------- /jaclearn/rl/simulator/pack.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : pack.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 04/23/2017 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | from jacinle.utils.imp import module_vars_as_dict 12 | 13 | 14 | class Pack(object): 15 | def __init__(self, cfg=None): 16 | self.cfg = cfg 17 | self.steps = [] 18 | self.is_ended = False 19 | 20 | self.__last_observation = None 21 | 22 | def reset(self, observation): 23 | self.__last_observation = observation 24 | 25 | def step(self, action, observation, reward, done, info=None): 26 | assert not self.is_ended 27 | 28 | last_observation = self.__last_observation 29 | 30 | if done: 31 | self.is_ended = True 32 | self.__last_observation = None 33 | else: 34 | self.__last_observation = observation 35 | 36 | record = dict( 37 | action=action, 38 | observation=last_observation, 39 | reward=reward, 40 | info=info) 41 | self.steps.append(record) 42 | 43 | if done: 44 | record = dict(action=None, observation=observation, reward=None, info=None) 45 | self.steps.append(record) 46 | 47 | def make_pickleable(self): 48 | return dict( 49 | cfg=module_vars_as_dict(self.cfg) if self.cfg is not None else None, 50 | steps=self.steps, 51 | is_ended=self.is_ended 52 | ) 53 | -------------------------------------------------------------------------------- /jacinle/storage/unsafe_queue.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : unsafe_queue.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 08/17/2024 7 | # 8 | # This file is part of Project Concepts. 9 | # Distributed under terms of the MIT license. 10 | 11 | import collections 12 | import heapq 13 | import itertools 14 | 15 | 16 | class Queue(object): 17 | """A simple queue implementation based on collections.deque.""" 18 | 19 | def __init__(self): 20 | self._queue = collections.deque() 21 | 22 | @property 23 | def size(self): 24 | return len(self._queue) 25 | 26 | @property 27 | def queue(self) -> collections.deque: 28 | return self._queue 29 | 30 | def put(self, item): 31 | self._queue.append(item) 32 | 33 | def get(self): 34 | return self._queue.popleft() 35 | 36 | def peek(self): 37 | return self._queue[0] 38 | 39 | def empty(self): 40 | return len(self._queue) == 0 41 | 42 | 43 | PRIORITY_QUEUE_ITEM_COUNTER = itertools.count() 44 | 45 | 46 | class PriorityQueue(object): 47 | """A simple priority queue implementation based on heapq.""" 48 | 49 | def __init__(self): 50 | self._queue = [] 51 | 52 | def put(self, item, priority): 53 | heapq.heappush(self._queue, (priority, next(PRIORITY_QUEUE_ITEM_COUNTER), item)) 54 | 55 | def get(self): 56 | return heapq.heappop(self._queue)[2] 57 | 58 | def peek(self): 59 | return self._queue[0][2] 60 | 61 | def empty(self): 62 | return len(self._queue) == 0 63 | -------------------------------------------------------------------------------- /jacinle/concurrency/queue.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : queue.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import queue 12 | import heapq 13 | 14 | __all__ = ['ListToFill', 'iter_queue', 'sorted_iter'] 15 | 16 | 17 | class ListToFill(list): 18 | def __init__(self, nr_target): 19 | super().__init__() 20 | self._nr_target = nr_target 21 | 22 | def append(self, *args, **kwargs): 23 | super().append(*args, **kwargs) 24 | if len(self) >= self._nr_target: 25 | raise queue.Full() 26 | 27 | 28 | def iter_queue(q, total=None): 29 | if total is None: 30 | while True: 31 | yield q.get() 32 | else: 33 | for i in range(total): 34 | yield q.get() 35 | 36 | 37 | def sorted_iter(iter, id_func=None): 38 | if id_func is None: 39 | id_func = lambda x: x[0] 40 | 41 | current = -1 42 | buffer = [] 43 | for i, v in enumerate(iter): 44 | if v is None: 45 | assert len(buffer) == 0, 'Buffer is not empty when receiving stop signal.' 46 | break 47 | 48 | idv = id_func(v) 49 | if idv == current + 1: 50 | yield idv, v 51 | current += 1 52 | while len(buffer) and id_func(buffer[0]) == current + 1: 53 | ele = heapq.heappop(buffer) 54 | yield ele[0], ele[2] 55 | current += 1 56 | else: 57 | heapq.heappush(buffer, (idv, i, v)) 58 | -------------------------------------------------------------------------------- /jaclearn/datasets/image_classification/svhn.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # File : svhn.py 4 | # Author : Jiayuan Mao 5 | # Email : maojiayuan@gmail.com 6 | # Date : 01/19/2018 7 | # 8 | # This file is part of Jacinle. 9 | # Distributed under terms of the MIT license. 10 | 11 | import os 12 | 13 | import numpy as np 14 | 15 | from jacinle.io.network import download 16 | 17 | __all__ = ['load_svhn'] 18 | 19 | 20 | svhn_web_address = { 21 | 'train': ["http://ufldl.stanford.edu/housenumbers/train_32x32.mat", 22 | "train_32x32.mat", "e26dedcc434d2e4c54c9b2d4a06d8373"], 23 | 'test': ["http://ufldl.stanford.edu/housenumbers/test_32x32.mat", 24 | "test_32x32.mat", "eb5a983be6a315427106f1b164d9cef3"], 25 | 'extra': ["http://ufldl.stanford.edu/housenumbers/extra_32x32.mat", 26 | "extra_32x32.mat", "a93ce644f1a588dc4d68dda5feec44a7"] 27 | } 28 | 29 | 30 | def load_svhn(data_dir, extra=False): 31 | from scipy.io import loadmat 32 | 33 | all_set_keys = list(svhn_web_address.keys()) 34 | if not extra: 35 | all_set_keys = all_set_keys[:2] 36 | 37 | all_sets = [] 38 | 39 | for subset in all_set_keys: 40 | data_addr, data_file, data_hash = svhn_web_address[subset] 41 | 42 | dataset = os.path.join(data_dir, data_file) 43 | 44 | if not os.path.isfile(dataset): 45 | download(data_addr, data_dir, data_file, md5=data_hash) 46 | 47 | mat = loadmat(dataset) 48 | mat['X'] = np.transpose(mat['X'], [3, 0, 1, 2]) 49 | all_sets.append((np.ascontiguousarray(mat['X']), mat['y'])) 50 | 51 | return tuple(all_sets) 52 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendors/pytorch_reservoir/torch_sampling"] 2 | path = vendors/pytorch_reservoir/torch_sampling 3 | url = https://github.com/LeviViana/torch_sampling 4 | [submodule "vendors/AdvancedIndexing-PyTorch"] 5 | path = vendors/AdvancedIndexing-PyTorch 6 | url = https://github.com/vacancy/AdvancedIndexing-PyTorch 7 | [submodule "vendors/SceneGraphParser"] 8 | path = vendors/SceneGraphParser 9 | url = https://github.com/vacancy/SceneGraphParser 10 | [submodule "vendors/Synchronized-BatchNorm-PyTorch"] 11 | path = vendors/Synchronized-BatchNorm-PyTorch 12 | url = https://github.com/vacancy/Synchronized-BatchNorm-PyTorch 13 | [submodule "vendors/PreciseRoIPooling"] 14 | path = vendors/PreciseRoIPooling 15 | url = https://github.com/vacancy/PreciseRoIPooling 16 | [submodule "vendors/JacMLDash"] 17 | path = vendors/JacMLDash 18 | url = https://github.com/vacancy/JacMLDash 19 | [submodule "vendors/pygco/pygco"] 20 | path = vendors/PyGCO/pygco 21 | url = https://github.com/vacancy/pygco 22 | [submodule "vendors/PyPatchMatch"] 23 | path = vendors/PyPatchMatch 24 | url = https://github.com/vacancy/PyPatchMatch 25 | [submodule "vendors/PyGCO/pygco_inpaint"] 26 | path = vendors/PyGCO/pygco_inpaint 27 | url = https://github.com/vacancy/gco_python 28 | [submodule "vendors/pytorch_scatter"] 29 | path = vendors/pytorch_scatter 30 | url = https://github.com/rusty1s/pytorch_scatter 31 | [submodule "vendors/pytorch_kmeans/kmeans_pytorch"] 32 | path = vendors/pytorch_kmeans/kmeans_pytorch 33 | url = https://github.com/subhadarship/kmeans_pytorch 34 | [submodule "vendors/pytorch_einshape/einshape"] 35 | path = vendors/pytorch_einshape/einshape 36 | url = https://github.com/vacancy/einshape 37 | --------------------------------------------------------------------------------