Skip to content

Latest commit

 

History

History
140 lines (91 loc) · 5.36 KB

File metadata and controls

140 lines (91 loc) · 5.36 KB

Cartoonizer Using facial-cartoonizer model

The Cartoonizer example demonstrates real-time "cartoonization" of a video stream on the MemryX MX3 using an open-source model. This guide provides setup instructions, model details, and necessary code snippets to help you quickly get started.

Cartoonizer Example

Overview

Property Details
Model FacialCartoonization (https://github.com/SystemErrorWang/FacialCartoonization)
Model Type Cartoonizer
Framework ONNX
Model Source Download here
Pre-compiled DFP Download here
Model Resolution 512x512
Output cartoonized version of the input image
OS Linux, Windows
License License

Requirements

Linux

Before running the application, ensure that Python, OpenCV, and the required packages are installed. You can install OpenCV and the pyfakewebcam using the following commands:

pip install -r requirements.txt

Windows

On Windows, first make sure you have installed Python 3.11🔗

Then open the src/python_windows/ folder and double-click on setup_env.bat. The script will install all requirements automatically.

Running the Application

Step 1: Download Pre-compiled DFP

Windows

Download and place the .dfp file in the python_windows/models/ folder.

Linux

To download and unzip the precompiled DFPs, use the following commands:

wget https://developer.memryx.com/model_explorer/2p2/Facial_cartoonizer_512_512_3_onnx.zip
mkdir -p models
unzip Facial_cartoonizer_512_512_3_onnx.zip -d models
(Optional) Download and compile the model yourself If you prefer, you can download and compile the model rather than using the precompiled model. Download the pretrained model weights (weight.pth) from the FacialCartoonization GitHub repository
wget https://github.com/SystemErrorWang/FacialCartoonization/blob/master/weight.pth

To export the model to ONNX format:

  1. Run the following command:
python src/utils/generate_onnx.py
  1. This will generate the ONNX model inside the models/ directory.

  2. Change to the models directory:

cd models

You can now use the MemryX Neural Compiler to compile the model and generate the DFP file required by the accelerator:

mx_nc -v -m facial-cartoonizer_512.onnx --autocrop -c 4 --dfp_fname Facial_cartoonizer_512_512_3_onnx.dfp

Output: The MemryX compiler will generate dfp file:

  • facial-cartoonizer_512.dfp: The DFP file for the main section of the model.

Additional Notes:

  • -v: Enables verbose output, useful for tracking the compilation process.
  • --autocrop: This option ensures that any unnecessary parts of the ONNX model (such as pre/post-processing not required by the chip) are cropped out.

Step 2: Run the Script/Program

With the compiled model, you can now run real-time inference. Below are the examples of how to do this using Python.

To run the example for real-time Cartoonizer using MX3, follow these steps:

Simply execute the following command:

cd src/python/
python run_facial_cartoonizer.py

Command-line Options: You can specify the model path and DFP (Compiled Model) path using the following options:

  • -d or --dfp: Path to the compiled DFP file (default is models/Facial_cartoonizer_512_512_3_onnx.dfp) or the original model

Example: To run with a specific model and DFP file, use:

python run_facial_cartoonizer.py -d <dfp_path> 

If no arguments are provided, the script will use the default paths for the model and DFP.

Windows

On Windows, you can instead just double-click the run.bat file instead of invoking the python interpreter on the command line.

Third-Party Licenses

This project uses third-party software, models, and libraries. Below are the details of the licenses for these dependencies:

Summary

This guide offers a quick and easy way to run Cartoonizer using the facial-cartoonizer model on MemryX accelerators. You can use Python implementation to perform real-time inference. Download the full code and the pre-compiled DFP file to get started immediately.