This is an example showing how to run the ResNet50 model from PyTorch on AMD's integrated GPU. We will use Olive to convert the model to ONNX format, convert it to FP16 precision, and optimize it. We will then use DirectML execution provider to run the model on the iGPU.
Create a clone of the Ryzen AI installation conda environment to add required python packages
set RYZEN_AI_CONDA_ENV_NAME=ryzen-ai-1.3.0
conda create --name igpu-example --clone %RYZEN_AI_CONDA_ENV_NAME%
conda activate igpu-example
python -m pip install -r requirements.txt
python -m olive.workflows.run --config resnet50_config.json --setup
python -m olive.workflows.run --config resnet50_config.json
The optimized models will be available in ./torch_to_onnx-float16_conversion-perf_tuning/.
python predict.py
NOTE: In predict.py, line 15, the iGPU device ID is enumerated as 0. For PCs with multiple GPUs, you may adjust the device_id to target a specific iGPU.
- Visual Studio 2022 Community edition, ensure “Desktop Development with C++” is installed
- cmake (version >= 3.26)
- opencv (version=4.6.0) required for the resnet50 example
It is recommended to build OpenCV from the source code and use static build. The following instruction installs OpenCV in the location "C:\opencv" as an example, this can be changed by modifying CMAKE_PREFIX_PATH
in the following cmake command. You may first change the directory to where you want to clone the OpenCV repository.
git clone https://github.com/opencv/opencv.git -b 4.6.0
cd opencv
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_CONFIGURATION_TYPES=Release -A x64 -T host=x64 -G "Visual Studio 17 2022" "-DCMAKE_INSTALL_PREFIX=C:\opencv" "-DCMAKE_PREFIX_PATH=C:\opencv" -DCMAKE_BUILD_TYPE=Release -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DBUILD_WITH_STATIC_CRT=OFF -B build
cmake --build build --config Release
cmake --install build --config Release
The build files will be written to build\
.
Build the given ResNet50 C++ example:
cd cpp
compile.bat "path/to/your/opencv/build"
Run inference:
run.bat