|
28 | 28 | "metadata": {}, |
29 | 29 | "outputs": [], |
30 | 30 | "source": [ |
31 | | - "import tensorflow as tf\n", |
32 | | - "from nvidia.dali import pipeline_def, fn, types\n", |
33 | | - "import nvidia.dali.plugin.tf as dali_tf\n", |
34 | | - "\n", |
| 31 | + "# This package will use for install uninstalled package\n", |
| 32 | + "import subprocess\n", |
| 33 | + "\n", |
| 34 | + "# Import TensorFlow and install if not installed\n", |
| 35 | + "try:\n", |
| 36 | + " import tensorflow as tf\n", |
| 37 | + "except(ModuleNotFoundError):\n", |
| 38 | + " subprocess.run([\"pip3\", \"install\", \"tensorflow\"])\n", |
| 39 | + " import tensorflow as tf\n", |
| 40 | + "\n", |
| 41 | + "# Import NVIDIA DALI and install if not installed\n", |
| 42 | + "try:\n", |
| 43 | + " from nvidia.dali import pipeline_def, fn, types\n", |
| 44 | + "except(ModuleNotFoundError):\n", |
| 45 | + " import re\n", |
| 46 | + "\n", |
| 47 | + " nv_smi = subprocess.run([\"nvidia-smi\"], stdout=subprocess.PIPE).stdout\n", |
| 48 | + " cuda_version = float(re.search(r'CUDA\\sVersion:\\s+(\\d+\\.\\d+)', nv_smi.decode()).group(1))\n", |
| 49 | + " if 12 <= cuda_version:\n", |
| 50 | + " subprocess.run(['pip' 'install' '--extra-index-url' 'https://developer.download.nvidia.com/compute/redist' '--upgrade nvidia-dali-cuda120'])\n", |
| 51 | + " else:\n", |
| 52 | + " subprocess.run(['pip' 'install' '--extra-index-url' 'https://developer.download.nvidia.com/compute/redist' '--upgrade nvidia-dali-cuda110'])\n", |
| 53 | + "\n", |
| 54 | + " from nvidia.dali import pipeline_def, fn, types\n", |
| 55 | + "\n", |
| 56 | + "# Import NVIDIA DALI TensorFlow plugin and install if not installed\n", |
| 57 | + "try:\n", |
| 58 | + " import nvidia.dali.plugin.tf as dali_tf\n", |
| 59 | + " \n", |
| 60 | + "except(ModuleNotFoundError):\n", |
| 61 | + " if 12 <= cuda_version:\n", |
| 62 | + " subprocess.run(['pip' 'install' '--extra-index-url' 'https://developer.download.nvidia.com/compute/redist' '--upgrade nvidia-dali-tf-plugin-cuda120'])\n", |
| 63 | + " else:\n", |
| 64 | + " subprocess.run(['pip' 'install' '--extra-index-url' 'https://developer.download.nvidia.com/compute/redist' '--upgrade nvidia-dali-tf-plugin-cuda110'])\n", |
| 65 | + " import nvidia.dali.plugin.tf as dali_tf\n", |
| 66 | + "\n", |
| 67 | + "\n", |
| 68 | + "# Import Python internal modules\n", |
35 | 69 | "import os\n", |
36 | 70 | "import glob\n", |
37 | | - "import math\n" |
| 71 | + "import math\n", |
| 72 | + "import subprocess\n", |
| 73 | + "import re" |
38 | 74 | ] |
39 | 75 | }, |
40 | 76 | { |
|
296 | 332 | "name": "python", |
297 | 333 | "nbconvert_exporter": "python", |
298 | 334 | "pygments_lexer": "ipython3", |
299 | | - "version": "3.10.11" |
| 335 | + "version": "3.8.16" |
300 | 336 | }, |
301 | 337 | "orig_nbformat": 4 |
302 | 338 | }, |
|
0 commit comments