|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Getting Started with [Intel Model Zoo](https://github.com/IntelAI/models)\n", |
| 8 | + "\n", |
| 9 | + "This code sample will serve as a sample use case to perform TensorFlow ResNet50v1.5 inference on a synthetic data implementing a FP32/FP16 and Int8 pre-trained model. The pre-trained model published as part of Intel Model Zoo will be used in this sample. " |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "markdown", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "## Select precision and download model\n", |
| 17 | + "Select the precision that you would like to run resnet50 model with. `fp32` , `fp16` or `int8`" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "code", |
| 22 | + "execution_count": null, |
| 23 | + "metadata": {}, |
| 24 | + "outputs": [], |
| 25 | + "source": [ |
| 26 | + "precision = \"fp32\" # or \"int8\" or \"fp16\"\n", |
| 27 | + "batch_size = 1024\n", |
| 28 | + "output_dir= './''" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "code", |
| 33 | + "execution_count": null, |
| 34 | + "metadata": {}, |
| 35 | + "outputs": [], |
| 36 | + "source": [ |
| 37 | + "import os\n", |
| 38 | + "initial_cwd = os.getcwd()\n", |
| 39 | + "model_bucket = 'https://storage.googleapis.com/intel-optimized-tensorflow/models/gpu/'\n", |
| 40 | + "model_precision = '_int8' if 'int8' == precision else ''\n", |
| 41 | + "model_file = 'resnet50_v1' + model_precision + '.pb'\n", |
| 42 | + "model_download_path = os.path.join(model_bucket, model_file)" |
| 43 | + ] |
| 44 | + }, |
| 45 | + { |
| 46 | + "cell_type": "code", |
| 47 | + "execution_count": null, |
| 48 | + "metadata": {}, |
| 49 | + "outputs": [], |
| 50 | + "source": [ |
| 51 | + "#download Intel's pretrained resnet50 model\n", |
| 52 | + "if not os.path.exists(os.path.join(os.getcwd(), model_file)):\n", |
| 53 | + " ! wget $model_download_path\n", |
| 54 | + "model_local_path = os.path.join(os.getcwd(), model_file)\n", |
| 55 | + "if not os.path.exists(model_local_path):\n", |
| 56 | + " raise Exception(\"Failed to download pretrained Model file {}\", model_download_path)" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "markdown", |
| 61 | + "metadata": {}, |
| 62 | + "source": [ |
| 63 | + "We will be using a synthetic dataset of size 244x244.\n", |
| 64 | + "It is important to set optimial batch_size, MKL run-time settings, TensorFlow's inter-intra number of threads to enable compute and data layer optimizations. We have identified optimial settings for popular topologies including ResNet50 to maximize GPU utlization. For more details on Run-time settings refer to blogs [maximize XPU performance](https://software.intel.com/en-us/articles/maximize-tensorflow-performance-on-cpu-considerations-and-recommendations-for-inference), [Intel Model Zoo tutorials](https://github.com/IntelAI/models/tree/master/docs). \n" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "code", |
| 69 | + "execution_count": null, |
| 70 | + "metadata": {}, |
| 71 | + "outputs": [], |
| 72 | + "source": [ |
| 73 | + "%cd /opt/intel/oneapi/modelzoo/latest" |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "cell_type": "markdown", |
| 78 | + "metadata": {}, |
| 79 | + "source": [ |
| 80 | + "## Batch and Online Inference" |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + "cell_type": "code", |
| 85 | + "execution_count": null, |
| 86 | + "metadata": {}, |
| 87 | + "outputs": [], |
| 88 | + "source": [ |
| 89 | + "# Run inference using --batch-size=128 for throughput, or --batch-size=1 for latency\n", |
| 90 | + "%run models/benchmarks/launch_benchmark.py \\\n", |
| 91 | + " --in-graph $model_local_path \\\n", |
| 92 | + " --model-name resnet50v1_5 \\\n", |
| 93 | + " --framework tensorflow \\\n", |
| 94 | + " --precision $precision \\\n", |
| 95 | + " --mode inference \\\n", |
| 96 | + " --batch-size=$batch_size \\\n", |
| 97 | + " --benchmark-only \\\n", |
| 98 | + " --output-dir=$output_dir \\\n", |
| 99 | + " --gpu " |
| 100 | + ] |
| 101 | + }, |
| 102 | + { |
| 103 | + "cell_type": "markdown", |
| 104 | + "metadata": {}, |
| 105 | + "source": [ |
| 106 | + "The output(both stdout and stderr) is displayed on the command line console" |
| 107 | + ] |
| 108 | + }, |
| 109 | + { |
| 110 | + "cell_type": "code", |
| 111 | + "execution_count": null, |
| 112 | + "metadata": {}, |
| 113 | + "outputs": [], |
| 114 | + "source": [ |
| 115 | + "os.chdir(initial_cwd)\n", |
| 116 | + "print('[CODE_SAMPLE_COMPLETED_SUCCESFULLY]')" |
| 117 | + ] |
| 118 | + } |
| 119 | + ], |
| 120 | + "metadata": { |
| 121 | + "kernelspec": { |
| 122 | + "display_name": "Python 3 (ipykernel)", |
| 123 | + "language": "python", |
| 124 | + "name": "python3" |
| 125 | + }, |
| 126 | + "language_info": { |
| 127 | + "codemirror_mode": { |
| 128 | + "name": "ipython", |
| 129 | + "version": 3 |
| 130 | + }, |
| 131 | + "file_extension": ".py", |
| 132 | + "mimetype": "text/x-python", |
| 133 | + "name": "python", |
| 134 | + "nbconvert_exporter": "python", |
| 135 | + "pygments_lexer": "ipython3", |
| 136 | + "version": "3.10.6" |
| 137 | + } |
| 138 | + }, |
| 139 | + "nbformat": 4, |
| 140 | + "nbformat_minor": 4 |
| 141 | +} |
0 commit comments