Code Monkey home page Code Monkey logo

morphocluster's Introduction

Morphocluster

Travis GPLv3 license

This repository contains the source code for the MorphoCluster application described in [Schroeder2020].

Installation (Web Application)

The web application runs in a Docker container.

  1. Clone the morphocluster repository and checkout the current stable branch: git clone -b 0.2.x https://github.com/morphocluster/morphocluster.git

  2. Decide where to store the data, e.g. /data/morphocluster, and create the required directories, e.g. mkdir -p /data/morphocluster/{postgres,data}. Make a copy of docker-compose.default.yml in the same directory, name it docker-compose.yml and edit the relevant parts (e.g. paths). Make a copy of environment.default.yml in the same directory, name it environment.yml and edit the relevant parts (e.g. for CUDA).

  3. Open a shell in the repository folder and build environment: docker-compose up --build This will take a long while when run for the first time.

  4. In a new terminal, connect to the MorphoCluster container and set it up:

    $ docker-compose exec morphocluster bash
    
    # Activate conda environment
    (base) root@abc123...:/code# . ./activate
    (morphocluster) root@abc123...:/code#
    
    # Create a user account
    flask add-user test-user
    Adding user test-user:
    Password: <hidden>
    Retype Password: <hidden>
  5. Data preparation. MorphoCluster accepts input data in ZIP files containing the image files and an index.csv file with two columns: object_id (a unique identifier for every object) and path (image file path inside the archive). EcoTaxa export files have to be converted (see below).

    Place the image archive and the deep learning model parameters into the data directory that is mounted inside the container.

    # Connect to MorphoCluster container and set up the environment (if not done before)
    $ docker-compose exec morphocluster bash
    (base) root@abc123...:/code# . ./activate
    (morphocluster) root@abc123...:/code#
    
    # Change into data directory
    $ cd /data
    
    # 0. Optionally convert EcoTaxa archive:
    $ morphocluster fix-ecotaxa archive.zip
    
    # 1. Calculate deep learning image features.
    # Using the GPU (see below) will considerably speed this up.
    # If --parameters-fn is not supplied, ImageNet-trained model weights will be used.
    # --input-mean and --input-std should then be supplied with the estimated mean color values.
    $ morphocluster features [--parameters-fn model_state.pth] [--input-mean 0.9,0.9,0.9] [--input-std 1,1,1] archive.zip features.h5
    
    # 2a. Cluster the features.
    $ morphocluster cluster [--pca 64] --min-cluster-size 128 features.h5 tree-128.zip
    
    # 2b. When repeating the clustering in the next iteration of the MorphoCluster process, supply the previously exported tree and reduce the cluster size.
    $ morphocluster cluster [--pca 64] --min-cluster-size 64 features.h5 tree-64.zip --tree /data/export/2020-05-15-10-34-34--3--tree-128.zip
    
    # 3. Import objects into the web application
    flask load-objects archive.zip
    
    # 4. Import features into the web application
    flask load-features [--pca 64] features.h5
    
    # 5. Import project into the web application
    flask load-project tree.zip

    Keep in mind that the paths are inside the Docker container, not on the host.

  6. Connect to the MorphoCluster service using the browser (http://localhost:8000/). Validate and Grow the found clusters and save the result. It will be placed in /data/export/ in the container.

  7. Repeat clustering, tree import, validation and growing.

Prerequisites

  • Docker (Version 20 or higher)
  • Docker Compose (Version 1.25 or higher)
  • The above steps were only tested on Linux.

GPU processing

By default, MorphoCluster uses the CPU to calculate deep learning image features. It is strongly advisable to use the GPU for that to speed up feature extraction dramatically. To enable feature extraction on the GPU, modify environment.yml to exclude cpuonly and include the correct cudatoolkit version. This has to be done before running docker-compose up --build. Read about the requirements for running CUDA containers.

Currently, docker-compose does not directly support NVIDIA docker (see #1073, #6691). It is therefore advisable to run the feature extraction direcly on the host.

SSH access

For users without the privilege to execute docker commands on the host system (e.g. for security reasons), it is possible to connect to the docker container directly via SSH.

  1. Make sure that port 22 is exposed in docker-compose.yml.

  2. Create a public key

    # Generate key pair (if not done already):
    $ ssh-keygen -t rsa -b 4096
    
    # Show public key. Copy this to your clipboard.
    $ cat ~/.ssh/id_rsa.pub
    # It looks a bit like this:
    ssh-rsa asdxyz ...
  3. Create docker/morphocluster/authorized_keys from the docker/morphocluster/authorized_keys.default template and paste the public key created in the previous step.

  4. After starting the morphocluster docker service, you can now connect to the docker container directly:

    $ ssh root@host -p 8022 -i ~/.ssh/id_rsa -o PubkeyAuthentication=yes
    
    # Inside the container, change into /code and activate the environment
    $ cd /code
    $ . activate
[Schroeder2020]Schröder, S., Kiko, R., & Koch, R. (2020). "MorphoCluster: Efficient Annotation of Plankton images by Clustering" arXiv:2005.01595.

morphocluster's People

Contributors

moi90 avatar dependabot[bot] avatar kimdonggyun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.