From 069666daf0f29dad68d46432c025f6a1bf0dae99 Mon Sep 17 00:00:00 2001 From: Xiaozhe Yao Date: Mon, 15 Oct 2018 21:31:24 +0800 Subject: [PATCH] add write package --- docs/en-US/guide/write-package.md | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/en-US/guide/write-package.md b/docs/en-US/guide/write-package.md index 12bf99259..2be5b9cd3 100644 --- a/docs/en-US/guide/write-package.md +++ b/docs/en-US/guide/write-package.md @@ -4,9 +4,49 @@ ### Project Structure +Your package is firstly a Python Package. Therefore, it will look like: + +``` +- example_package + - example_package + - solver.py + - bundle.py + - pretrained + - pretrained.toml + - tests // optional + - examples // optional + - cvpm.toml + - requirements.txt + - README.md +``` + ### Solvers +Solver is a ```class``` extended from ```cvpm.Solver``` class. In this class, you need to implement 2 functions: ```__init__``` and ```infer```. As their literal meanings, in the ```init``` function, parameters that your infer functions use should be initiate, and in the ```infer``` function, a image file path will be passed in the parameter, and the ```infer``` function is supposed to return your result in a dict or list. + +For example, a simple solver frame will look like + +``` python +from cvpm.solver import Solver + +class SampleSolver(Solver): + def __init__(self, toml_file=None): + super().__init__(toml_file) + # Do you Init Work here + self.classifer = get_classifier() + self.set_ready() + def infer(self, image_file, config): + # Use your own load_image method, or from cvpm.utility import load_image_file + image = load_image(image_file) + result = self.classifier(image) + return result +``` + ### Bundle + +::: tip 注意 请确保你的 Node.js 版本 >= 8。 ::: + + ### cvpm.toml @@ -27,4 +67,5 @@ Your README file should be look like ``` You can look at [Face Utility](https://github.com/cvmodel/Face_Utility) for reference that we provided as an official repository. + ## Best Practice \ No newline at end of file