Tag: 日本語

  • How to Install SLEAP [Updated February 2024]

    How to Install SLEAP [Updated February 2024]

    Here I’d like to walk through how to install SLEAP, a machine learning-based tool for tracking animal body parts.

    DeepLabCut is the best-known tracking tool, and I’ve written about how to install it myself in the past, while many others have posted articles about it as well.

    SLEAP, however, has relatively few articles written about it in Japanese.
    SLEAP has many advantages over DeepLabCut, so I decided to write up the installation procedure to make it a viable option for more people.

    SLEAP’s documentation covers everything from installation to usage very clearly, complete with videos, so anyone comfortable with English should find it easy to get started.

    The SLEAP paper is available here

    The official SLEAP website is here

    The SLEAP GitHub repository is here

    Introduction

    First, a note about the approach described in the official SLEAP installation guide:

    mamba create -y -n sleap -c conda-forge -c nvidia -c sleap -c anaconda sleap=1.3.3

    the one-line command that is supposed to handle environment creation, package installation, and everything else at once. I tried it on several computers, but in every case it hung indefinitely during the environment creation step and never completed.

    So in this post I’ll introduce the alternative installation method that the developers also suggest.

    Installation

    We’ll basically follow the installation instructions on the official SLEAP site.

    Environment

    ・Windows 11 Pro
    ・Verified on an NVIDIA 3080
    ・SLEAP 1.3.3
    ・Python 3.7.12

    Downloading the files

    First, download the files from the SLEAP GitHub repository to your computer.

    If you’re using Git, run the following command.

    git clone https://github.com/talmolab/sleap

    If the git command isn’t available, either install git or download the files directly from GitHub.

    Installing the GPU driver

    Install the NVIDIA driver.
    (Skip this step if it’s already installed.)

    Installing Anaconda

    Next, download and install the Windows 10 64-bit version from the Anaconda website.
    Click Free Download on the Anaconda site and scroll down; you’ll see a screen like the one below.
    Install the Windows installer on the far left.

    Once Anaconda is installed, you should find “Anaconda Prompt” in your Windows app list.
    We’ll use it to run the commands below to create the virtual environment, install the packages, and finally launch SLEAP.

    Creating the virtual environment and installing

    Next, run the following commands to create the virtual environment and install SLEAP.
    The environment will be named “sleap”.

    cd sleap
    conda env create -f environment.yml -n sleap

    Incidentally, the commands above work on computers with a GPU;
    on machines without one, use the following instead.

    cd sleap
    conda env create -f environment_no_cuda.yml -n sleap

    That completes the installation.

    Checking that the installation worked

    Activate the virtual environment and launch SLEAP with sleap-label.

    conda activate sleap
    sleap-label

    You’ll need to activate the virtual environment (the conda activate sleap command) every time you reopen Anaconda Prompt.

    After activating the environment, the prompt should change from (base) to (sleap).

    If it launches, the installation was successful.

    Checking version information for reporting in a paper

    To check the version, activate the sleap environment and then run the following command.

    python -c "import sleap; sleap.versions()"

    This outputs:

    SLEAP: 1.3.3
    TensorFlow: 2.7.0
    Numpy: 1.21.5
    Python: 3.7.12
    OS: Windows-10-10.0.22621-SP0

    which shows the SLEAP version and related information.

    To check whether SLEAP can use the GPU, run:

    python -c "import sleap; sleap.system_summary()"

    If the GPU is available, you’ll see output like the following.

    GPUs: 1/1 available
      Device: /physical_device:GPU:0
             Available: True
           Initialized: False
         Memory growth: None

    In future posts, I hope to walk through how to actually use SLEAP.

    Bonus

    For those who aren’t sure which computer to buy, I’ve started offering PC purchase consultations on Coconala!

    あなたの要望に合わせてパソコンを選び、提案します パソコン選びに困っている方々へ!様々な目的に対応できます!

    I often pick out computers and give advice about them, and many friends have told me I could make money doing PC consultations.
    That inspired me to give it a try!

    I’ll recommend a machine that fits both what you want to use it for and your budget.
    In particular, I’ve chosen and used many computers intended for machine learning.

    And if you’d like, I can also advise you on what to look for the next time you buy a computer.

    Computers I’ve picked out so far include lab analysis machines, everyday-use machines, game streaming machines, machines for incoming university students, machines that can run CAD for architecture students, and simple entry-level machines.

    I use both Mac and Windows, so I can discuss and recommend either one!

    Please feel free to make use of it.

  • How to Install Python Video Annotator

    How to Install Python Video Annotator

    What is Python Video Annotator?

    Python Video Annotator is an application that lets you analyze recorded videos and annotate events within them along a timeline.

    Researchers in neuroscience and ethology can use it to record videos of animals and then analyze and quantify their behavior.
    For example, suppose you are recording mouse behavior and want to score events such as tongue extension, tail flicks, or ear movements.
    When does each event occur in the video, and how long does it last?
    Watching the video and logging everything in Excel each time quickly becomes overwhelming when you have defined many behaviors.
    With a tool like this, you can annotate the video directly and export the timing and event information.

    There used to be an open-source application for scoring animal behavior called VCode.
    The problem, however, is that it no longer runs on current computer operating systems.

    Python Video Annotator runs on modern PCs, retains the features you need, and can additionally be combined with external sensor data (such as pressure gauges) and behavior quantification tools like DeepLabCut, making it a very useful tool for researchers.

    How to install

    The official site describes the installation procedure in detail, but I could not get it to install properly on my machine. (Installing it directly may have caused conflicts with packages already present on my system.)
    So instead I followed the approach described on the GitHub page: building a virtual environment with Anaconda and installing there.

    It sounds complicated when written out, but the steps are actually very simple.
    As of now (October 20, 2021) it does not appear to support the latest macOS (Big Sur 11.6), though this will likely be fixed soon.
    For that reason, I will use Windows as the example here.

    That said, once you have installed Anaconda on macOS and can use the conda command, the steps are essentially the same, so please refer to this guide once support arrives. (For details, see my previous post.)

    Install Anaconda and open the Anaconda Prompt.
    Then create a virtual environment and activate it.

    conda create -n videoannotator python=3.6
    conda activate videoannotator

    Next, install the required packages.

    pip install opencv-python-headless pyqt5==5.14.1 pyqtwebengine==5.14.0

    Then install Python Video Annotator.

    pip install python-video-annotator

    Once the various processes finish, the installation is complete.

    To launch it, activate the virtual environment first, then run the command.

    conda activate videoannotator
    start-video-annotator

    If the software starts up, you are all set.

  • How to Install DeepLabCut 2.3 [Updated December 2023]

    How to Install DeepLabCut 2.3 [Updated December 2023]

    In this post, I’ll walk through how to install DeepLabCut.

    Reference sites
    ・Japanese-language sites
    https://qiita.com/auditorycortex/items/1b3a55101cddf09553b2
    ↑Very clear. Following this should get you through just fine.

    https://note.com/sakulab/n/n9caeb32d74d6
    ↑Includes screenshots

    ・DeepLabCut homepage
    ・GitHub

    Installation

    Environment
    ・Windows 10
    ・Verified on NVIDIA 2060 SUPER, NVIDIA 1080 Ti, and NVIDIA 3080
    (did not work on NVIDIA 1060 SUPER)
    ・DeepLabCut 2.1
    ・NVIDIA Driver, latest version
    ・Anaconda3
    ・Python 3.8
    ・CUDA 11.8
    ・tensorflow-gpu 2.5

    Steps
    First, download the master files from the GitHub page.

    You can download them via “Download ZIP” under Code.

    Next, download and install the Windows 10 64-bit version from the Anaconda website.

    Install the NVIDIA driver. (Skip this step if it is already installed.)

    Scroll down on the DeepLabCut website, click “DOWNLOAS CONDA FILE” on the right,
    and download DEEPLABCUT.yaml.

    Create a DeepLabCut folder somewhere on your PC (the Desktop or a directory on the C drive is recommended), and make an “environment” folder inside it.
    Then place the DEEPLABCUT.yaml file you just downloaded into that folder.
    This is just personal preference, but I like to keep environment files in one fixed location, so this is how I do it.

    Launch Anaconda Prompt as an administrator. (A terminal-like window full of white text on black, similar to Command Prompt, will appear.)
    Anaconda Prompt is installed together with Anaconda, so you should be able to find it in your list of installed programs.

    Now build a virtual environment using the DEEPLABCUT.yaml file you downloaded.
    In Anaconda Prompt, enter

    conda env create -f C:(DLC-GPU.yamlファイルの場所)DEEPLABCUT.yaml

    You can check the location of the DEEPLABCUT.yaml file from the file’s properties, so look it up there and enter it.

    When you run this command, various components will be downloaded.
    After that, activate the virtual environment you created.

    conda activate DEEPLABCUT

    The prompt should change from (base) to (DEEPLABCUT).
    If you get that far, you’re good for now.

    Next, install CUDA and cuDNN.

    conda install -c conda-forge cudnn

    This will download suitable versions of the CUDA toolkit and cuDNN for you.

    Then enter the following four commands to complete the installation.

    pip install numpy
    pip install deeplabcut
    pip install imgaug
    pip install torch

    Update DeepLabCut, and the installation is complete.

    pip install --upgrade deeplabcut

    Once you’ve made it this far, try launching it.

    conda activate DEEPLABCUT
    python -m deeplabcut

    Entering this will launch the DeepLabCut GUI.

    What to do when DeepLabCut won’t run on the GPU

    Sometimes you start training and think, “Huh? Isn’t this slow?”
    That’s because DeepLabCut is running on the CPU when you intended it to run on the GPU.

    A common cause is a version mismatch among CUDA, cuDNN, and tensorflow.

    Packages like tensorflow keep getting updated to newer versions,
    so things occasionally stop working.

    For the latest version information, please check DeepLabCut’s GitHub.

    That covers the installation process.
    In upcoming posts, I plan to explain how to use it.

    Bonus

    For those who aren’t sure which computer to buy, I’ve started offering PC purchase consultations on Coconala!

    あなたの要望に合わせてパソコンを選び、提案します パソコン選びに困っている方々へ!様々な目的に対応できます!

    I often pick out computers and give advice on them, and many friends have told me I could make money doing PC consultations.
    That inspired me to give it a try!

    I’ll recommend a purchase that fits how you plan to use the computer and your budget.
    In particular, I’ve chosen and used a lot of computers for machine learning.

    And if you’d like, I can also advise you on what to look for the next time you buy a computer.

    Computers I’ve helped select include analysis machines for research labs, everyday-use PCs, PCs for game streaming, PCs for incoming university students, CAD-capable PCs for architecture students, and simple stopgap machines.

    I use both Mac and Windows, so I can discuss and recommend either one!

    Please feel free to make use of it.

    Addendum 1

    I’ve also written an article on how to install “SLEAP,” another behavior tracking tool like DeepLabCut.

    SLEAP is every bit as capable as DeepLabCut, so please give it a try.

  • Bonsai as a visual programming language

    Bonsai as a visual programming language

    Bonsai is a visual programming language introduced in a 2015 paper.
    It allows you to acquire data from sensors and process it at the same time.

    A key feature of Bonsai is that complex processing pipelines can be assembled easily, much like putting together a puzzle, and the results of that processing can be checked in real time.

    Bonsai can also be combined with other analysis software (DeepLabCut, Open Ephys, BonVision, and so on) and with hardware (cameras, controllers, microcontrollers, etc.), making it highly extensible.

    Because you can carry out complex analysis and processing intuitively without having to learn a programming language that looks intimidating, anyone can use it easily, and it broadens the range of experiments you can run.

    The paper describing Bonsai is available here.
    You can install Bonsai from here.

    Image taken from the paper.
    Each circle is called a node and represents an individual operation.

    This is what the screen looks like when Bonsai is actually running (taken from the paper).
    On the left you can search for nodes and add the one you need; in the central panel you arrange nodes to build up a pipeline while visualizing what it does; and on the right are the detailed settings for each node.

    The windows popping up in the main panel show the execution status of each node; for a camera capture node, for example, the live camera image can be displayed.

    It may look difficult at first glance, but seen this way it turns out to be surprisingly straightforward.

    Now let’s actually install it.
    That said, all you need to do is download it from this site.
    Just open the downloaded “Bonsai-*.*.*.exe” file and run the installer.
    Note that security software such as Trend Micro may block the installation.

    Once Bonsai is installed, both Bonsai and Bonsai (x86) will appear in your list of applications.
    For normal use either one is fine, but occasionally one of them will fail to run; in that case, trying the other one often works.

    One drawback is that Bonsai currently runs on Windows only, and is not supported on Linux or macOS.
    That may change in the future, but it is something to keep in mind.

    From the next post, I’ll start actually using Bonsai.