Nest - A flexible tool for building and sharing deep learning modules

Overview

Nest - A flexible tool for building and sharing deep learning modules

Nest is a flexible deep learning module manager, which aims at encouraging code reuse and sharing. It ships with a bunch of useful features, such as CLI based module management, runtime checking, and experimental task runner, etc. You can integrate Nest with PyTorch, Tensorflow, MXNet, or any deep learning framework you like that provides a python interface.

Moreover, a set of Pytorch-backend Nest modules, e.g., network trainer, data loader, optimizer, dataset, visdom logging, are already provided. More modules and framework support will be added later.


Prerequisites

  • System (tested on Ubuntu 14.04LTS, Win10, and MacOS High Sierra)
  • Python >= 3.5.4
  • Git

Installation

# directly install via pip
pip install git+https://github.com/ZhouYanzhao/Nest.git

# manually download and install
git clone https://github.com/ZhouYanzhao/Nest.git
pip install ./Nest

Basic Usage

The official website and documentation are under construction.

Create your first Nest module

  1. Create "hello.py" under your current path with the following content:

    from nest import register
    
    @register(author='Yanzhao', version='1.0.0')
    def hello_nest(name: str) -> str:
        """My first Nest module!"""
    
        return 'Hello ' + name

    Note that the type of module parameters and return values must be clearly defined. This helps the user to better understand the module, and at runtime Nest automatically checks whether each module receives and outputs as expected, thus helping you to identify potential bugs earlier.

  2. Execute the following command in your shell to verify the module:

    str # Documentation: # My first Nest module! # author: Yanzhao # module_path: /Users/yanzhao/Workspace/Nest.doc # version: 1.0.0 ">
    $ nest module list -v
    # Output:
    # 
    # 1 Nest module found.
    # [0] main.hello_nest (1.0.0) by "Yanzhao":
    #     hello_nest(
    #         name:str) -> str
    
    # Documentation:
    #     My first Nest module!
    #     author: Yanzhao
    #     module_path: /Users/yanzhao/Workspace/Nest.doc
    #     version: 1.0.0 

    Note that all modules under current path are registered under the "main" namespace.

    With the CLI tool, you can easily manage Nest modules. Execute nest -h for more details.

  3. That's it. You just created a simple Nest module!

Use your Nest module in Python

  1. Open an interactive python interpreter under the same path of "hello.py" and run following commands:

    >> modules.hello_nest('Yanzhao', wrong=True) # Output: # # Unexpected param(s) "wrong" for Nest module: # hello_nest( # name:str) -> str ">
    >>> from nest import modules
    >>> print(modules.hello_nest) # access the module
    # Output:
    # 
    # hello_nest(
    # name:str) -> str
    >>> print(modules['*_nes?']) # wildcard search
    # Output:
    # 
    # hello_nest(
    # name:str) -> str
    >>> print(modules['r/main.\w+_nest']) # regex search
    # Output:
    # 
    # hello_nest(
    # name:str) -> str
    >>> modules.hello_nest('Yanzhao') # use the module
    # Output:
    #
    # 'Hello Yanzhao'
    >>> modules.hello_nest(123) # runtime type checking
    # Output:
    #
    # TypeError: The param "name" of Nest module "hello_nest" should be type of "str". Got "123".
    >>> modules.hello_nest('Yanzhao', wrong=True)
    # Output:
    #
    # Unexpected param(s) "wrong" for Nest module:
    # hello_nest(
    # name:str) -> str

    Note that Nest automatically imports modules and checks them as they are used to make sure everything is as expected.

  2. You can also directly import modules like this:

    >>> from nest.main.hello import hello_nest
    >>> hello_nest('World')
    # Output:
    #
    # 'Hello World'

    The import syntax is from nest. . import

  3. Access to Nest modules through code is flexible and easy.

Debug your Nest modules

  1. Open an interactive python interpreter under the same path of "hello.py" and run following commands:

    >>> from nest import modules
    >>> modules.hello_nest('Yanzhao')
    # Output:
    #
    # 'Hello Yanzhao'
  2. Keep the interpreter OPEN and use an externel editor to modify the "hello.py":

    # change Line7 from "return 'Hello ' + name" to
    return 'Nice to meet you, ' + name
  3. Back to the interpreter and rerun the same command:

    >>> modules.hello_nest('Yanzhao')
    # Output:
    #
    # 'Nice to meet you, Yanzhao'

    Note that Nest detects source file modifications and automatically reloads the module.

  4. You can use this feature to develop and debug your Nest modules efficiently.

Install Nest modules from local path

  1. Create a folder my_namespace and move the hello.py into it:

    $ mkdir my_namespace
    $ mv hello.py ./my_namespace/
  2. Create a new file more.py under the folder my_namespace with the following content:

    float: """Multiply two numbers.""" return a * b ">
    from nest import register
    
    @register(author='Yanzhao', version='1.0.0')
    def sum(a: int, b: int) -> int:
        """Sum two numbers."""
    
        return a + b
    
    # There is no need to repeatedly declare meta information
    # as modules within the same file automatically reuse the 
    # previous information. But overriding is also supported.
    @register(version='2.0.0')
    def mul(a: float, b: float) -> float:
        """Multiply two numbers."""
        
        return a * b

    Now we have:

    current path/
    ├── my_namespace/
    │   ├── hello.py
    │   ├── more.py
    
  3. Run the following command in the shell:

    Search paths. Continue? (Y/n) [Press ] ">
    $ nest module install ./my_namespace hello_word
    # Output:
    #
    # Install "./my_namespace/" -> Search paths. Continue? (Y/n) [Press 
          
           ]
          

    This command will add "my_namespace" folder to Nest's search path, and register all Nest modules in it under the namespace "hello_word". If the last argument is omitted, the directory name, "my_namespace" in this case, is used as the namespace.

  4. Verify the installation via CLI:

    $ nest module list
    # Output:
    #
    # 3 Nest modules found.
    # [0] hello_world.hello_nest (1.0.0)
    # [1] hello_world.mul (2.0.0)
    # [2] hello_world.sum (1.0.0)

    Note that those Nest modules can now be accessed regardless of your working path.

  5. Verify the installation via Python interpreter:

    $ ipython # open IPython interpreter
    >>> from nest import modules
    >>> print(len(modules))
    # Output:
    #
    # 3
    >>> modules.[Press <Tab>] # IPython Auto-completion
    # Output:
    #
    # hello_nest
    # mul
    # sum
    >>> modules.sum(3, 2)
    # Output:
    #
    # 5
    >>> modules.mul(2.5, 4.0)
    # Output:
    #
    # 10.0
  6. Thanks to the auto-import feature of Nest, you can easily share modules between different local projects.

Install Nest modules from URL

  1. You can use the CLI tool to install modules from URL:

    # select one of the following commands to execute
    # 0. install from Github repo via short URL (GitLab, Bitbucket are also supported)
    $ nest module install [email protected]/Nest:pytorch pytorch
    # 1. install from Git repo
    $ nest module install "-b pytorch https://github.com/ZhouYanzhao/Nest.git" pytorch
    # 2. install from zip file URL
    $ nest module install "https://github.com/ZhouYanzhao/Nest/archive/pytorch.zip" pytorch

    The last optional argument is used to specify the namespace, "pytorch" in this case.

  2. Verify the installation:

    $ nest module list
    # Output:
    #
    # 26 Nest modules found.
    # [0] hello_world.hello_nest (1.0.0)
    # [1] hello_world.mul (2.0.0)
    # [2] hello_world.sum (1.0.0)
    # [3] pytorch.adadelta_optimizer (0.1.0)
    # [4] pytorch.checkpoint (0.1.0)
    # [5] pytorch.cross_entropy_loss (0.1.0)
    # [6] pytorch.fetch_data (0.1.0)
    # [7] pytorch.finetune (0.1.0)
    # [8] pytorch.image_transform (0.1.0)
    # ...

Uninstall Nest modules

  1. You can remove modules from Nest's search path by executing:

    # given namespace
    $ nest module remove hello_world
    # given path to the namespace
    $ nest module remove ./my_namespace/
  2. You can also delete the corresponding files by appending a --delete or -d flag:

    $ nest module remove hello_world --delete

Version control Nest modules

  1. When installing modules, Nest adds the namespace to its search path without modifying or moving the original files. So you can use any version control system you like, e.g., Git, to manage modules. For example:

    $ cd <path of the namespace>
    # update modules
    $ git pull
    # specify version
    $ git checkout v1.0
  2. When developing a Nest module, it is recommended to define meta information for the module, such as the author, version, requirements, etc. Those information will be used by Nest's CLI tool. There are two ways to set meta information:

    • define meta information in code
    from nest import register
    
    @register(author='Yanzhao', version='1.0')
    def my_module() -> None:
        """My Module"""
        pass
    • define meta information in a nest.yml under the path of namespace
    author: Yanzhao
    version: 1.0
    requirements:
        - {url: opencv, tool: conda}
        # default tool is pip
        - torch>=0.4

    Note that you can use both ways at the same time.

Use Nest to manage your experiments

  1. Make sure you have Pytorch-backend modules installed, and if not, execute the following command:

    $ nest module install [email protected]/Nest:pytorch pytorch
  2. Create "train_mnist.yml" with the following content:

    _name: network_trainer
    data_loaders:
      _name: fetch_data
      dataset: 
        _name: mnist
        data_dir: ./data
      batch_size: 128
      num_workers: 4
      transform:
        _name: image_transform
        image_size: 28
        mean: [0.1307]
        std: [0.3081]
      train_splits: [train]
      test_splits: [test]
    model:
      _name: lenet5
    criterion:
      _name: cross_entropy_loss
    optimizer:
      _name: adadelta_optimizer
    meters:
      top1:
        _name: topk_meter
        k: 1
    max_epoch: 10
    device: cpu
    hooks:
      on_end_epoch: 
        - 
          _name: print_state
          formats:
            - 'epoch: {epoch_idx}'
            - 'train_acc: {metrics[train_top1]:.1f}%'
            - 'test_acc: {metrics[test_top1]:.1f}%'   

    Check HERE for more comprehensive demos.

  3. Run your experiments through CLI:

    $ nest task run ./train_mnist.yml
  4. You can also use Nest's task runner in your code:

    >>> from nest import run_tasks
    >>> run_tasks('./train_mnist.yml')
  5. Based on the task runner feature, Nest modules can be flexibly replaced and assembled to create your desired experiment settings.

Contact

Yanzhao Zhou

Issues

Feel free to submit bug reports and feature requests.

Contribution

Pull requests are welcome.

License

MIT

Copyright © 2018-present, Yanzhao Zhou

Owner
ZhouYanzhao
ZhouYanzhao
PocketNet: Extreme Lightweight Face Recognition Network using Neural Architecture Search and Multi-Step Knowledge Distillation

PocketNet This is the official repository of the paper: PocketNet: Extreme Lightweight Face Recognition Network using Neural Architecture Search and M

Fadi Boutros 40 Dec 22, 2022
Research shows Google collects 20x more data from Android than Apple collects from iOS. Block this non-consensual telemetry using pihole blocklists.

pihole-antitelemetry Research shows Google collects 20x more data from Android than Apple collects from iOS. Block both using these pihole lists. Proj

Adrian Edwards 290 Jan 09, 2023
Visual Question Answering in Pytorch

Visual Question Answering in pytorch /!\ New version of pytorch for VQA available here: https://github.com/Cadene/block.bootstrap.pytorch This repo wa

Remi 672 Jan 01, 2023
Code for the ICASSP-2021 paper: Continuous Speech Separation with Conformer.

Continuous Speech Separation with Conformer Introduction We examine the use of the Conformer architecture for continuous speech separation. Conformer

Sanyuan Chen (陈三元) 81 Nov 28, 2022
Convolutional Neural Network for Text Classification in Tensorflow

This code belongs to the "Implementing a CNN for Text Classification in Tensorflow" blog post. It is slightly simplified implementation of Kim's Convo

Denny Britz 5.5k Jan 02, 2023
a curated list of docker-compose files prepared for testing data engineering tools, databases and open source libraries.

data-services A repository for storing various Data Engineering docker-compose files in one place. How to use it ? Set the required settings in .env f

BigData.IR 525 Dec 03, 2022
G-NIA model from "Single Node Injection Attack against Graph Neural Networks" (CIKM 2021)

Single Node Injection Attack against Graph Neural Networks This repository is our Pytorch implementation of our paper: Single Node Injection Attack ag

Shuchang Tao 18 Nov 21, 2022
An open-source Deep Learning Engine for Healthcare that aims to treat & prevent major diseases

AlphaCare Background AlphaCare is a work-in-progress, open-source Deep Learning Engine for Healthcare that aims to treat and prevent major diseases. T

Siraj Raval 44 Nov 05, 2022
Using Language Model to Bootstrap Human Activity Recognition Ambient Sensors Based in Smart Homes

Using Language Model to Bootstrap Human Activity Recognition Ambient Sensors Based in Smart Homes This repository is the official implementation of Us

Damien Bouchabou 0 Oct 18, 2021
PyTorch Implement of Context Encoders: Feature Learning by Inpainting

Context Encoders: Feature Learning by Inpainting This is the Pytorch implement of CVPR 2016 paper on Context Encoders 1) Semantic Inpainting Demo Inst

321 Dec 25, 2022
[ICCV'21] Pri3D: Can 3D Priors Help 2D Representation Learning?

Pri3D: Can 3D Priors Help 2D Representation Learning? [ICCV 2021] Pri3D leverages 3D priors for downstream 2D image understanding tasks: during pre-tr

Ji Hou 124 Jan 06, 2023
A simple python stock Predictor

Python Stock Predictor A simple python stock Predictor Demo Run Locally Clone the project git clone https://github.com/yashraj-n/stock-price-predict

Yashraj narke 5 Nov 29, 2021
Example of semantic segmentation in Keras

keras-semantic-segmentation-example Example of semantic segmentation in Keras Single class example: Generated data: random ellipse with random color o

53 Mar 23, 2022
Official code repository of the paper Learning Associative Inference Using Fast Weight Memory by Schlag et al.

Learning Associative Inference Using Fast Weight Memory This repository contains the offical code for the paper Learning Associative Inference Using F

Imanol Schlag 18 Oct 12, 2022
The story of Chicken for Club Bing

Chicken Story tl;dr: The time when Microsoft banned my entire country for cheating at Club Bing. (A lot of the details are from memory so I've recreat

Eyal 142 May 16, 2022
Group R-CNN for Point-based Weakly Semi-supervised Object Detection (CVPR2022)

Group R-CNN for Point-based Weakly Semi-supervised Object Detection (CVPR2022) By Shilong Zhang*, Zhuoran Yu*, Liyang Liu*, Xinjiang Wang, Aojun Zhou,

Shilong Zhang 129 Dec 24, 2022
The codes and related files to reproduce the results for Image Similarity Challenge Track 2.

ISC-Track2-Submission The codes and related files to reproduce the results for Image Similarity Challenge Track 2. Required dependencies To begin with

Wenhao Wang 89 Jan 02, 2023
GeoMol: Torsional Geometric Generation of Molecular 3D Conformer Ensembles

GeoMol: Torsional Geometric Generation of Molecular 3D Conformer Ensembles This repository contains a method to generate 3D conformer ensembles direct

127 Dec 20, 2022
Pytorch implementation of our paper LIMUSE: LIGHTWEIGHT MULTI-MODAL SPEAKER EXTRACTION.

LiMuSE Overview Pytorch implementation of our paper LIMUSE: LIGHTWEIGHT MULTI-MODAL SPEAKER EXTRACTION. LiMuSE explores group communication on a multi

Auditory Model and Cognitive Computing Lab 17 Oct 26, 2022
This repo is for segmentation of T2 hyp regions in gliomas.

T2-Hyp-Segmentor This repo is for segmentation of T2 hyp regions in gliomas. By downloading the model from here you can use it to segment your T2w ima

1 Jan 18, 2022