- Create and activate a virtual environment that uses Python 3.12.
- Install PyTorch 2.5.1 (see this instruction).
- Install other dependencies: PIL 10.3.0, numpy 2.0.1, polars 1.21.0.
- (For server deployment) onnx, onnxscript (install with pip) and OpenVINO Model Server. To run the client code at
ovms/client
you would need Node.js and NPM.
See this 03_inference.ipynb for more.
Do these steps:
-
Install OpenVINO Model Server into the directory
ovms
of this repo (see the project's docs for instructions). -
Start the server:
# Make sure the working directory is ovms
ovms --port 9000 --rest_port 8000 --model_name catdog --model_path models/catdog
- After the server has been launched, run the client code
# Make sure the working directory is ovms/client
npm start ../../images/may-2.jpg
# Here "../../images/may-2.jpg" is simply the path to the image.
# Replace it with any images you want.
# This client code is a single Node.js script which only depends
# on sharp (see package.json), so it is portable.
How to train from scratch:
- Download the dataset from Microsoft Download Center (select English).
- Extract and put the dataset folder under
data/
. If success, there should be two folders,data/PetImages/Cat/
for cat images anddata/PetImages/Dog/
for dog images. - Run 01_training.ipynb to train the model on the training set and validates on the validation set.
- Run 02_evaluation.ipynb to evaluate the model on the testing set.
- (Optional) Export your PyTorch model to ONNX format (see 04_export_onnx.ipynb).
Images need to be preprocessed before fed to the model (see the image below). See the transform functions in 01_training.ipynb.
This is the plot of the losses and accuracy scores by epoch on the training and validation sets (see the image below).