### Install with mirror configurations Source: https://github.com/alibaba/pipcook/blob/main/docs/contributing/guide-to-contributor.md Use mirrors to speed up the installation of Python and packages. ```sh $ BOA_TUNA=1 npm install ``` ```bash $ export BOA_CONDA_MIRROR=https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda # this is for miniconda $ export BOA_CONDA_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple # this is for pip $ npm install ``` -------------------------------- ### Ava Unit Test Example Source: https://github.com/alibaba/pipcook/blob/main/docs/rfcs/0001-framework-migration.md Demonstrates unit testing with Ava, including array shuffling verification and mocking file system operations using Sinon. Requires setup for Ava and Sinon. ```javascript // ava import test from 'ava'; import * as fs from 'fs-extra'; import * as sinon from 'sinon'; import { shuffle } from './public'; test('array shuffle', (t) => { const array = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; shuffle(array); t.notDeepEqual(array, [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]); t.deepEqual(array.sort(), [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]); }); // serial hook test.serial.afterEach(() => { sinon.restore(); }); // serial case test.serial('test a', (t) => { const fsReadJsonMock = sinon.stub(fs, 'readJson').resolves({}); t.deepEqual(await fs.readJson('mockFileName.json'), {}); }); test.serial('test b', (t) => { const fsReadJsonMock = sinon.stub(fs, 'readJson').resolves(undefined); t.is(await fs.readJson('mockFileName.json'), undefined); }); test.todo('some todo cases'); ``` -------------------------------- ### Install Pipcook Client Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/contributing/contribute-a-script.md Install the Pipcook CLI globally to use Pipcook commands. ```sh $ npm install @pipcook/cli -g $ pipcook -v 2.0.0 ``` -------------------------------- ### Install Node.js model dependencies Source: https://github.com/alibaba/pipcook/blob/main/docs/manual/pipcook-models.md Navigate to the model directory and install required dependencies before usage. ```bash $ cd output/nodejs $ npm install # To install deps ``` -------------------------------- ### Install Pipcook CLI Source: https://context7.com/alibaba/pipcook/llms.txt Global installation of the Pipcook command-line tool via npm or Docker. ```bash # Install Pipcook CLI globally npm install -g @pipcook/cli # Verify installation pipcook --version # Alternative: Install via Docker docker pull pipcook/pipcook:latest docker run -it pipcook/pipcook:latest /bin/bash ``` -------------------------------- ### Build Pipcook from source Source: https://github.com/alibaba/pipcook/blob/main/docs/contributing/guide-to-contributor.md Install dependencies and compile the project. ```bash $ npm install $ npm run build ``` -------------------------------- ### Serve a Model Source: https://github.com/alibaba/pipcook/blob/main/docs/README.md Start a local server to serve the trained model. ```shell $ pipcook serve ./output ℹ preparing framework ℹ preparing scripts ℹ preparing artifact plugins ℹ initializing framework packages Pipcook has served at: http://localhost:9091 ``` -------------------------------- ### Install Dependencies with Tuna Mirror Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/contributing/guide-to-contributor.md Install dependencies using the Tuna mirror for faster downloads of Python and packages. ```bash $ BOA_TUNA=1 npm install ``` -------------------------------- ### Install Pipcook CLI Source: https://github.com/alibaba/pipcook/blob/main/docs/manual/pipcook-tools.md Install the Pipcook command-line interface globally using npm. ```sh $ npm install @pipcook/cli -g ``` -------------------------------- ### Install Dependencies with Custom Mirrors Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/contributing/guide-to-contributor.md Install dependencies specifying custom miniconda and Python index mirrors. ```bash $ export BOA_CONDA_MIRROR=https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda # this is for miniconda $ export BOA_CONDA_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple # this is for pip $ npm install ``` -------------------------------- ### Install Pipcook CLI Beta Version Source: https://github.com/alibaba/pipcook/blob/main/docs/meta/PROJECT_GUIDE.md Use this command to install the beta version of the Pipcook CLI globally. This provides access to the latest experimental features and bug fixes. ```bash $ npm install @pipcook/pipcook-cli@beta -g ``` ```bash $ npm install --tag beta @pipcook/pipcook-cli -g ``` -------------------------------- ### Installing Boa via npm Source: https://github.com/alibaba/pipcook/blob/main/docs/tutorials/using-python-functions-in-nodejs.md Command to install the Boa package independently. ```bash $ npm install @pipcook/boa ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/alibaba/pipcook/blob/main/README.md Install project dependencies using npm after cloning the repository. This command ensures all necessary packages are available. ```shell $ npm install ``` -------------------------------- ### Install Pipcook CLI Source: https://github.com/alibaba/pipcook/blob/main/notebooks/pipcook_image_classification.ipynb Installs the Pipcook CLI tool globally and creates a symbolic link for system-wide access. ```python !npm install @pipcook/cli -g !rm -f /usr/bin/pipcook !ln -s /usr/local/lib/nodejs/node-v12.19.0-linux-x64/bin/pipcook /usr/bin/pipcook ``` -------------------------------- ### Initialize Pipcook Environment Source: https://github.com/alibaba/pipcook/blob/main/notebooks/pipcook_object_detection.ipynb Downloads and installs Node.js 12.x and configures the system PATH for Pipcook operations. ```python !wget -P /tmp https://nodejs.org/dist/v12.19.0/node-v12.19.0-linux-x64.tar.xz !rm -rf /usr/local/lib/nodejs !mkdir -p /usr/local/lib/nodejs !tar -xJf /tmp/node-v12.19.0-linux-x64.tar.xz -C /usr/local/lib/nodejs !sh -c 'echo "export PATH=/usr/local/lib/nodejs/node-v12.19.0-linux-x64/bin:\$PATH" >> /etc/profile' !rm -f /usr/bin/node !rm -f /usr/bin/npm !ln -s /usr/local/lib/nodejs/node-v12.19.0-linux-x64/bin/node /usr/bin/node !ln -s /usr/local/lib/nodejs/node-v12.19.0-linux-x64/bin/npm /usr/bin/npm !npm config delete registry import os PATH_ENV = os.environ['PATH'] %env PATH=/usr/local/lib/nodejs/node-v12.19.0-linux-x64/bin:${PATH_ENV} ``` -------------------------------- ### Generate Arithmetic Data and Create Dataset Source: https://github.com/alibaba/pipcook/blob/main/docs/contributing/contribute-a-script.md A complete example showing data generation logic and the corresponding DataSource entry function. ```javascript /** * Generate examples. * * Each example consists of a question, e.g., '123+456' and and an * answer, e.g., '579'. * * @param digits Maximum number of digits of each operand of the * @param numExamples Number of examples to generate. * @param invert Whether to invert the strings in the question. * @returns The generated examples and digit array. */ function generateData(digits, numExamples, invert = false) { const digitArray = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; const arraySize = digitArray.length; const output = []; const maxLen = digits + 1 + digits; const f = () => { let str = ''; while (str.length < digits) { const index = Math.floor(Math.random() * arraySize); str += digitArray[index]; } return parseInt(str); }; const seen = new Set(); while (output.length < numExamples) { const a = f(); const b = f(); const sorted = b > a ? [a, b] : [b, a]; const key = sorted[0] + '`' + sorted[1]; if (seen.has(key)) { continue; } seen.add(key); // Pad the data with spaces such that it is always maxLen. const q = `${a}+${b}`; const query = q + ' '.repeat(maxLen - q.length); let ans = (a + b).toString(); // Answer can be of maximum size `digits + 1`. ans += ' '.repeat(digits + 1 - ans.length); if (invert) { throw new Error('invert is not implemented yet'); } output.push([query, ans]); } return output; } /** * This is the entry of datasource script */ module.exports = async (options, context) => { // 1 let { digits = '2', numExamples = '100' } = options; digits = parseInt(digits); numExamples = parseInt(numExamples); // 2 const dataCook = context.dataCook; // 3 const data = generateData(digits, numExamples); const split = Math.floor(numExamples * 0.9); const trainData = data.slice(0, split).map(item => ({ label: item[1], data: item[0] })); const testData = data.slice(split).map(item => ({ label: item[1], data: item[0] })); // 4 const meta = { type: dataCook.Dataset.Types.DatasetType.General, size: { test: testData.length, train: trainData.length } }; // 5 return dataCook.Dataset.makeDataset({ trainData, testData }, meta); }; ``` -------------------------------- ### Install Pipcook CLI Source: https://github.com/alibaba/pipcook/blob/main/notebooks/pipcook_object_detection.ipynb Installs the Pipcook command-line interface globally via npm and creates a symbolic link. ```python !npm install @pipcook/cli -g --unsafe-perm !rm -f /usr/bin/pipcook !ln -s /usr/local/lib/nodejs/node-v12.19.0-linux-x64/bin/pipcook /usr/bin/pipcook ``` -------------------------------- ### Pipcook Pipeline Schema v2.0 Example Source: https://github.com/alibaba/pipcook/blob/main/docs/rfcs/0000-new-pipeline.md This example demonstrates a typical Pipcook pipeline configuration using the v2.0 schema, showcasing the array-based 'plugins' structure with various plugin types and their parameters. ```json { "$id": "http://alibaba.github.io/pipcook/pipeline-2.0.json", "$schema": "http://json-schema.org/draft-07/schema", "default": {}, "description": "The root schema comprises the entire JSON document.", "examples": [ { "specVersion": "2.0", "plugins": [ { "type": "dataCollect", "package": "@pipcook/plugins-chinese-poem-data-collect", "params": { "url": "foobar" } }, { "type": "dataAccess", "package": "@pipcook/plugins-textline-data-access" }, { "type": "dataProcess", "package": "@pipcook/plugins-textline-data-process", "params": { "arg1": "foobar" } }, { "type": "dataProcess", "package": "@pipcook/plugins-textline-data-process", "params": { "arg2": "foobar" } }, { "type": "modelDefine", "package": "@pipcook/plugins-tfjs-text-lstm-model-define" }, { "type": "modelTrain", "package": "@pipcook/plugins-tfjs-text-lstm-model-train", "params": { "epochs": 200 } }, { "type": "modelEvaluate", "package": "@pipcook/plugins-tfjs-text-lstm-model-evaluate" }, { "type": "deploy", "package": "@pipcook/plugins-nodejs-deploy-aws-ec2", "params": { "key": "..." } } ] } ], "required": [ "plugins" ], "title": "The JSON schema for Pipcook Pipeline.", "type": "object", "properties": { "specVersion": { "$id": "#/properties/specVersion", "type": "string", "title": "The version schema", "description": "The pipeline spec version", "default": "", "examples": [ "2.0" ] }, "plugins": { "$id": "#/properties/plugins", "type": "array", "title": "The plugins schema", "description": "An explanation about the purpose of this instance.", "additionalItems": false, "items": { "$id": "#/properties/plugins/items", "anyOf": [ { "$id": "#/properties/plugins/items/data-collect", "required": [ "type", "package" ], "title": "a type of plugin to collect the dataset from the source url.", "type": "object", "minItems": 1, "maxItems": 1, "properties": { "type": { "enum": [ "dataCollect" ], "type": "string" }, "package": { "type": "string", "title": "The package uri of the plugin", "default": "" }, "params": { "default": {}, "title": "The params of the plugin", "type": "object", "properties": { "url": { "type": "string", "title": "the data source url.", "optional": true } }, "additionalProperties": true } }, "additionalProperties": true }, { "$id": "#/properties/plugins/items/data-access", "required": [ "type", "package" ], "title": "a type of plugin to create the common `UniDataset` object.", "type": "object", "minItems": 1, "maxItems": 1, "properties": { "type": { "enum": [ "dataAccess" ], "type": "string" }, "package": { "type": "string", "title": "The package uri of the plugin", "default": "" }, "params": { "default": {}, "title": "The params of the plugin", "type": "object", "additionalProperties": true } }, "additionalProperties": true }, { "$id": "#/properties/plugins/items/data-process", "required": [ "type", "package" ], "title": "a type of plugin to process the sample/example in the `UniDataset`.", "type": "object", "minItems": 0, "properties": { "type": { "enum": [ "dataProcess" ], "type": "string" }, "package": { "type": "string", "title": "The package uri of the plugin", "default": "" }, "params": { "default": {}, "title": "The params of the plugin", "type": "object", "properties": { "arg1": { "type": "string", "optional": true }, "arg2": { "type": "string", "optional": true } }, "additionalProperties": true } }, "additionalProperties": true }, { "$id": "#/properties/plugins/items/model-define", "required": [ "type", "package" ], "title": "a type of plugin to define the model.", "type": "object", "minItems": 1, "maxItems": 1, "properties": { "type": { "enum": [ "modelDefine" ], "type": "string" }, "package": { "type": "string", "title": "The package uri of the plugin", "default": "" }, "params": { "default": {}, "title": "The params of the plugin", "type": "object", "additionalProperties": true } }, "additionalProperties": true }, { "$id": "#/properties/plugins/items/model-train", "required": [ "type", "package" ], "title": "a type of plugin to train the model.", "type": "object", "minItems": 1, "maxItems": 1, "properties": { "type": { "enum": [ "modelTrain" ], "type": "string" }, "package": { "type": "string", "title": "The package uri of the plugin", "default": "" }, "params": { "default": {}, "title": "The params of the plugin", "type": "object", "properties": { "epochs": { "type": "integer", "title": "the number of epochs to train the model.", "optional": true } }, "additionalProperties": true } }, "additionalProperties": true }, { "$id": "#/properties/plugins/items/model-evaluate", "required": [ "type", "package" ], "title": "a type of plugin to evaluate the model.", "type": "object", "minItems": 1, "maxItems": 1, "properties": { "type": { "enum": [ "modelEvaluate" ], "type": "string" }, "package": { "type": "string", "title": "The package uri of the plugin", "default": "" }, "params": { "default": {}, "title": "The params of the plugin", "type": "object", "additionalProperties": true } }, "additionalProperties": true }, { "$id": "#/properties/plugins/items/deploy", "required": [ "type", "package" ], "title": "a type of plugin to deploy the model.", "type": "object", "minItems": 1, "maxItems": 1, "properties": { "type": { "enum": [ "deploy" ], "type": "string" }, "package": { "type": "string", "title": "The package uri of the plugin", "default": "" }, "params": { "default": {}, "title": "The params of the plugin", "type": "object", "properties": { "key": { "type": "string", "optional": true } }, "additionalProperties": true } }, "additionalProperties": true } ] } } } } ``` -------------------------------- ### Install Pipcook via NPM Source: https://github.com/alibaba/pipcook/blob/main/docs/INSTALL.md Use this command to install Pipcook globally via NPM. This is the recommended method for most users. ```sh $ npm install -g @pipcook/cli ``` -------------------------------- ### Framework Directory Structure Example Source: https://github.com/alibaba/pipcook/blob/main/docs/manual/intro-to-framework.md This is a typical directory structure for a Pipcook framework package, including the framework description file, initialization script, and node_modules. ```sh ├── framework.json ├── index.js └── node_modules ``` -------------------------------- ### Pipcook Working Directory Structure Source: https://github.com/alibaba/pipcook/blob/main/docs/manual/intro-to-pipeline.md Example of the directory structure generated after pipeline execution. ```text ├── pipeline-config.json ├── cache ├── data ├── framework ├── model └── scripts ``` -------------------------------- ### Install Python Packages for Boa Source: https://context7.com/alibaba/pipcook/llms.txt Manage Python dependencies using the 'bip' wrapper and configure PYTHONPATH for custom environments. ```bash # Install Python packages using bip (Boa's pip wrapper) ./node_modules/.bin/bip install numpy ./node_modules/.bin/bip install tensorflow ./node_modules/.bin/bip install scikit-learn ./node_modules/.bin/bip install pandas # For virtualenv or conda users, set PYTHONPATH export PYTHONPATH=/Users/venv/lib/python3.7/site-packages # Then use in JavaScript const boa = require('@pipcook/boa'); const np = boa.import('numpy'); const sklearn = boa.import('sklearn'); ``` -------------------------------- ### Install Python Packages with bip Source: https://github.com/alibaba/pipcook/blob/main/docs/manual/intro-to-boa.md Use the 'bip' command, an alias for pip, to install Python packages within the Boa-managed conda environment. ```sh ./node_modules/.bin/bip install ``` -------------------------------- ### Jasmine Unit Test Example Source: https://github.com/alibaba/pipcook/blob/main/docs/rfcs/0001-framework-migration.md Illustrates unit testing with Jasmine, focusing on verifying array shuffling. This example uses Jasmine's `describe` and `it` syntax. ```javascript // jasmine import { shuffle } from './public'; describe('public utils', () => { it('test if the array is shuffled', () => { const array = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; shuffle(array); expect(array).not.toEqual([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]); expect(array.sort()).toEqual([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]); }); } ``` -------------------------------- ### Training Log Output Source: https://github.com/alibaba/pipcook/blob/main/docs/tutorials/component-image-classification.md Example of the console output generated during the model training process, showing epoch progress, loss, and accuracy metrics. ```text Epoch 1/15 187/187 [==============================] - 12s 65ms/step - loss: 0.0604 - accuracy: 0.9823 - val_loss: 8.8755 - val_accuracy: 0.4112 Epoch 2/15 187/187 [==============================] - 11s 61ms/step - loss: 0.0056 - accuracy: 0.9993 - val_loss: 5.5883 - val_accuracy: 0.4925 Epoch 3/15 187/187 [==============================] - 11s 59ms/step - loss: 0.0107 - accuracy: 0.9980 - val_loss: 0.3830 - val_accuracy: 0.8388 ... 187/187 [==============================] - 11s 61ms/step - loss: 3.0090e-05 - accuracy: 1.0000 - val_loss: 1.5646e-08 - val_accuracy: 1.0000 Epoch 14/15 187/187 [==============================] - 11s 61ms/step - loss: 5.1657e-05 - accuracy: 1.0000 - val_loss: 1.9073e-08 - val_accuracy: 1.0000 Epoch 15/15 187/187 [==============================] - 11s 61ms/step - loss: 5.1657e-05 - accuracy: 1.0000 - val_loss: 1.9073e-08 - val_accuracy: 1.0000 ``` -------------------------------- ### PascalVOC XML Annotation Example Source: https://github.com/alibaba/pipcook/blob/main/docs/spec/dataset.md An example of an XML file used for annotating image data in the PascalVOC format. It includes details like folder, filename, image size, and object bounding boxes. ```xml folder path image name width height category name left top right bottom ``` -------------------------------- ### Build Pipcook Project Source: https://github.com/alibaba/pipcook/blob/main/README.md Build the Pipcook project after installing dependencies. This command compiles the project for development or production use. ```shell $ npm run build ``` -------------------------------- ### Creating a TensorFlow model in Node.js Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/tutorials/using-python-functions-in-nodejs.md Shows how to import TensorFlow.js and define a Keras model by inheriting from Python's Model class. This example highlights the use of boa.kwargs() for specifying activation functions in layers. ```javascript const boa = require('@pipcook/boa'); const tf = boa.import('tensorflow'); const { layers, Model } = tf.keras; class TestModel extends Model { constructor() { super(); this.conv1 = layers.Conv2D(32, 3, boa.kwargs({ activation: 'relu' })); this.flatten = layers.Flatten(); this.d1 = layers.Dense(128, boa.kwargs({ activation: 'relu' })); this.d2 = layers.Dense(10, boa.kwargs({ activation: 'softmax' })); } call(x) { return this.conv1(x) .flatten(x) .d1(x).d2(x); } } ``` -------------------------------- ### Pull Pipcook Docker Image Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/INSTALL.md Download the latest Pipcook Docker image from the Alibaba source repository. This is an alternative installation method. ```sh $ docker pull registry.cn-beijing.aliyuncs.com/pipcook/pipcook:latest ``` -------------------------------- ### Execute Training Pipeline Source: https://github.com/alibaba/pipcook/blob/main/docs/tutorials/component-image-classification.md Command to initiate the training process using a specified configuration file and output directory. ```shell $ pipcook run image-classification.json --output ./classification ``` -------------------------------- ### Serve Pipcook Model Source: https://github.com/alibaba/pipcook/blob/main/README.md Serve a trained Pipcook model for deployment. This command prepares the framework, scripts, and plugins, then initializes the packages. ```shell $ pipcook serve ./output ``` -------------------------------- ### Create VS Code Launch Configuration Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/contributing/contribute-a-script.md Set up a launch.json file in VS Code to enable debugging of Pipcook run commands. ```json { "version": "0.2.0", "configurations": [ { "type": "pwa-node", "request": "launch", "name": "Launch Program", "skipFiles": [ "/**" ], "runtimeExecutable": "pipcook", "runtimeArgs": [ "run", "${workspaceFolder}/debug/addition-rnn.json", "--output", "${workspaceFolder}/debug/workspace" ] } ] } ``` -------------------------------- ### 配置 Pipcook 安装源 Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/faq/pipcook-framework.md 通过 pipcook init 命令指定 npm 客户端或使用清华源以加速安装过程。 ```bash pipcook init -c ``` ```bash pipcook init --tuna ``` -------------------------------- ### Pipcook Run Help Source: https://github.com/alibaba/pipcook/blob/main/docs/manual/pipcook-tools.md Display help information for the 'pipcook run' command to see available options. ```sh $ pipcook run --help ``` -------------------------------- ### Check Pipcook Version Source: https://github.com/alibaba/pipcook/blob/main/notebooks/pipcook_object_detection.ipynb Verifies that the Pipcook CLI is installed correctly by checking its version. ```python !sudo pipcook -v ``` -------------------------------- ### Run tests Source: https://github.com/alibaba/pipcook/blob/main/docs/contributing/guide-to-contributor.md Execute the test suite for the entire project or specific packages. ```bash $ npm test ``` ```bash $ ./node_modules/.bin/lerna run --scope ``` -------------------------------- ### Create VS Code Debug Configuration Files Source: https://github.com/alibaba/pipcook/blob/main/docs/contributing/contribute-a-script.md Create the .vscode directory and the launch.json file for debugging in VS Code. ```sh $ mkdir .vscode $ touch .vscode/launch.json ``` -------------------------------- ### Python Generator Example Source: https://github.com/alibaba/pipcook/blob/main/docs/manual/intro-to-boa.md A Python generator function that counts down from a given number to zero, yielding each number. ```python def count_down(count): while count >= 0: yield count count -= 1 ``` -------------------------------- ### Pull Pipcook Docker Image Source: https://github.com/alibaba/pipcook/blob/main/docs/INSTALL.md Download the latest Pipcook Docker image. Ensure Docker is installed and running. ```sh $ docker pull pipcook/pipcook:latest ``` -------------------------------- ### Specify GPU for Training Source: https://github.com/alibaba/pipcook/blob/main/docs/faq/plugins.md Set the CUDA_VISIBLE_DEVICES environment variable to the desired GPU index before starting the Pipcook daemon. ```bash $CUDA_VISIBLE_DEVICES ``` -------------------------------- ### Implement a Basic DataSource Script Source: https://github.com/alibaba/pipcook/blob/main/docs/contributing/contribute-a-script.md A template for a DataSource script entry function using the datacook context to create a dataset. ```javascript /* * This is the entry of datasource script */ module.exports = async (options, context) => { let { // options from query, note that their types are `srting` or `string[]` } = options; // should get the instance of datacook from context const dataCook = context.dataCook; dataCook = context.dataCook; /** * create dataset here */ const trainData = [ { label: 'label-1', data: 'data-1' }, { label: 'label-2', data: 'data-2' } ]; const testData = [ { label: 'label-1', data: 'data-1' }, { label: 'label-2', data: 'data-2' } ]; const meta = { type: dataCook.Dataset.Types.DatasetType.General, size: { test: testData.length, train: trainData.length } }; return dataCook.Dataset.makeDataset({ trainData, testData }, meta); }; ``` -------------------------------- ### Get Python Built-in Functions Source: https://github.com/alibaba/pipcook/blob/main/docs/manual/intro-to-boa.md Access Python's built-in functions like 'len' and 'range' through boa.builtins(). ```javascript const { len, range } = boa.builtins(); len([1, 2, 3]); // 3 len(range(0, 10)); // 10 ``` -------------------------------- ### Importing OS module and using its functions in Node.js Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/tutorials/using-python-functions-in-nodejs.md Demonstrates importing the 'os' Python module using boa.import() and calling its functions like getpid(). It also shows how to use boa.kwargs() for keyword arguments when calling Python functions like os.makedirs(). ```javascript const boa = require('@pipcook/boa'); const os = boa.import('os'); console.log(os.getpid()); // prints the pid from python. // using keyword arguments namely \`kwargs\` os.makedirs('..', boa.kwargs({ mode: 0x777, exist_ok: false, })); // using bult-in functions const { range, len } = boa.builtins(); const list = range(0, 10); // create a range array console.log(len(list)); // 10 console.log(list[2]); // 2 ``` -------------------------------- ### Configure YOLO Training Options Source: https://github.com/alibaba/pipcook/blob/main/example/pipelines/README-CN.md Define training parameters including batch size, epochs, and early-stopping patience. ```json { "options": { "framework": "tfjs@3.8", "gpu": false, "train": { "epochs": 100, "batchSize": 16, "patience": 10 } } } ``` -------------------------------- ### Configure Object Detection Pipeline (YOLO) Source: https://context7.com/alibaba/pipcook/llms.txt Sets up a pipeline for object detection using the YOLO architecture. Specify the datasource, dataflow scripts, model, and training options. ```json { "specVersion": "2.0", "type": "ObjectDetection", "datasource": "https://cdn.jsdelivr.net/gh/imgcook/pipcook-script@9d210de/scripts/object-detection-yolo/build/datasource.js?format=pascalvoc&url=https://pipcook-cloud.oss-cn-hangzhou.aliyuncs.com/dataset/mask.zip", "dataflow": [ "https://cdn.jsdelivr.net/gh/imgcook/pipcook-script@9d210de/scripts/object-detection-yolo/build/dataflow.js?size=416&size=416" ], "model": "https://cdn.jsdelivr.net/gh/imgcook/pipcook-script@9d210de/scripts/object-detection-yolo/build/model.js", "options": { "framework": "tfjs@3.8", "train": { "epochs": 100, "batchSize": 16, "patience": 10 } } } ``` -------------------------------- ### CSV Format for Text Classification Source: https://context7.com/alibaba/pipcook/llms.txt Example of a CSV file used for text classification tasks. Each row contains a text sample and its corresponding category label. ```csv name,category "This product is amazing",positive "Terrible quality, do not buy",negative "Average product, nothing special",neutral "Highly recommended!",positive "Complete waste of money",negative ``` -------------------------------- ### Simplified Data Source Configuration Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/contributing/contribute-a-script.md When using the 'file' protocol for data sources in a pipeline, the protocol header can be omitted. ```json { "datasource": "/data/my-datasource.js" } ``` -------------------------------- ### Run Pipcook Docker Container Source: https://github.com/alibaba/pipcook/blob/main/docs/INSTALL.md Start an interactive terminal session within the Pipcook Docker container. This allows you to run Pipcook commands inside the isolated environment. ```sh $ docker run -it pipcook/pipcook:latest /bin/bash ``` -------------------------------- ### PascalVOC XML Annotation for Object Detection Source: https://context7.com/alibaba/pipcook/llms.txt Example of an XML file structured in PascalVOC format for object detection tasks. It includes image metadata and bounding box annotations for objects. ```xml images image_name.jpg 800 600 button 100 150 200 180 input 50 200 300 230 ``` -------------------------------- ### Specify Dataset Format (Local Path) Source: https://github.com/alibaba/pipcook/blob/main/example/pipelines/README.md Configure the datasource to use a local dataset directory with the PascalVoc format. The 'url' parameter is set to 'file://' followed by the local path. ```json { "datasource": "https://cdn.jsdelivr.net/gh/imgcook/pipcook-script@9d210de/scripts/object-detection-yolo/build/datasource.js?format=pascalvoc&url=file:///path/to/dataset-directory" } ``` -------------------------------- ### Serve Models via HTTP Source: https://context7.com/alibaba/pipcook/llms.txt Deploy trained models as REST APIs for real-time predictions, with options for custom ports and debugging. ```bash # Serve model on default port 9091 pipcook serve ./output # Output: # ℹ preparing framework # ℹ preparing scripts # ℹ preparing artifact plugins # ℹ initializing framework packages # Pipcook has served at: http://localhost:9091 # Serve on custom port pipcook serve ./output --port 8080 # Serve with debug mode pipcook serve ./model-workspace --port 3000 --debug # Test the prediction endpoint (for image classification) curl -X POST http://localhost:9091/predict \ -F "file=@./test-image.jpg" ``` -------------------------------- ### Python Functions in Node.js Worker Threads Source: https://github.com/alibaba/pipcook/blob/main/docs/manual/intro-to-boa.md Example demonstrating how to run Python functions in a separate Node.js worker thread using '@pipcook/boa' and 'worker_threads'. This allows non-blocking execution of Python code. ```javascript const { Worker, isMainThread, workerData, parentPort } = require('worker_threads'); const boa = require('@pipcook/boa'); const pybasic = boa.import('tests.base.basic'); // a Python example const { SharedPythonObject, symbols } = boa; class Foobar extends pybasic.Foobar { hellomsg(x) { return `hello <${x}> on ${this.test}(${this.count})`; } } if (isMainThread) { const foo = new Foobar(); const worker = new Worker(__filename, { workerData: { foo: new SharedPythonObject(foo), }, }); let alive = setInterval(() => { const ownership = foo[symbols.GetOwnershipSymbol](); console.log(`ownership should be ${expectedOwnership}.`); }, 1000); worker.on('message', state => { if (state === 'done') { console.log('task is completed'); setTimeout(() => { clearInterval(alive); console.log(foo.ping('x')); }, 1000); } }); } else { const { foo } = workerData; console.log(`worker: get an object${foo} and sleep 5s in Python`); foo.sleep(); // this is a blocking function which is implemented at Python to sleep 1s console.log('python sleep is done, and sleep in nodejs(thread)'); setTimeout(() => parentPort.postMessage('done'), 1000); } ``` -------------------------------- ### Import Python Modules with Boa Source: https://context7.com/alibaba/pipcook/llms.txt Demonstrates importing and using Python modules like 'os', 'numpy', and 're' directly within Node.js using the Boa Python bridge. Ensure '@pipcook/boa' is installed. ```javascript const boa = require('@pipcook/boa'); // Import Python system modules const os = boa.import('os'); console.log(os.getpid()); // prints the pid from python // Import third-party Python packages const np = boa.import('numpy'); const tf = boa.import('tensorflow'); // Create numpy arrays const arr = np.array([[1, 2, 3], [4, 5, 6]], np.int32); console.log(arr[0]); // 1 // Reshape arrays const x1 = np.arange(15).reshape(3, 5); console.log(x1.shape); // (3, 5) // Use regex module const re = boa.import('re'); const m = re.search('(?<=abc)def', 'abcdef'); console.log(m.group(0)); // 'def' ``` -------------------------------- ### Run Node.js with experimental loaders Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/manual/intro-to-boa.md Commands to execute Node.js applications using the Pipcook Boa ESM loader. ```bash $ node --experimental-loader @pipcook/boa/esm/loader.mjs app.mjs ``` ```bash $ node --experimental-modules --experimental-loader @pipcook/boa/esm/loader.mjs app.mjs ``` -------------------------------- ### Clone the Pipcook repository Source: https://github.com/alibaba/pipcook/blob/main/docs/contributing/guide-to-contributor.md Initial step to obtain the source code from GitHub. ```bash $ git clone git@github.com:alibaba/pipcook.git ``` -------------------------------- ### Dataset Directory Structure for PascalVOC Source: https://context7.com/alibaba/pipcook/llms.txt Illustrates the expected directory layout for datasets using the PascalVOC format, including separate folders for annotations and images. ```tree dataset/ ├── annotations/ │ ├── train/ │ │ └── image_name.xml │ ├── validation/ │ └── test/ └── images/ └── image_name.jpg ``` -------------------------------- ### Text Dataset CSV Format Example Source: https://github.com/alibaba/pipcook/blob/main/docs/spec/dataset.md This shows the standard CSV format for text datasets in Pipcook. The first column contains the text content, and the second column specifies the category, with ',' as the delimiter and no header row. ```csv name, category prod1, type1 prod2, type2 prod3, type2 prod4, type1 ``` -------------------------------- ### Scaffold a new Pipcook script project Source: https://github.com/alibaba/pipcook/blob/main/docs/contributing/contribute-a-script.md Use the npm init command to generate a template project structure for Pipcook scripts. ```sh $ npm init pipcook-script all my-scripts js && cd my-scripts $ tree -L 1 . ├── LICENSE ├── README.md ├── debug ├─ node_modules ├── package-lock.json ├── package.json ├── src └─ webpack.config.js $ tree ./src ./src ├── dataflow.js ├── datasource.js ├── index.js └── model.js ``` -------------------------------- ### Predict Button Click Handler Source: https://github.com/alibaba/pipcook/blob/main/packages/cli/serve-resource/text/index.html This JavaScript code handles the prediction request when the 'Predict' button is clicked. It retrieves the input text, sends a GET request to the 'predict' endpoint with the input as a query parameter, and displays the server's response in the element with the ID 'result'. Ensure jQuery is included for this functionality. ```javascript $(document).ready(function () { document.getElementById('input_text').focus(); $('#predict').click(function (event) { event.preventDefault(); var input = document.getElementById('input_text').value; $.get({ url: 'predict?input=' + input, cache: false, contentType: false, processData: false, success: function (resp) { $('#result').html(JSON.stringify(resp, null, ' ')); }, }); }); }); ``` -------------------------------- ### 运行 Pipcook 训练任务 Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/faq/pipcook-framework.md 使用 pipcook run 命令启动训练,支持本地路径或远程 URL 作为配置文件。 ```bash pipcook run ``` -------------------------------- ### Train Machine Learning Models Source: https://context7.com/alibaba/pipcook/llms.txt Train models using pipeline configuration files with support for remote URLs, local files, and custom training options. ```bash # Train image classification model with MobileNet pipcook train https://cdn.jsdelivr.net/gh/alibaba/pipcook@main/example/pipelines/image-classification-mobilenet.json -o ./output # Train from local pipeline file pipcook run /path/to/your/pipeline-config.json -o ./my-model # Train with custom options pipcook train pipeline.json \ --output ./classification-output \ --npmClient npm \ --registry https://registry.npmjs.org \ --debug # Expected output: # Epoch 1/15 # 187/187 [==============================] - 12s 65ms/step - loss: 0.0604 - accuracy: 0.9823 # ... # Epoch 15/15 # 187/187 [==============================] - 11s 61ms/step - loss: 5.1657e-05 - accuracy: 1.0000 ``` -------------------------------- ### Train a Pipeline Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/README.md Execute a machine learning pipeline using a JSON configuration file. ```sh $ pipcook train https://cdn.jsdelivr.net/gh/alibaba/pipcook@main/example/pipelines/image-classification-mobilenet.json -o output ``` -------------------------------- ### Run a pipeline Source: https://github.com/alibaba/pipcook/blob/main/docs/contributing/guide-to-contributor.md Execute a specific pipeline using the provided tool script. ```bash $ sh tools/run_pipeline.sh ``` -------------------------------- ### Configure Training Options for Image Classification Source: https://github.com/alibaba/pipcook/blob/main/example/pipelines/README.md Set training options such as the framework, GPU usage, and number of epochs. GPU is enabled by default. ```json { "options": { "framework": "tfjs@3.8", "gpu": false, "train": { "epochs": 10 } } } ``` -------------------------------- ### Run All Pipcook Tests Source: https://github.com/alibaba/pipcook/blob/main/docs/zh-cn/contributing/guide-to-contributor.md Execute all tests for the Pipcook project. ```bash $ npm test ``` -------------------------------- ### Train a Model Source: https://github.com/alibaba/pipcook/blob/main/docs/README.md Train a model using a specified pipeline configuration file. ```shell $ pipcook train https://cdn.jsdelivr.net/gh/alibaba/pipcook@main/example/pipelines/image-classification-mobilenet.json -o ./output ``` -------------------------------- ### Manage Context with with() Source: https://github.com/alibaba/pipcook/blob/main/docs/tutorials/using-python-functions-in-nodejs.md Uses the with-statement to manage local context, ensuring resources are properly entered and exited. ```python with(localcontext()) { # balabala } ```