|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# deeptrack.backend._config\n", |
| 8 | + "\n", |
| 9 | + "<a href=\"https://colab.research.google.com/github/DeepTrackAI/DeepTrack2/blob/develop/tutorials/3-advanced-topics/DTAT399F_backend._config.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": null, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "# !pip install deeptrack # Uncomment if running on Colab/Kaggle." |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "markdown", |
| 23 | + "metadata": {}, |
| 24 | + "source": [ |
| 25 | + "This advanced tutorial introduces the backend._config module." |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "cell_type": "markdown", |
| 30 | + "metadata": {}, |
| 31 | + "source": [ |
| 32 | + "## 1. What is `_config`?\n", |
| 33 | + "\n", |
| 34 | + "The `_config` module defines a configuration management system for handling devices (CPU/GPU) and numerical computation backend libraries like `numpy`, `cupy`, `torch`." |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "cell_type": "markdown", |
| 39 | + "metadata": {}, |
| 40 | + "source": [ |
| 41 | + "## 2. Instancing a Config object" |
| 42 | + ] |
| 43 | + }, |
| 44 | + { |
| 45 | + "cell_type": "code", |
| 46 | + "execution_count": null, |
| 47 | + "metadata": {}, |
| 48 | + "outputs": [], |
| 49 | + "source": [ |
| 50 | + "from deeptrack.backend._config import Config\n", |
| 51 | + "\n", |
| 52 | + "configuration = Config()" |
| 53 | + ] |
| 54 | + }, |
| 55 | + { |
| 56 | + "cell_type": "markdown", |
| 57 | + "metadata": {}, |
| 58 | + "source": [ |
| 59 | + "## 3. Setting Device to GPU\n" |
| 60 | + ] |
| 61 | + }, |
| 62 | + { |
| 63 | + "cell_type": "code", |
| 64 | + "execution_count": null, |
| 65 | + "metadata": {}, |
| 66 | + "outputs": [ |
| 67 | + { |
| 68 | + "name": "stderr", |
| 69 | + "output_type": "stream", |
| 70 | + "text": [ |
| 71 | + "/tmp/ipykernel_10742/2569479069.py:1: DeprecationWarning: (enable/disable)_gpu is deprecated. Use set_device instead\n", |
| 72 | + " configuration.enable_gpu()\n" |
| 73 | + ] |
| 74 | + } |
| 75 | + ], |
| 76 | + "source": [ |
| 77 | + "configuration.set_device(\"gpu\")\n", |
| 78 | + "\n", |
| 79 | + "# Or equivalently:\n", |
| 80 | + "configuration.enable_gpu() # Deprecated but available for compatability." |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + "cell_type": "markdown", |
| 85 | + "metadata": {}, |
| 86 | + "source": [ |
| 87 | + "## 4. Disabling GPU\n", |
| 88 | + "Disabling the GPU, and thus enabling the CPU is done with the `set_device` function." |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + "cell_type": "code", |
| 93 | + "execution_count": 47, |
| 94 | + "metadata": {}, |
| 95 | + "outputs": [], |
| 96 | + "source": [ |
| 97 | + "configuration.set_device(\"cpu\")" |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "markdown", |
| 102 | + "metadata": {}, |
| 103 | + "source": [ |
| 104 | + "## 5. Set Backend library to Torch\n", |
| 105 | + "By default, the backend computation library is Numpy, but this can be changed with the `set_backend` function." |
| 106 | + ] |
| 107 | + }, |
| 108 | + { |
| 109 | + "cell_type": "code", |
| 110 | + "execution_count": null, |
| 111 | + "metadata": {}, |
| 112 | + "outputs": [], |
| 113 | + "source": [ |
| 114 | + "configuration.set_backend_torch() \n", |
| 115 | + "\n", |
| 116 | + "# Or equivalently:\n", |
| 117 | + "configuration.set_backend(\"torch\")" |
| 118 | + ] |
| 119 | + }, |
| 120 | + { |
| 121 | + "cell_type": "markdown", |
| 122 | + "metadata": {}, |
| 123 | + "source": [ |
| 124 | + "## 5. Enabling/Disabling Image Wrapping\n", |
| 125 | + "Image wrapping is a function which wraps the output of a feature into a list for formatting purposes. By default this is disabled.\n", |
| 126 | + "To enable Image Wrapping in the config file, you specify this with the `enable_mage_wrapper()` function." |
| 127 | + ] |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "code", |
| 131 | + "execution_count": null, |
| 132 | + "metadata": {}, |
| 133 | + "outputs": [ |
| 134 | + { |
| 135 | + "data": { |
| 136 | + "text/plain": [ |
| 137 | + "<deeptrack.backend._config.Config.wrapper_enabled_context.<locals>.NullContext at 0x7f5419416a10>" |
| 138 | + ] |
| 139 | + }, |
| 140 | + "execution_count": 58, |
| 141 | + "metadata": {}, |
| 142 | + "output_type": "execute_result" |
| 143 | + } |
| 144 | + ], |
| 145 | + "source": [ |
| 146 | + "configuration.enable_image_wrapper()" |
| 147 | + ] |
| 148 | + } |
| 149 | + ], |
| 150 | + "metadata": { |
| 151 | + "kernelspec": { |
| 152 | + "display_name": ".venv", |
| 153 | + "language": "python", |
| 154 | + "name": "python3" |
| 155 | + }, |
| 156 | + "language_info": { |
| 157 | + "codemirror_mode": { |
| 158 | + "name": "ipython", |
| 159 | + "version": 3 |
| 160 | + }, |
| 161 | + "file_extension": ".py", |
| 162 | + "mimetype": "text/x-python", |
| 163 | + "name": "python", |
| 164 | + "nbconvert_exporter": "python", |
| 165 | + "pygments_lexer": "ipython3", |
| 166 | + "version": "3.10.12" |
| 167 | + } |
| 168 | + }, |
| 169 | + "nbformat": 4, |
| 170 | + "nbformat_minor": 2 |
| 171 | +} |
0 commit comments