From 93802fd3fa9372e8575f8b750f336d719e919df6 Mon Sep 17 00:00:00 2001 From: Dina Suehiro Jones Date: Thu, 19 Aug 2021 14:39:37 -0700 Subject: [PATCH] Adds container packages for PyTorch Mask R-CNN Training and Inference (#89) * Add PyTorch SPR Mask R-CNN package specs, docs, and quickstart filesg * Update build arg * Doc updates for training * Print status * update error handling * try to run without pretrained model for training * Fix else * Doc update * Doc updates * Regenerated dockerfiles * Add new line at EOF --- .../pytorch-spr-maskrcnn-inference.Dockerfile | 87 ++++++++++++ .../pytorch-spr-maskrcnn-training.Dockerfile | 87 ++++++++++++ .../inference/cpu/.docs/container_build.md | 26 ++++ .../maskrcnn/inference/cpu/.docs/datasets.md | 25 ++++ .../inference/cpu/.docs/description.md | 5 + .../inference/cpu/.docs/docker_spr.md | 32 +++++ .../maskrcnn/inference/cpu/.docs/license.md | 4 + .../inference/cpu/.docs/quickstart.md | 8 ++ .../maskrcnn/inference/cpu/.docs/title.md | 2 + .../inference/cpu/.docs/wrapper_package.md | 16 +++ .../maskrcnn/inference/cpu/README_SPR.md | 126 ++++++++++++++++++ .../maskrcnn/inference/cpu/accuracy.sh | 51 +++++++ .../pytorch/maskrcnn/inference/cpu/build.sh | 42 ++++++ .../inference/cpu/inference_realtime.sh | 51 +++++++ .../inference/cpu/inference_throughput.sh | 51 +++++++ .../pytorch/maskrcnn/inference/cpu/run.sh | 68 ++++++++++ .../training/cpu/.docs/container_build.md | 26 ++++ .../maskrcnn/training/cpu/.docs/datasets.md | 30 +++++ .../training/cpu/.docs/description.md | 5 + .../maskrcnn/training/cpu/.docs/docker_spr.md | 19 +++ .../maskrcnn/training/cpu/.docs/license.md | 4 + .../maskrcnn/training/cpu/.docs/quickstart.md | 6 + .../maskrcnn/training/cpu/.docs/title.md | 2 + .../training/cpu/.docs/wrapper_package.md | 16 +++ .../maskrcnn/training/cpu/README_SPR.md | 116 ++++++++++++++++ .../pytorch/maskrcnn/training/cpu/build.sh | 42 ++++++ .../pytorch/maskrcnn/training/cpu/run.sh | 59 ++++++++ .../pytorch/maskrcnn/training/cpu/training.sh | 49 +++++++ .../pytorch/spr-maskrcnn-inference_spec.yml | 71 ++++++++++ .../pytorch/spr-maskrcnn-training_spec.yml | 67 ++++++++++ tools/scripts/model-builder | 6 + 31 files changed, 1199 insertions(+) create mode 100644 dockerfiles/pytorch/pytorch-spr-maskrcnn-inference.Dockerfile create mode 100644 dockerfiles/pytorch/pytorch-spr-maskrcnn-training.Dockerfile create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/container_build.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/datasets.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/description.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/docker_spr.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/license.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/quickstart.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/title.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/wrapper_package.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/README_SPR.md create mode 100755 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/accuracy.sh create mode 100755 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/build.sh create mode 100755 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/inference_realtime.sh create mode 100755 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/inference_throughput.sh create mode 100755 quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/run.sh create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/container_build.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/datasets.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/description.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/docker_spr.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/license.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/quickstart.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/title.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/wrapper_package.md create mode 100644 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/README_SPR.md create mode 100755 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/build.sh create mode 100755 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/run.sh create mode 100755 quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/training.sh create mode 100644 tools/docker/specs/centos/pytorch/spr-maskrcnn-inference_spec.yml create mode 100644 tools/docker/specs/centos/pytorch/spr-maskrcnn-training_spec.yml diff --git a/dockerfiles/pytorch/pytorch-spr-maskrcnn-inference.Dockerfile b/dockerfiles/pytorch/pytorch-spr-maskrcnn-inference.Dockerfile new file mode 100644 index 000000000..d2e69e3da --- /dev/null +++ b/dockerfiles/pytorch/pytorch-spr-maskrcnn-inference.Dockerfile @@ -0,0 +1,87 @@ +# Copyright (c) 2020-2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# +# THIS IS A GENERATED DOCKERFILE. +# +# This file was assembled from multiple pieces, whose use is documented +# throughout. Please refer to the TensorFlow dockerfiles documentation +# for more information. + +ARG PYTORCH_IMAGE="model-zoo" +ARG PYTORCH_TAG="pytorch-ipex-spr" + +FROM ${PYTORCH_IMAGE}:${PYTORCH_TAG} AS intel-optimized-pytorch + +# Build Torch Vision +ARG TORCHVISION_VERSION=v0.8.0 + +RUN source ~/anaconda3/bin/activate pytorch && \ + git clone https://github.com/pytorch/vision && \ + cd vision && \ + git checkout ${TORCHVISION_VERSION} && \ + python setup.py install + +RUN source ~/anaconda3/bin/activate pytorch && \ + pip install matplotlib Pillow pycocotools && \ + pip install yacs opencv-python cityscapesscripts transformers && \ + conda install -y libopenblas psutil && \ + cd /workspace/installs && \ + wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.7.90/gperftools-2.7.90.tar.gz && \ + tar -xzf gperftools-2.7.90.tar.gz && \ + cd gperftools-2.7.90 && \ + ./configure --prefix=$HOME/.local && \ + make && \ + make install && \ + rm -rf /workspace/installs/ + +ARG PACKAGE_DIR=model_packages + +ARG PACKAGE_NAME="pytorch-spr-maskrcnn-inference" + +ARG MODEL_WORKSPACE + +# ${MODEL_WORKSPACE} and below needs to be owned by root:root rather than the current UID:GID +# this allows the default user (root) to work in k8s single-node, multi-node +RUN umask 002 && mkdir -p ${MODEL_WORKSPACE} && chgrp root ${MODEL_WORKSPACE} && chmod g+s+w,o+s+r ${MODEL_WORKSPACE} + +ADD --chown=0:0 ${PACKAGE_DIR}/${PACKAGE_NAME}.tar.gz ${MODEL_WORKSPACE} + +RUN chown -R root ${MODEL_WORKSPACE}/${PACKAGE_NAME} && chgrp -R root ${MODEL_WORKSPACE}/${PACKAGE_NAME} && chmod -R g+s+w ${MODEL_WORKSPACE}/${PACKAGE_NAME} && find ${MODEL_WORKSPACE}/${PACKAGE_NAME} -type d | xargs chmod o+r+x + +WORKDIR ${MODEL_WORKSPACE}/${PACKAGE_NAME} + +ARG MASKRCNN_DIR="/workspace/pytorch-spr-maskrcnn-inference/models/maskrcnn" + +RUN source ~/anaconda3/bin/activate pytorch && \ + cd ${MASKRCNN_DIR} && \ + cd maskrcnn-benchmark && \ + python setup.py install && \ + pip install onnx + +FROM intel-optimized-pytorch AS release +COPY --from=intel-optimized-pytorch /root/anaconda3 /root/anaconda3 +COPY --from=intel-optimized-pytorch /workspace/lib/ /workspace/lib/ +COPY --from=intel-optimized-pytorch /root/.local/ /root/.local/ + +ENV DNNL_MAX_CPU_ISA="AVX512_CORE_AMX" + +ENV PATH="~/anaconda3/bin:${PATH}" +ENV LD_PRELOAD="/workspace/lib/jemalloc/lib/libjemalloc.so:$LD_PRELOAD" +ENV MALLOC_CONF="oversize_threshold:1,background_thread:true,metadata_thp:auto,dirty_decay_ms:9000000000,muzzy_decay_ms:9000000000" +ENV BASH_ENV=/root/.bash_profile +WORKDIR /workspace/ +RUN yum install -y numactl mesa-libGL && \ + yum clean all && \ + echo "source activate pytorch" >> /root/.bash_profile diff --git a/dockerfiles/pytorch/pytorch-spr-maskrcnn-training.Dockerfile b/dockerfiles/pytorch/pytorch-spr-maskrcnn-training.Dockerfile new file mode 100644 index 000000000..d1f4fe667 --- /dev/null +++ b/dockerfiles/pytorch/pytorch-spr-maskrcnn-training.Dockerfile @@ -0,0 +1,87 @@ +# Copyright (c) 2020-2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================ +# +# THIS IS A GENERATED DOCKERFILE. +# +# This file was assembled from multiple pieces, whose use is documented +# throughout. Please refer to the TensorFlow dockerfiles documentation +# for more information. + +ARG PYTORCH_IMAGE="model-zoo" +ARG PYTORCH_TAG="pytorch-ipex-spr" + +FROM ${PYTORCH_IMAGE}:${PYTORCH_TAG} AS intel-optimized-pytorch + +# Build Torch Vision +ARG TORCHVISION_VERSION=v0.8.0 + +RUN source ~/anaconda3/bin/activate pytorch && \ + git clone https://github.com/pytorch/vision && \ + cd vision && \ + git checkout ${TORCHVISION_VERSION} && \ + python setup.py install + +RUN source ~/anaconda3/bin/activate pytorch && \ + pip install matplotlib Pillow pycocotools && \ + pip install yacs opencv-python cityscapesscripts transformers && \ + conda install -y libopenblas psutil && \ + cd /workspace/installs && \ + wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.7.90/gperftools-2.7.90.tar.gz && \ + tar -xzf gperftools-2.7.90.tar.gz && \ + cd gperftools-2.7.90 && \ + ./configure --prefix=$HOME/.local && \ + make && \ + make install && \ + rm -rf /workspace/installs/ + +ARG PACKAGE_DIR=model_packages + +ARG PACKAGE_NAME="pytorch-spr-maskrcnn-training" + +ARG MODEL_WORKSPACE + +# ${MODEL_WORKSPACE} and below needs to be owned by root:root rather than the current UID:GID +# this allows the default user (root) to work in k8s single-node, multi-node +RUN umask 002 && mkdir -p ${MODEL_WORKSPACE} && chgrp root ${MODEL_WORKSPACE} && chmod g+s+w,o+s+r ${MODEL_WORKSPACE} + +ADD --chown=0:0 ${PACKAGE_DIR}/${PACKAGE_NAME}.tar.gz ${MODEL_WORKSPACE} + +RUN chown -R root ${MODEL_WORKSPACE}/${PACKAGE_NAME} && chgrp -R root ${MODEL_WORKSPACE}/${PACKAGE_NAME} && chmod -R g+s+w ${MODEL_WORKSPACE}/${PACKAGE_NAME} && find ${MODEL_WORKSPACE}/${PACKAGE_NAME} -type d | xargs chmod o+r+x + +WORKDIR ${MODEL_WORKSPACE}/${PACKAGE_NAME} + +ARG MASKRCNN_DIR="/workspace/pytorch-spr-maskrcnn-training/models/maskrcnn" + +RUN source ~/anaconda3/bin/activate pytorch && \ + cd ${MASKRCNN_DIR} && \ + cd maskrcnn-benchmark && \ + python setup.py install && \ + pip install onnx + +FROM intel-optimized-pytorch AS release +COPY --from=intel-optimized-pytorch /root/anaconda3 /root/anaconda3 +COPY --from=intel-optimized-pytorch /workspace/lib/ /workspace/lib/ +COPY --from=intel-optimized-pytorch /root/.local/ /root/.local/ + +ENV DNNL_MAX_CPU_ISA="AVX512_CORE_AMX" + +ENV PATH="~/anaconda3/bin:${PATH}" +ENV LD_PRELOAD="/workspace/lib/jemalloc/lib/libjemalloc.so:$LD_PRELOAD" +ENV MALLOC_CONF="oversize_threshold:1,background_thread:true,metadata_thp:auto,dirty_decay_ms:9000000000,muzzy_decay_ms:9000000000" +ENV BASH_ENV=/root/.bash_profile +WORKDIR /workspace/ +RUN yum install -y numactl mesa-libGL && \ + yum clean all && \ + echo "source activate pytorch" >> /root/.bash_profile diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/container_build.md b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/container_build.md new file mode 100644 index 000000000..537c5d40b --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/container_build.md @@ -0,0 +1,26 @@ +## Build the container + +The package has scripts and a Dockerfile that are +used to build a workload container that runs the model. This container +uses the PyTorch/IPEX container as it's base, so ensure that you have built +the `pytorch-ipex-spr.tar.gz` container prior to building this model container. + +Use `docker images` to verify that you have the base container built. For example: +``` +$ docker images | grep pytorch-ipex-spr +model-zoo pytorch-ipex-spr fecc7096a11e 40 minutes ago 8.31GB +``` + +To build the container, extract the package and +run the `build.sh` script. +``` +# Extract the package +tar -xzf +cd + +# Build the container +./build +``` + +After the build completes, you should have a container called +`` that will be used to run the model. diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/datasets.md b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/datasets.md new file mode 100644 index 000000000..7ba461afb --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/datasets.md @@ -0,0 +1,25 @@ +## Datasets + +The [COCO dataset](https://cocodataset.org) is used to run . +Download and extract the 2017 validation images and annotations from the +[COCO dataset website](https://cocodataset.org/#download) to a `coco` folder +and unzip the files. After extracting the zip files, your dataset directory +structure should look something like this: +``` +coco +├── annotations +│ ├── captions_train2017.json +│ ├── captions_val2017.json +│ ├── instances_train2017.json +│ ├── instances_val2017.json +│ ├── person_keypoints_train2017.json +│ └── person_keypoints_val2017.json +└── val2017 + ├── 000000000139.jpg + ├── 000000000285.jpg + ├── 000000000632.jpg + └── ... +``` +The parent of the `annotations` and `val2017` directory (in this example `coco`) +is the directory that should be used when setting the `DATASET_DIR` environment +variable for (for example: `export DATASET_DIR=/home//coco`). diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/description.md b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/description.md new file mode 100644 index 000000000..49f899094 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/description.md @@ -0,0 +1,5 @@ + +## Description + +This document has instructions for running using +Intel-optimized PyTorch. diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/docker_spr.md b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/docker_spr.md new file mode 100644 index 000000000..4dfe93a3e --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/docker_spr.md @@ -0,0 +1,32 @@ +## Run the model + +Download the pretrained model and set the `PRETRAINED_MODEL` environment variable +to point to the file. +``` +curl -O https://download.pytorch.org/models/maskrcnn/e2e_mask_rcnn_R_50_FPN_1x.pth +export PRETRAINED_MODEL=$(pwd)/e2e_mask_rcnn_R_50_FPN_1x.pth +``` + +After you've downloaded the pretrained model and followed the instructions to +[build the container](#build-the-container) and [prepare the dataset](#datasets), +use the `run.sh` script from the container package to run . +Set environment variables to specify the dataset directory, precision to run, and +an output directory. By default, the `run.sh` script will run the +`inference_realtime.sh` quickstart script. To run a different script, specify +the name of the script using the `SCRIPT` environment variable. +``` +# Navigate to the container package directory +cd + +# Set the required environment vars +export PRECISION= +export PRETRAINED_MODEL= +export DATASET_DIR= +export OUTPUT_DIR= + +# Run the container with inference_realtime.sh quickstart script +./run.sh + +# Specify a different quickstart script to run, for example, accuracy.sh +SCRIPT=accuracy.sh ./run.sh +``` diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/license.md b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/license.md new file mode 100644 index 000000000..e547f148d --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/license.md @@ -0,0 +1,4 @@ + +## License + +Licenses can be found in the model package, in the `licenses` directory. diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/quickstart.md b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/quickstart.md new file mode 100644 index 000000000..d4885a930 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/quickstart.md @@ -0,0 +1,8 @@ + +## Quick Start Scripts + +| Script name | Description | +|-------------|-------------| +| `inference_realtime.sh` | Runs multi instance realtime inference using 4 cores per instance for the specified precision (fp32, int8, or bf16). | +| `inference_throughput.sh` | Runs multi instance batch inference using 24 cores per instance for the specified precision (fp32, int8, or bf16). | +| `accuracy.sh` | Measures the inference accuracy for the specified precision (fp32, int8, or bf16). | diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/title.md b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/title.md new file mode 100644 index 000000000..a4ccbf863 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/title.md @@ -0,0 +1,2 @@ + +# PyTorch diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/wrapper_package.md b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/wrapper_package.md new file mode 100644 index 000000000..0d77199f3 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/wrapper_package.md @@ -0,0 +1,16 @@ +## Model Package + +The model package includes the Dockerfile and scripts needed to build and +run in a container. +``` + +├── README.md +├── build.sh +├── licenses +│   ├── LICENSE +│   └── third_party +├── model_packages +│   └── +├── .Dockerfile +└── run.sh +``` diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/README_SPR.md b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/README_SPR.md new file mode 100644 index 000000000..639386cdc --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/README_SPR.md @@ -0,0 +1,126 @@ + +# PyTorch Mask R-CNN inference + + +## Description + +This document has instructions for running Mask R-CNN inference using +Intel-optimized PyTorch. + +## Model Package + +The model package includes the Dockerfile and scripts needed to build and +run Mask R-CNN inference in a container. +``` +pytorch-spr-maskrcnn-inference +├── README.md +├── build.sh +├── licenses +│   ├── LICENSE +│   └── third_party +├── model_packages +│   └── pytorch-spr-maskrcnn-inference.tar.gz +├── pytorch-spr-maskrcnn-inference.Dockerfile +└── run.sh +``` + + +## Quick Start Scripts + +| Script name | Description | +|-------------|-------------| +| `inference_realtime.sh` | Runs multi instance realtime inference using 4 cores per instance for the specified precision (fp32, int8, or bf16). | +| `inference_throughput.sh` | Runs multi instance batch inference using 24 cores per instance for the specified precision (fp32, int8, or bf16). | +| `accuracy.sh` | Measures the inference accuracy for the specified precision (fp32, int8, or bf16). | + +## Datasets + +The [COCO dataset](https://cocodataset.org) is used to run Mask R-CNN inference. +Download and extract the 2017 validation images and annotations from the +[COCO dataset website](https://cocodataset.org/#download) to a `coco` folder +and unzip the files. After extracting the zip files, your dataset directory +structure should look something like this: +``` +coco +├── annotations +│ ├── captions_train2017.json +│ ├── captions_val2017.json +│ ├── instances_train2017.json +│ ├── instances_val2017.json +│ ├── person_keypoints_train2017.json +│ └── person_keypoints_val2017.json +└── val2017 + ├── 000000000139.jpg + ├── 000000000285.jpg + ├── 000000000632.jpg + └── ... +``` +The parent of the `annotations` and `val2017` directory (in this example `coco`) +is the directory that should be used when setting the `DATASET_DIR` environment +variable for Mask R-CNN (for example: `export DATASET_DIR=/home//coco`). + +## Build the container + +The Mask R-CNN inference package has scripts and a Dockerfile that are +used to build a workload container that runs the model. This container +uses the PyTorch/IPEX container as it's base, so ensure that you have built +the `pytorch-ipex-spr.tar.gz` container prior to building this model container. + +Use `docker images` to verify that you have the base container built. For example: +``` +$ docker images | grep pytorch-ipex-spr +model-zoo pytorch-ipex-spr fecc7096a11e 40 minutes ago 8.31GB +``` + +To build the Mask R-CNN inference container, extract the package and +run the `build.sh` script. +``` +# Extract the package +tar -xzf pytorch-spr-maskrcnn-inference.tar.gz +cd pytorch-spr-maskrcnn-inference + +# Build the container +./build +``` + +After the build completes, you should have a container called +`model-zoo:pytorch-spr-maskrcnn-inference` that will be used to run the model. + +## Run the model + +Download the pretrained model and set the `PRETRAINED_MODEL` environment variable +to point to the file. +``` +curl -O https://download.pytorch.org/models/maskrcnn/e2e_mask_rcnn_R_50_FPN_1x.pth +export PRETRAINED_MODEL=$(pwd)/e2e_mask_rcnn_R_50_FPN_1x.pth +``` + +After you've downloaded the pretrained model and followed the instructions to +[build the container](#build-the-container) and [prepare the dataset](#datasets), +use the `run.sh` script from the container package to run Mask R-CNN inference. +Set environment variables to specify the dataset directory, precision to run, and +an output directory. By default, the `run.sh` script will run the +`inference_realtime.sh` quickstart script. To run a different script, specify +the name of the script using the `SCRIPT` environment variable. +``` +# Navigate to the container package directory +cd pytorch-spr-maskrcnn-inference + +# Set the required environment vars +export PRECISION= +export PRETRAINED_MODEL= +export DATASET_DIR= +export OUTPUT_DIR= + +# Run the container with inference_realtime.sh quickstart script +./run.sh + +# Specify a different quickstart script to run, for example, accuracy.sh +SCRIPT=accuracy.sh ./run.sh +``` + + +## License + +Licenses can be found in the model package, in the `licenses` directory. + diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/accuracy.sh b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/accuracy.sh new file mode 100755 index 000000000..26a18b830 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/accuracy.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +MODEL_DIR=${MODEL_DIR-$PWD} + +echo "PRECISION: ${PRECISION}" +echo "OUTPUT_DIR: ${OUTPUT_DIR}" + +if [ -z "${OUTPUT_DIR}" ]; then + echo "The required environment variable OUTPUT_DIR has not been set" + exit 1 +fi + +# Create the output directory in case it doesn't already exist +mkdir -p ${OUTPUT_DIR} + +if [ -z "${PRECISION}" ]; then + echo "The required environment variable PRECISION has not been set" + echo "Please set PRECISION to fp32, int8, or bf16." + exit 1 +fi + +cd ${MODEL_DIR}/models/maskrcnn/maskrcnn-benchmark + +export work_space=${OUTPUT_DIR} + +if [[ $PRECISION == "int8" ]]; then + bash run_inference_cpu_accuracy.sh int8 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-inference-accuracy-int8.log +elif [[ $PRECISION == "bf16" ]]; then + bash run_inference_cpu_accuracy.sh bf16 jit 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-inference-accuracy-bf16.log +elif [[ $PRECISION == "fp32" ]]; then + bash run_inference_cpu_accuracy.sh fp32 jit 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-inference-accuracy-fp32.log +else + echo "The specified precision '${PRECISION}' is unsupported." + echo "Supported precisions are: fp32, bf16, and int8" + exit 1 +fi diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/build.sh b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/build.sh new file mode 100755 index 000000000..8175db45f --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/build.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -e + +PACKAGE_NAME=pytorch-spr-maskrcnn-inference +DOCKERFILE=pytorch-spr-maskrcnn-inference.Dockerfile +PYTORCH_BASE_IMAGE=${PYTORCH_BASE_IMAGE:-model-zoo} +PYTORCH_BASE_TAG=${PYTORCH_BASE_TAG:-pytorch-ipex-spr} +IMAGE_NAME=${IMAGE_NAME:-model-zoo:pytorch-spr-maskrcnn-inference} + +if [ "$(docker images -q ${PYTORCH_BASE_IMAGE}:${PYTORCH_BASE_TAG})" == "" ]; then + echo "The Intel(R) Extension for PyTorch container (${PYTORCH_BASE_IMAGE}:${PYTORCH_BASE_TAG}) was not found." + echo "This container is required, as it is used as the base for building the maskrcnn inference container." + echo "Please download the IPEX container package and build the image and then retry this build." + exit 1 +fi + +docker build --build-arg PYTORCH_IMAGE=model-zoo \ + --build-arg PYTORCH_TAG=pytorch-ipex-spr \ + --build-arg PACKAGE_NAME=$PACKAGE_NAME \ + --build-arg MODEL_WORKSPACE=/workspace \ + --build-arg MASKRCNN_DIR=/workspace/pytorch-spr-maskrcnn-inference/models/maskrcnn \ + --build-arg http_proxy=$http_proxy \ + --build-arg https_proxy=$https_proxy \ + --build-arg no_proxy=$no_proxy \ + -t $IMAGE_NAME \ + -f $DOCKERFILE . diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/inference_realtime.sh b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/inference_realtime.sh new file mode 100755 index 000000000..638fcb1b2 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/inference_realtime.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +MODEL_DIR=${MODEL_DIR-$PWD} + +echo "PRECISION: ${PRECISION}" +echo "OUTPUT_DIR: ${OUTPUT_DIR}" + +if [ -z "${OUTPUT_DIR}" ]; then + echo "The required environment variable OUTPUT_DIR has not been set" + exit 1 +fi + +# Create the output directory in case it doesn't already exist +mkdir -p ${OUTPUT_DIR} + +if [ -z "${PRECISION}" ]; then + echo "The required environment variable PRECISION has not been set" + echo "Please set PRECISION to fp32, int8, or bf16." + exit 1 +fi + +cd ${MODEL_DIR}/models/maskrcnn/maskrcnn-benchmark + +export work_space=${OUTPUT_DIR} + +if [[ $PRECISION == "int8" ]]; then + bash run_inference_cpu_multi_instance_latency.sh int8 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-inference-realtime-int8.log +elif [[ $PRECISION == "bf16" ]]; then + bash run_inference_cpu_multi_instance_latency.sh bf16 jit 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-inference-realtime-bf16.log +elif [[ $PRECISION == "fp32" ]]; then + bash run_inference_cpu_multi_instance_latency.sh fp32 jit 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-inference-realtime-fp32.log +else + echo "The specified precision '${PRECISION}' is unsupported." + echo "Supported precisions are: fp32, bf16, and int8" + exit 1 +fi diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/inference_throughput.sh b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/inference_throughput.sh new file mode 100755 index 000000000..34c382792 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/inference_throughput.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +MODEL_DIR=${MODEL_DIR-$PWD} + +echo "PRECISION: ${PRECISION}" +echo "OUTPUT_DIR: ${OUTPUT_DIR}" + +if [ -z "${OUTPUT_DIR}" ]; then + echo "The required environment variable OUTPUT_DIR has not been set" + exit 1 +fi + +# Create the output directory in case it doesn't already exist +mkdir -p ${OUTPUT_DIR} + +if [ -z "${PRECISION}" ]; then + echo "The required environment variable PRECISION has not been set" + echo "Please set PRECISION to fp32, int8, or bf16." + exit 1 +fi + +cd ${MODEL_DIR}/models/maskrcnn/maskrcnn-benchmark + +export work_space=${OUTPUT_DIR} + +if [[ $PRECISION == "int8" ]]; then + bash run_inference_cpu_multi_instance.sh int8 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-inference-throughput-int8.log +elif [[ $PRECISION == "bf16" ]]; then + bash run_inference_cpu_multi_instance.sh bf16 jit 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-inference-throughput-bf16.log +elif [[ $PRECISION == "fp32" ]]; then + bash run_inference_cpu_multi_instance.sh fp32 jit 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-inference-throughput-fp32.log +else + echo "The specified precision '${PRECISION}' is unsupported." + echo "Supported precisions are: fp32, bf16, and int8" + exit 1 +fi diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/run.sh b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/run.sh new file mode 100755 index 000000000..01be53705 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/run.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +if [ -z "${OUTPUT_DIR}" ]; then + echo "The required environment variable OUTPUT_DIR has not been set" + exit 1 +fi + +if [ -z "${PRECISION}" ]; then + echo "The required environment variable PRECISION has not been set" + exit 1 +fi + +if [ -z "${DATASET_DIR}" ]; then + echo "The required environment variable DATASET_DIR has not been set" + exit 1 +fi + +if [ -z "${PRETRAINED_MODEL}" ]; then + echo "The required environment variable PRETRAINED_MODEL has not been set" + exit 1 +fi + + +mkdir -p ${OUTPUT_DIR} + +IMAGE_NAME=${IMAGE_NAME:-model-zoo:pytorch-spr-maskrcnn-inference} +DOCKER_ARGS=${DOCKER_ARGS:---privileged --init -it} +WORKDIR=/workspace/pytorch-spr-maskrcnn-inference + +# inference scripts: +# inference_realtime.sh +# inference_throughput.sh +# accuracy.sh +export SCRIPT="${SCRIPT:-inference_realtime.sh}" + +if [[ ${SCRIPT} != quickstart* ]]; then + SCRIPT="quickstart/$SCRIPT" +fi + +docker run --rm \ + ${dataset_env} \ + --env PRECISION=${PRECISION} \ + --env OUTPUT_DIR=${OUTPUT_DIR} \ + --env http_proxy=${http_proxy} \ + --env https_proxy=${https_proxy} \ + --env no_proxy=${no_proxy} \ + --volume ${PRETRAINED_MODEL}:${WORKDIR}/models/maskrcnn/maskrcnn-benchmark/ImageNetPretrained/MSRA/e2e_mask_rcnn_R_50_FPN_1x.pth \ + --volume ${DATASET_DIR}:${WORKDIR}/models/maskrcnn/maskrcnn-benchmark/datasets/coco \ + --volume ${OUTPUT_DIR}:${OUTPUT_DIR} \ + -w ${WORKDIR} \ + ${DOCKER_ARGS} \ + $IMAGE_NAME \ + /bin/bash $SCRIPT diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/container_build.md b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/container_build.md new file mode 100644 index 000000000..537c5d40b --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/container_build.md @@ -0,0 +1,26 @@ +## Build the container + +The package has scripts and a Dockerfile that are +used to build a workload container that runs the model. This container +uses the PyTorch/IPEX container as it's base, so ensure that you have built +the `pytorch-ipex-spr.tar.gz` container prior to building this model container. + +Use `docker images` to verify that you have the base container built. For example: +``` +$ docker images | grep pytorch-ipex-spr +model-zoo pytorch-ipex-spr fecc7096a11e 40 minutes ago 8.31GB +``` + +To build the container, extract the package and +run the `build.sh` script. +``` +# Extract the package +tar -xzf +cd + +# Build the container +./build +``` + +After the build completes, you should have a container called +`` that will be used to run the model. diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/datasets.md b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/datasets.md new file mode 100644 index 000000000..1ed0be44d --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/datasets.md @@ -0,0 +1,30 @@ +## Datasets + +The [COCO dataset](https://cocodataset.org) is used to run +. Download and unzip the 2017 training and validation images and +annotations from the [COCO dataset website](https://cocodataset.org/#download) +to a `coco` folder and unzip the files. After extracting the zip files, +your dataset directory structure should look something like this: +``` +coco +├── annotations +│ ├── captions_train2017.json +│ ├── captions_val2017.json +│ ├── instances_train2017.json +│ ├── instances_val2017.json +│ ├── person_keypoints_train2017.json +│ └── person_keypoints_val2017.json +├── train2017 +│ ├── 000000000009.jpg +│ ├── 000000000025.jpg +│ ├── 000000000030.jpg +│ └── ... +└── val2017 + ├── 000000000139.jpg + ├── 000000000285.jpg + ├── 000000000632.jpg + └── ... +``` +The parent of the `annotations`, `val2017`, and `train2017` directory (in this +example `coco`) is the directory that should be used when setting the `DATASET_DIR` +environment variable for (for example: `export DATASET_DIR=/home//coco`). diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/description.md b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/description.md new file mode 100644 index 000000000..49f899094 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/description.md @@ -0,0 +1,5 @@ + +## Description + +This document has instructions for running using +Intel-optimized PyTorch. diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/docker_spr.md b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/docker_spr.md new file mode 100644 index 000000000..c76a8d5ef --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/docker_spr.md @@ -0,0 +1,19 @@ +## Run the model + +After you've followed the instructions to [build the container](#build-the-container) +and [prepare the dataset](#datasets), use the `run.sh` script from the container package +to run . Set environment variables to specify the dataset directory, +precision to run, and an output directory. The `run.sh` script will run the +`training.sh` quickstart script in the container. +``` +# Navigate to the container package directory +cd + +# Set the required environment vars +export PRECISION= +export DATASET_DIR= +export OUTPUT_DIR= + +# Run the container with training.sh quickstart script +./run.sh +``` diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/license.md b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/license.md new file mode 100644 index 000000000..e547f148d --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/license.md @@ -0,0 +1,4 @@ + +## License + +Licenses can be found in the model package, in the `licenses` directory. diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/quickstart.md b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/quickstart.md new file mode 100644 index 000000000..5824fc723 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/quickstart.md @@ -0,0 +1,6 @@ + +## Quick Start Scripts + +| Script name | Description | +|-------------|-------------| +| `training.sh` | Runs training for the specified precision (fp32 or bf16). | diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/title.md b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/title.md new file mode 100644 index 000000000..a4ccbf863 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/title.md @@ -0,0 +1,2 @@ + +# PyTorch diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/wrapper_package.md b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/wrapper_package.md new file mode 100644 index 000000000..0d77199f3 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/wrapper_package.md @@ -0,0 +1,16 @@ +## Model Package + +The model package includes the Dockerfile and scripts needed to build and +run in a container. +``` + +├── README.md +├── build.sh +├── licenses +│   ├── LICENSE +│   └── third_party +├── model_packages +│   └── +├── .Dockerfile +└── run.sh +``` diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/README_SPR.md b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/README_SPR.md new file mode 100644 index 000000000..c5c080b74 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/README_SPR.md @@ -0,0 +1,116 @@ + +# PyTorch Mask R-CNN training + + +## Description + +This document has instructions for running Mask R-CNN training using +Intel-optimized PyTorch. + +## Model Package + +The model package includes the Dockerfile and scripts needed to build and +run Mask R-CNN training in a container. +``` +pytorch-spr-maskrcnn-training +├── README.md +├── build.sh +├── licenses +│   ├── LICENSE +│   └── third_party +├── model_packages +│   └── pytorch-spr-maskrcnn-training.tar.gz +├── pytorch-spr-maskrcnn-training.Dockerfile +└── run.sh +``` + + +## Quick Start Scripts + +| Script name | Description | +|-------------|-------------| +| `training.sh` | Runs training for the specified precision (fp32 or bf16). | + +## Datasets + +The [COCO dataset](https://cocodataset.org) is used to run Mask R-CNN +training. Download and unzip the 2017 training and validation images and +annotations from the [COCO dataset website](https://cocodataset.org/#download) +to a `coco` folder and unzip the files. After extracting the zip files, +your dataset directory structure should look something like this: +``` +coco +├── annotations +│ ├── captions_train2017.json +│ ├── captions_val2017.json +│ ├── instances_train2017.json +│ ├── instances_val2017.json +│ ├── person_keypoints_train2017.json +│ └── person_keypoints_val2017.json +├── train2017 +│ ├── 000000000009.jpg +│ ├── 000000000025.jpg +│ ├── 000000000030.jpg +│ └── ... +└── val2017 + ├── 000000000139.jpg + ├── 000000000285.jpg + ├── 000000000632.jpg + └── ... +``` +The parent of the `annotations`, `val2017`, and `train2017` directory (in this +example `coco`) is the directory that should be used when setting the `DATASET_DIR` +environment variable for Mask R-CNN (for example: `export DATASET_DIR=/home//coco`). + +## Build the container + +The Mask R-CNN training package has scripts and a Dockerfile that are +used to build a workload container that runs the model. This container +uses the PyTorch/IPEX container as it's base, so ensure that you have built +the `pytorch-ipex-spr.tar.gz` container prior to building this model container. + +Use `docker images` to verify that you have the base container built. For example: +``` +$ docker images | grep pytorch-ipex-spr +model-zoo pytorch-ipex-spr fecc7096a11e 40 minutes ago 8.31GB +``` + +To build the Mask R-CNN training container, extract the package and +run the `build.sh` script. +``` +# Extract the package +tar -xzf pytorch-spr-maskrcnn-training.tar.gz +cd pytorch-spr-maskrcnn-training + +# Build the container +./build +``` + +After the build completes, you should have a container called +`model-zoo:pytorch-spr-maskrcnn-training` that will be used to run the model. + +## Run the model + +After you've followed the instructions to [build the container](#build-the-container) +and [prepare the dataset](#datasets), use the `run.sh` script from the container package +to run Mask R-CNN training. Set environment variables to specify the dataset directory, +precision to run, and an output directory. The `run.sh` script will run the +`training.sh` quickstart script in the container. +``` +# Navigate to the container package directory +cd pytorch-spr-maskrcnn-training + +# Set the required environment vars +export PRECISION= +export DATASET_DIR= +export OUTPUT_DIR= + +# Run the container with training.sh quickstart script +./run.sh +``` + + +## License + +Licenses can be found in the model package, in the `licenses` directory. + diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/build.sh b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/build.sh new file mode 100755 index 000000000..ad04aadb2 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/build.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +set -e + +PACKAGE_NAME=pytorch-spr-maskrcnn-training +DOCKERFILE=pytorch-spr-maskrcnn-training.Dockerfile +PYTORCH_BASE_IMAGE=${PYTORCH_BASE_IMAGE:-model-zoo} +PYTORCH_BASE_TAG=${PYTORCH_BASE_TAG:-pytorch-ipex-spr} +IMAGE_NAME=${IMAGE_NAME:-model-zoo:pytorch-spr-maskrcnn-training} + +if [ "$(docker images -q ${PYTORCH_BASE_IMAGE}:${PYTORCH_BASE_TAG})" == "" ]; then + echo "The Intel(R) Extension for PyTorch container (${PYTORCH_BASE_IMAGE}:${PYTORCH_BASE_TAG}) was not found." + echo "This container is required, as it is used as the base for building the maskrcnn training container." + echo "Please download the IPEX container package and build the image and then retry this build." + exit 1 +fi + +docker build --build-arg PYTORCH_IMAGE=model-zoo \ + --build-arg PYTORCH_TAG=pytorch-ipex-spr \ + --build-arg PACKAGE_NAME=$PACKAGE_NAME \ + --build-arg MODEL_WORKSPACE=/workspace \ + --build-arg MASKRCNN_DIR=/workspace/pytorch-spr-maskrcnn-training/models/maskrcnn \ + --build-arg http_proxy=$http_proxy \ + --build-arg https_proxy=$https_proxy \ + --build-arg no_proxy=$no_proxy \ + -t $IMAGE_NAME \ + -f $DOCKERFILE . diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/run.sh b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/run.sh new file mode 100755 index 000000000..6ee254c62 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/run.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +if [ -z "${OUTPUT_DIR}" ]; then + echo "The required environment variable OUTPUT_DIR has not been set" + exit 1 +fi + +if [ -z "${PRECISION}" ]; then + echo "The required environment variable PRECISION has not been set" + exit 1 +fi + +if [ -z "${DATASET_DIR}" ]; then + echo "The required environment variable DATASET_DIR has not been set" + exit 1 +fi + +mkdir -p ${OUTPUT_DIR} + +IMAGE_NAME=${IMAGE_NAME:-model-zoo:pytorch-spr-maskrcnn-training} +DOCKER_ARGS=${DOCKER_ARGS:---privileged --init -it} +WORKDIR=/workspace/pytorch-spr-maskrcnn-training + +# training scripts: +# training.sh +export SCRIPT="${SCRIPT:-training.sh}" + +if [[ ${SCRIPT} != quickstart* ]]; then + SCRIPT="quickstart/$SCRIPT" +fi + +docker run --rm \ + ${dataset_env} \ + --env PRECISION=${PRECISION} \ + --env OUTPUT_DIR=${OUTPUT_DIR} \ + --env http_proxy=${http_proxy} \ + --env https_proxy=${https_proxy} \ + --env no_proxy=${no_proxy} \ + --volume ${DATASET_DIR}:${WORKDIR}/models/maskrcnn/maskrcnn-benchmark/datasets/coco \ + --volume ${OUTPUT_DIR}:${OUTPUT_DIR} \ + -w ${WORKDIR} \ + ${DOCKER_ARGS} \ + $IMAGE_NAME \ + /bin/bash $SCRIPT diff --git a/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/training.sh b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/training.sh new file mode 100755 index 000000000..0bc0ab664 --- /dev/null +++ b/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/training.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +MODEL_DIR=${MODEL_DIR-$PWD} + +echo "PRECISION: ${PRECISION}" +echo "OUTPUT_DIR: ${OUTPUT_DIR}" + +if [ -z "${OUTPUT_DIR}" ]; then + echo "The required environment variable OUTPUT_DIR has not been set" + exit 1 +fi + +# Create the output directory in case it doesn't already exist +mkdir -p ${OUTPUT_DIR} + +if [ -z "${PRECISION}" ]; then + echo "The required environment variable PRECISION has not been set" + echo "Please set PRECISION to fp32 or bf16." + exit 1 +fi + +cd ${MODEL_DIR}/models/maskrcnn/maskrcnn-benchmark + +export work_space=${OUTPUT_DIR} + +if [[ $PRECISION == "bf16" ]]; then + bash run_training_cpu.sh bf16 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-training-bf16.log +elif [[ $PRECISION == "fp32" ]]; then + bash run_training_cpu.sh fp32 2>&1 | tee -a ${OUTPUT_DIR}/maskrcnn-training-fp32.log +else + echo "The specified precision '${PRECISION}' is unsupported." + echo "Supported precisions are: fp32 and bf16" + exit 1 +fi diff --git a/tools/docker/specs/centos/pytorch/spr-maskrcnn-inference_spec.yml b/tools/docker/specs/centos/pytorch/spr-maskrcnn-inference_spec.yml new file mode 100644 index 000000000..4e9bbaae9 --- /dev/null +++ b/tools/docker/specs/centos/pytorch/spr-maskrcnn-inference_spec.yml @@ -0,0 +1,71 @@ +releases: + versioned: + tag_specs: + - '{pytorch-multistage}{spr-maskrcnn-inference}' +slice_sets: + spr-maskrcnn-inference: + - add_to_name: -spr-maskrcnn-inference + dockerfile_subdirectory: pytorch + args: + - PYTORCH_IMAGE=model-zoo + - PYTORCH_TAG=pytorch-ipex-spr + - PACKAGE_NAME=pytorch-spr-maskrcnn-inference + - MASKRCNN_DIR=/workspace/pytorch-spr-maskrcnn-inference/models/maskrcnn + partials: + - pytorch/torch-vision-from-source + - pytorch/spr-model-installs + - model_package + - pytorch/models/maskrcnn-dependencies + - pytorch/spr-release-conda-env + - pytorch/spr-dnnl-max-var + - pytorch/spr-entrypoint + files: + - source: tools/docker/models/cpu-models/maskrcnn-ww32 + destination: models/maskrcnn + - source: quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/inference_realtime.sh + destination: quickstart/inference_realtime.sh + - source: quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/inference_throughput.sh + destination: quickstart/inference_throughput.sh + - source: quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/accuracy.sh + destination: quickstart/accuracy.sh + wrapper_package_files: + - source: output/pytorch-spr-maskrcnn-inference.tar.gz + destination: model_packages/pytorch-spr-maskrcnn-inference.tar.gz + - source: quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/build.sh + destination: build.sh + - source: quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/run.sh + destination: run.sh + - source: dockerfiles/pytorch/pytorch-spr-maskrcnn-inference.Dockerfile + destination: pytorch-spr-maskrcnn-inference.Dockerfile + - source: LICENSE + destination: licenses/LICENSE + - source: third_party + destination: licenses/third_party + - source: quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/README_SPR.md + destination: README.md + documentation: + - docs: + - name: Title + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/title.md + - name: Description + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/description.md + - name: Model Package + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/wrapper_package.md + - name: Quickstart + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/quickstart.md + - name: Datasets + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/datasets.md + - name: Container build + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/container_build.md + - name: Docker + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/docker_spr.md + - name: License + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu/.docs/license.md + name: README_SPR.md + text_replace: + : Mask R-CNN + : inference + : pytorch-spr-maskrcnn-inference.tar.gz + : pytorch-spr-maskrcnn-inference + : model-zoo:pytorch-spr-maskrcnn-inference + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/inference/cpu diff --git a/tools/docker/specs/centos/pytorch/spr-maskrcnn-training_spec.yml b/tools/docker/specs/centos/pytorch/spr-maskrcnn-training_spec.yml new file mode 100644 index 000000000..21dd56c3c --- /dev/null +++ b/tools/docker/specs/centos/pytorch/spr-maskrcnn-training_spec.yml @@ -0,0 +1,67 @@ +releases: + versioned: + tag_specs: + - '{pytorch-multistage}{spr-maskrcnn-training}' +slice_sets: + spr-maskrcnn-training: + - add_to_name: -spr-maskrcnn-training + dockerfile_subdirectory: pytorch + args: + - PYTORCH_IMAGE=model-zoo + - PYTORCH_TAG=pytorch-ipex-spr + - PACKAGE_NAME=pytorch-spr-maskrcnn-training + - MASKRCNN_DIR=/workspace/pytorch-spr-maskrcnn-training/models/maskrcnn + partials: + - pytorch/torch-vision-from-source + - pytorch/spr-model-installs + - model_package + - pytorch/models/maskrcnn-dependencies + - pytorch/spr-release-conda-env + - pytorch/spr-dnnl-max-var + - pytorch/spr-entrypoint + files: + - source: tools/docker/models/cpu-models/maskrcnn-ww32 + destination: models/maskrcnn + - source: quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/training.sh + destination: quickstart/training.sh + wrapper_package_files: + - source: output/pytorch-spr-maskrcnn-training.tar.gz + destination: model_packages/pytorch-spr-maskrcnn-training.tar.gz + - source: quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/build.sh + destination: build.sh + - source: quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/run.sh + destination: run.sh + - source: dockerfiles/pytorch/pytorch-spr-maskrcnn-training.Dockerfile + destination: pytorch-spr-maskrcnn-training.Dockerfile + - source: LICENSE + destination: licenses/LICENSE + - source: third_party + destination: licenses/third_party + - source: quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/README_SPR.md + destination: README.md + documentation: + - docs: + - name: Title + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/title.md + - name: Description + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/description.md + - name: Model Package + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/wrapper_package.md + - name: Quickstart + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/quickstart.md + - name: Datasets + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/datasets.md + - name: Container build + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/container_build.md + - name: Docker + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/docker_spr.md + - name: License + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu/.docs/license.md + name: README_SPR.md + text_replace: + : Mask R-CNN + : training + : pytorch-spr-maskrcnn-training.tar.gz + : pytorch-spr-maskrcnn-training + : model-zoo:pytorch-spr-maskrcnn-training + uri: models/quickstart/image_segmentation/pytorch/maskrcnn/training/cpu diff --git a/tools/scripts/model-builder b/tools/scripts/model-builder index 367761cee..5ca80bd14 100755 --- a/tools/scripts/model-builder +++ b/tools/scripts/model-builder @@ -138,8 +138,14 @@ _model_builder._build-imz-tf-tools() DOCKERIGNORE pushd $_dir 2>/dev/null 1>/dev/null docker build $_quiet $_proxy_build --tag imz-tf-tools:latest -f tools.Dockerfile . && echo '> Build successful' >&2 + docker_exit_code=$? rm -f .dockerignore popd 2>/dev/null 1>/dev/null + + if [[ $docker_exit_code != 0 ]]; then + echo "ERROR: Unable to build the imz-tf-tools container to run the assembler" + exit $docker_exit_code + fi } #