Neural Architecture Search Powered by Swarm Intelligence 🐜

Overview

Neural Architecture Search Powered by Swarm Intelligence 🐜

DeepSwarm

DeepSwarm is an open-source library which uses Ant Colony Optimization to tackle the neural architecture search problem. The main goal of DeepSwarm is to automate one of the most tedious and daunting tasks, so people can spend more of their time on more important and interesting things. DeepSwarm offers a powerful configuration system which allows you to fine-tune the search space to your needs.

Example 🖼

from deepswarm.backends import Dataset, TFKerasBackend
from deepswarm.deepswarm import DeepSwarm

dataset = Dataset(training_examples=x_train, training_labels=y_train, testing_examples=x_test, testing_labels=y_test)
backend = TFKerasBackend(dataset=dataset)
deepswarm = DeepSwarm(backend=backend)
topology = deepswarm.find_topology()
trained_topology = deepswarm.train_topology(topology, 50)

Installation 💾

  1. Install the package

    pip install deepswarm
  2. Install one of the implemented backends that you want to use

    pip install tensorflow-gpu==1.13.1

Usage 🕹

  1. Create a new file containing the example code

    touch train.py
  2. Create settings directory which contains default.yaml file. Alternatively you can run the script and instantly stop it, as this should automatically create settings directory which contains default.yaml file

  3. Update the newly created YAML file to your dataset needs. The only two important changes you must make are: (1) change the loss function to reflect your task (2) change the shape of input and output nodes

Search 🔎

(1) The ant is placed on the input node. (2) The ant checks what transitions are available. (3) The ant uses the ACS selection rule to choose the next node. (4) After choosing the next node the ant selects node’s attributes. (5) After all ants finished their tour the pheromone is updated. (6) The maximum allowed depth is increased and the new ant population is generated.

Note: Arrow thickness indicates the pheromone amount, meaning that thicker arrows have more pheromone.

Configuration 🛠

Node type Attributes
Input shape: tuple which defines the input shape, depending on the backend could be (width, height, channels) or (channels, width, height).
Conv2D filter_count: defines how many filters can be used.
kernel_size: defines what size kernels can be used. For example, if it is set to [1, 3], then only 1x1 and 3x3 kernels will be used.
activation: defines what activation functions can be used. Allowed values are: ReLU, ELU, LeakyReLU, Sigmoid and Softmax.
Dropout rate: defines the allowed dropout rates. For example, if it is set to [0.1, 0.3], then either 10% or 30% of input units will be dropped.
BatchNormalization -
Pool2D pool_type: defines the types of allowed pooling nodes. Allowed values are: max (max pooling) and average (average pooling).
pool_size: defines the allowed pooling window sizes. For example, if it is set to [2], then only 2x2 pooling windows will be used.
stride: defines the allowed stride sizes.
Flatten -
Dense output_size: defines the allowed output space dimensionality.
activation: defines what activation functions can be used. Allowed values are: ReLU, ELU, LeakyReLU, Sigmoid and Softmax.
Output output_size: defines the output size (how many different classes to classify).
activation: defines what activation functions can be used. Allowed value are ReLU, ELU, LeakyReLU, Sigmoid and Softmax.
Setting Description
save_folder Specifies the name of the folder which should be used to load the backup. If not specified the search will start from zero.
metrics Specifies what metrics should algorithm use to evaluate the models. Currently available options are: accuracy and loss.
max_depth Specifies the maximum allowed network depth (how deeply the graph can be expanded). The search is performed until the maximum depth is reached. However, it does not mean that the depth of the best architecture will be equal to the max_depth.
reuse_patience Specifies the maximum number of times that weights can be reused without improving the cost. For example, if it is set to 1 it means that when some model X reuses weights from model Y and model X cost did not improve compared to model Y, next time instead of reusing model Y weights, new random weights will be generated.
start Specifies the starting pheromone value for all the new connections.
decay Specifies the local pheromone decay rate in percentage. For example, if it is set to 0.1 it means that during the local pheromone update the pheromone value will be decreased by 10%.
evaporation Specifies the global pheromone evaporation rate in percentage. For example, if it is set to 0.1 it means that during the global pheromone update the pheromone value will be decreased by 10%.
greediness Specifies how greedy should ants be during the edge selection (the number is given in percentage). For example, 0.5 means that 50% of the time when ant selects a new edge it should select the one with the highest associated probability.
ant_count Specifies how many ants should be generated during each generation (time before the depth is increased).
epochs Specifies for how many epochs each candidate architecture should be trained.
batch_size Specifies the batch size (number of samples used to calculate a single gradient step) used during the training process.
patience Specifies the early stopping number used during the training (after how many epochs when the cost is not improving the training process should be stopped).
loss Specifies what loss function should be used during the training. Currently available options are sparse_categorical_crossentropy and categorical_crossentropy.
spatial_nodes Specifies which nodes are placed before the flattening node. Values in this array must correspond to node names.
flat_nodes Specifies which nodes are placed after the flattening node (array should also include the flattening node). Values in this array must correspond to node names.
verbose Specifies if the associated component should log the output.

Future goals 🌟

  • Add a node which can combine the input from the two previous nodes.
  • Add a node which can skip the depth n in order to connect to the node in depth n+1.
  • Delete the models which are not referenced anymore.
  • Add an option to assemble the best n models into one model.
  • Add functionality to reuse the weights from the non-continues blocks, i.e. take the best weights for depth n-1 from one model and then take the best weights for depth n+1 from another model.

Citation 🖋

Online version is available at: arXiv:1905.07350

@article{byla2019deepswarm,
  title   =  {DeepSwarm: Optimising Convolutional Neural Networks using Swarm Intelligence},
  author  =  {Edvinas Byla and Wei Pang},
  journal =  {arXiv preprint arXiv:1905.07350},
  year    =  {2019}
}

Acknowledgments 🎓

DeepSwarm was developed under the supervision of Dr Wei Pang in partial fulfilment of the requirements for the degree of Bachelor of Science of the University of Aberdeen.

Comments
  • Out of memory when saving object

    Out of memory when saving object

        def save_object(self, data, name):
            """Saves given object to the object backup directory.
    
            Args:
                data: object that needs to be saved.
                name: string value representing the name of the object.
            """
    
            with open(str(self.current_path / Storage.DIR["OBJECT"] / name), 'wb') as f:
                pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
    

    this yeilds a MemoryError when trying to do the pickle. It takes up at least 20GB of RAM. My model is fairly small. See log excerpt following:

    -------------------------------NEW BEST ANT FOUND-------------------------------
    ---------------------------BEST ANT DURING ITERATION----------------------------
    ======= 
     Ant: 0x5eaa4358 
     Loss: 0.246397 
     Accuracy: 0.908695 
     Path: InputNode(shape:(256, 256, 1)) -> Conv2DNode(kernel_size:3, filter_count:64, activation:ReLU) -> FlattenNode() -> OutputNode(output_size:1, activation:Sigmoid) 
     Hash: 0f8bcb2b4fbd88fb3c5ffca7be08add054c8d35df1f122f4db0f043a91f7c901 
    =======
    
    opened by isaacgerg 9
  • Error after generating ant 1

    Error after generating ant 1

    I get the following error everytime after generating ant 1

    builtins.ValueError: Tensor("Adam/iterations:0", shape=(), dtype=resource) must be from the same graph as Tensor("training/Adam/Const:0", shape=(), dtype=int64).

    Prior output is:

    ======= Ant: 0x5f7a92e8 Loss: 0.531042 Accuracy: 0.750683 Path: InputNode(shape:(256, 256, 1)) -> Conv2DNode(kernel_size:1, filter_count:64, activation:ReLU) -> FlattenNode() -> OutputNode(output_size:1, activation:Sigmoid) Hash: 2510cfe0ba8648855dc73f4c2cb8e7ff75878eeee906c211c51f470bc6ff0547

    ---------------------------Current search depth is 1---------------------------- --------------------------------GENERATING ANT 1-------------------------------- Train on 5270 samples, validate on 586 samples

    opened by isaacgerg 6
  •  builtins.NotImplementedError: numpy() is only available when eager execution is enabled.

    builtins.NotImplementedError: numpy() is only available when eager execution is enabled.

    Got this error after running a bit more.

    Stack:

    File "D:\ASASINATR\projects\muscle_deep_swarm\trainer.py", line 332, in main() File "D:\ASASINATR\projects\muscle_deep_swarm\trainer.py", line 325, in main topology = deepswarm.find_topology() File "c:\python35\Lib\site-packages\deepswarm\deepswarm.py", line 43, in find_topology best_ant = self.aco.search() File "c:\python35\Lib\site-packages\deepswarm\aco.py", line 61, in search self.storage.perform_backup() File "c:\python35\Lib\site-packages\deepswarm\storage.py", line 67, in perform_backup self.save_object(self.deepswarm, Storage.ITEM["BACKUP"]) File "c:\python35\Lib\site-packages\deepswarm\storage.py", line 213, in save_object pickle.dump(data, f, pickle.HIGHEST_PROTOCOL) File "c:\python35\Lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 923, in reduce return (ResourceVariable, (self.numpy(),)) File "c:\python35\Lib\site-packages\tensorflow\python\ops\resource_variable_ops.py", line 687, in numpy "numpy() is only available when eager execution is enabled.")

    builtins.NotImplementedError: numpy() is only available when eager execution is enabled.

    opened by isaacgerg 4
  • Readme should indicate this work only in python 3.6 and greater

    Readme should indicate this work only in python 3.6 and greater

    WindowsPath doesnt integrate nicely into open until python 3.6.

    EDIT 1: you could also wrap the open(windowsPath) methods with open(str(windowsPath))

    opened by isaacgerg 2
  • Is

    Is "SPMT" spearmint?

    Since it is not referenced, so I have this question in the paper.

    If so that would be very amazing, the comparison between PSO and Bayesian Optimization has been validated in SigOpt's paper where two of them were very close instead of such a big gap in your paper. However, they didn't optimize topology but only the number of hidden units. I think maybe this is the main reason why NAS requires a different techniques than traditional ML where topology is hard-wired in the model itself.

    opened by pswpswpsw 1
  • Pytorch implementation

    Pytorch implementation

    First up, thanks for this wonderfully structured code. Works perfectly with Tensorflow 1.13.1

    I am currently working on adapting this for time series data for my use-case. In the backends.py there is a provision to extend this to other backends than TF. Is there a PyTorch implementation available for the same?

    opened by tushara21 1
  • Bump pyyaml from 5.1 to 5.4

    Bump pyyaml from 5.1 to 5.4

    Bumps pyyaml from 5.1 to 5.4.

    Changelog

    Sourced from pyyaml's changelog.

    5.4 (2021-01-19)

    5.3.1 (2020-03-18)

    • yaml/pyyaml#386 -- Prevents arbitrary code execution during python/object/new constructor

    5.3 (2020-01-06)

    5.2 (2019-12-02)

    • Repair incompatibilities introduced with 5.1. The default Loader was changed, but several methods like add_constructor still used the old default yaml/pyyaml#279 -- A more flexible fix for custom tag constructors yaml/pyyaml#287 -- Change default loader for yaml.add_constructor yaml/pyyaml#305 -- Change default loader for add_implicit_resolver, add_path_resolver
    • Make FullLoader safer by removing python/object/apply from the default FullLoader yaml/pyyaml#347 -- Move constructor for object/apply to UnsafeConstructor
    • Fix bug introduced in 5.1 where quoting went wrong on systems with sys.maxunicode <= 0xffff yaml/pyyaml#276 -- Fix logic for quoting special characters
    • Other PRs: yaml/pyyaml#280 -- Update CHANGES for 5.1

    5.1.2 (2019-07-30)

    • Re-release of 5.1 with regenerated Cython sources to build properly for Python 3.8b2+

    ... (truncated)

    Commits
    • 58d0cb7 5.4 release
    • a60f7a1 Fix compatibility with Jython
    • ee98abd Run CI on PR base branch changes
    • ddf2033 constructor.timezone: _copy & deepcopy
    • fc914d5 Avoid repeatedly appending to yaml_implicit_resolvers
    • a001f27 Fix for CVE-2020-14343
    • fe15062 Add 3.9 to appveyor file for completeness sake
    • 1e1c7fb Add a newline character to end of pyproject.toml
    • 0b6b7d6 Start sentences and phrases for capital letters
    • c976915 Shell code improvements
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

    ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

    When I try to run the program I get following error:


    ValueError Traceback (most recent call last) in 2 import tensorflow as tf 3 ----> 4 from deepswarm.backends import Dataset, TFKerasBackend 5 from deepswarm.deepswarm import DeepSwarm 6

    ~\AppData\Local\Programs\Python\Python38\Scripts\DeepSwarm-master\deepswarm\backends.py in 7 8 from abc import ABC, abstractmethod ----> 9 from sklearn.model_selection import train_test_split 10 from tensorflow.keras import backend as K 11

    c:\users\user\appdata\local\programs\python\python38\lib\site-packages\sklearn_init_.py in 62 else: 63 from . import __check_build ---> 64 from .base import clone 65 from .utils._show_versions import show_versions 66

    c:\users\user\appdata\local\programs\python\python38\lib\site-packages\sklearn\base.py in 12 from scipy import sparse 13 from .externals import six ---> 14 from .utils.fixes import signature 15 from .utils import _IS_32BIT 16 from . import version

    c:\users\user\appdata\local\programs\python\python38\lib\site-packages\sklearn\utils_init_.py in 10 from scipy.sparse import issparse 11 ---> 12 from .murmurhash import murmurhash3_32 13 from .class_weight import compute_class_weight, compute_sample_weight 14 from . import _joblib

    init.pxd in init sklearn.utils.murmurhash()

    ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

    I use: python 3.8 numpy 1.20.1

    I would appreciate your help.

    opened by Billnewgate327 12
  • 1D Option?

    1D Option?

    Hi, thanks for your awesome tool! It would be great if there were an option to train models for sequences or 1d inputs - will there be a future version with 1D CNN layer options? Thanks!

    Type: Enhancement Status: Accepted Priority: Low 
    opened by collinskatie 1
  • [feature request] Add new evaluate_model function which can return a more generalized metric

    [feature request] Add new evaluate_model function which can return a more generalized metric

    In evaluate_model, the code below can be used to return metrics which can only be computed on all of the data as opposed to averaged by batches as currently done. For simplicity, you can set numThreads and qSize to 1.

    def evaluate(model, generator, steps, numThreads=2, qSize=5):
        numItemsPushed_predict = 0
        dataQueue = queue.Queue(maxsize=qSize)
        mutex = threading.Lock()
    
        def producer(steps):
            nonlocal numItemsPushed_predict
            killMe = False
            while True:
                mutex.acquire()
                if numItemsPushed_predict < steps:
                    numItemsPushed_predict += 1
                else:
                    killMe = True
                myUid = numItemsPushed_predict
                mutex.release()
                if killMe:
                    return
                #
                x, y = generator.next(myUid-1)
                dataQueue.put((x,y,myUid-1))
                #
            #
        #
    
        tVec = []
        for k in range(numThreads):
            t = threading.Thread(target=producer, args=(steps,))
            t.daemon = True
            t.start()
            tVec.append(t)
    
        resultVec = []
        batchSize = None
        pBar = tqdm.tqdm(range(steps), desc='EVALUATE')
        for k in pBar:
            currentQSize = dataQueue.qsize()
            item = dataQueue.get()
            x = item[0]
            y = item[1]
            uid = item[2] # For debug
            if batchSize is None:
                if type(x) is list:
                    batchSize = x[0].shape[0]
                else:
                    batchSize = x.shape[0]
                #
                resultVec = np.zeros(steps)
            r = model.evaluate(x, y, batch_size = batchSize, verbose=0)
            resultVec[k] = r
            #if type(y_pred) is list:
            #    predVec[k*batchSize : (k+1)*batchSize] = y_pred[0].flatten()
            #else:
            #    predVec[k*batchSize : (k+1)*batchSize] = y_pred.flatten()
            pBar.set_description('EVALUATE | QSize: {0}/{1}'.format(currentQSize, qSize))
        #
    
        return resultVec
    

    evaluate_model(self, model) becomes:

    y_true, y_pred = evaluate(model, data -- will have to convert from generator (easy), 1, 1) loss = lossFunction(y_true, y_pred) accuracy can be computed from sklearn.accuracy_score

    You could also support losses like AUC now.

    Type: Enhancement Status: Accepted Priority: Medium 
    opened by isaacgerg 3
Releases(v0.0.9)
REBEL: Relation Extraction By End-to-end Language generation

REBEL: Relation Extraction By End-to-end Language generation This is the repository for the Findings of EMNLP 2021 paper REBEL: Relation Extraction By

Babelscape 222 Jan 06, 2023
Attack on Confidence Estimation algorithm from the paper "Disrupting Deep Uncertainty Estimation Without Harming Accuracy"

Attack on Confidence Estimation (ACE) This repository is the official implementation of "Disrupting Deep Uncertainty Estimation Without Harming Accura

3 Mar 30, 2022
An official PyTorch Implementation of Boundary-aware Self-supervised Learning for Video Scene Segmentation (BaSSL)

An official PyTorch Implementation of Boundary-aware Self-supervised Learning for Video Scene Segmentation (BaSSL)

Kakao Brain 72 Dec 28, 2022
2021 CCF BDCI 全国信息检索挑战杯(CCIR-Cup)智能人机交互自然语言理解赛道第二名参赛解决方案

2021 CCF BDCI 全国信息检索挑战杯(CCIR-Cup) 智能人机交互自然语言理解赛道第二名解决方案 比赛网址: CCIR-Cup-智能人机交互自然语言理解 1.依赖环境: python==3.8 torch==1.7.1+cu110 numpy==1.19.2 transformers=

JinXiang 22 Oct 29, 2022
This repository contains Prior-RObust Bayesian Optimization (PROBO) as introduced in our paper "Accounting for Gaussian Process Imprecision in Bayesian Optimization"

Prior-RObust Bayesian Optimization (PROBO) Introduction, TOC This repository contains Prior-RObust Bayesian Optimization (PROBO) as introduced in our

Julian Rodemann 2 Mar 19, 2022
Database Reasoning Over Text project for ACL paper

Database Reasoning over Text This repository contains the code for the Database Reasoning Over Text paper, to appear at ACL2021. Work is performed in

Facebook Research 320 Dec 12, 2022
PyTorch implementation of the ideas presented in the paper Interaction Grounded Learning (IGL)

Interaction Grounded Learning This repository contains a simple PyTorch implementation of the ideas presented in the paper Interaction Grounded Learni

Arthur Juliani 4 Aug 31, 2022
A dual benchmarking study of visual forgery and visual forensics techniques

A dual benchmarking study of facial forgery and facial forensics In recent years, visual forgery has reached a level of sophistication that humans can

8 Jul 06, 2022
A memory-efficient implementation of DenseNets

efficient_densenet_pytorch A PyTorch =1.0 implementation of DenseNets, optimized to save GPU memory. Recent updates Now works on PyTorch 1.0! It uses

Geoff Pleiss 1.4k Dec 25, 2022
PyTorch implementation for the visual prior component (i.e. perception module) of the Visually Grounded Physics Learner [Li et al., 2020].

VGPL-Visual-Prior PyTorch implementation for the visual prior component (i.e. perception module) of the Visually Grounded Physics Learner (VGPL). Give

Toru 8 Dec 29, 2022
Simultaneous NMT/MMT framework in PyTorch

This repository includes the codes, the experiment configurations and the scripts to prepare/download data for the Simultaneous Machine Translation wi

<a href=[email protected]"> 37 Sep 29, 2022
AI Summer's complete catalog of articles

Learn Deep Learning with AI Summer A collection of all articles (almost 100) written for the AI Summer blog organized by topic. Deep Learning Theory M

AI Summer 95 Dec 29, 2022
EMNLP'2021: Simple Entity-centric Questions Challenge Dense Retrievers

EntityQuestions This repository contains the EntityQuestions dataset as well as code to evaluate retrieval results from the the paper Simple Entity-ce

Princeton Natural Language Processing 119 Sep 28, 2022
Everything about being a TA for ITP/AP course!

تی‌ای بودن! تی‌ای یا دستیار استاد از نقش‌های رایج بین دانشجویان مهندسی است، این ریپوزیتوری قرار است نکات مهم درمورد تی‌ای بودن و تی ای شدن را به ما نش

<a href=[email protected]"> 14 Sep 10, 2022
Official PyTorch implementation of Data-free Knowledge Distillation for Object Detection, WACV 2021.

Introduction This repository is the official PyTorch implementation of Data-free Knowledge Distillation for Object Detection, WACV 2021. Data-free Kno

NVIDIA Research Projects 50 Jan 05, 2023
[ECCVW2020] Robust Long-Term Object Tracking via Improved Discriminative Model Prediction (RLT-DiMP)

Feel free to visit my homepage Robust Long-Term Object Tracking via Improved Discriminative Model Prediction (RLT-DIMP) [ECCVW2020 paper] Presentation

Seokeon Choi 35 Oct 26, 2022
PyTorch implementation of "A Simple Baseline for Low-Budget Active Learning".

A Simple Baseline for Low-Budget Active Learning This repository is the implementation of A Simple Baseline for Low-Budget Active Learning. In this pa

10 Nov 14, 2022
ReAct: Out-of-distribution Detection With Rectified Activations

ReAct: Out-of-distribution Detection With Rectified Activations This is the source code for paper ReAct: Out-of-distribution Detection With Rectified

38 Dec 05, 2022
GAT - Graph Attention Network (PyTorch) 💻 + graphs + 📣 = ❤️

GAT - Graph Attention Network (PyTorch) 💻 + graphs + 📣 = ❤️ This repo contains a PyTorch implementation of the original GAT paper ( 🔗 Veličković et

Aleksa Gordić 1.9k Jan 09, 2023
[ICLR2021] Unlearnable Examples: Making Personal Data Unexploitable

Unlearnable Examples Code for ICLR2021 Spotlight Paper "Unlearnable Examples: Making Personal Data Unexploitable " by Hanxun Huang, Xingjun Ma, Sarah

Hanxun Huang 98 Dec 07, 2022