semvec/pypi-packages huggingface dataset:
onebrain 0.0.9
onebrain sdk in python version
License: MIT
Requires Python: >=3.6
Keywords: onebrain

# Onebrain-SDK
## 安装
首先镜像里需安装onebrain-sdk。可以采用whl包本地安装的形式。
一般来说，平台提供的镜像里应该已经集成onebrain-sdk了。
## 打最新的whl包
```shell script
git clone https://gitee.com/onebrain/onebrain-sdk.git
python setup.py bdist_wheel -d onebrain
```
将whl包上传至镜像
## 安装whl包
```shell script
pip install onebrain-0.0.1-py3-none-any.whl
```

SDK说明
使用示例
```python
from onebrain.api import OnebrainClient

run_id = "my_train_job"
# 创建与平台通信的client对象
client = OnebrainClient()
```
然后就可以通过client对象来上传指标到平台了
以pytorch训练任务为例
```shell script
# ...
def train(dataloader:DataLoader, model:nn.Module, loss_fn, optimizer:torch.optim.Optimizer, step):
    image_size = len(dataloader.dataset)
    print(f"数据集的图片总数: {image_size}")
    
    for batch, (x_train, y_train) in enumerate(dataloader):
        x_train, y_train = x_train.to(device), y_train.to(device)
        y_hat = model(x_train)
        loss = loss_fn(y_hat, y_train)
        loss.backward()
        optimizer.step()
        optimizer.zero_grad()

        if batch % 100 == 0:
            loss, current = loss.item(), batch * len(x)
            print(f'batch:{batch}, loss: {loss}, , image_num:{current}/{image_size}')
            # 上传指标
            client.log_metric(key="loss", value=loss, step=step)

for epoch in range(epochs):
    print(f"Epoch {epoch}\n --------------------------------")
    train(train_dataloader, model, loss_fn, optimizer, epoch)
```

#### log_metric方法参数说明：
- run_id:  训练任务的唯一标识，默认从环境变量获取，填充为平台生成的resourceId
- key：指标名称
- value: 指标值
- timestamp:  时间戳，默认为当前时间
- step: 训练的step 

#### 备注：
在OnebrainClient对象实例化之初，会根据容器的环境变量判断该以何种方式上报平台。
默认为RestfulApi，也支持使用MQ上报指标。当环境变量不存在时，实例化会失败并报错。
opencv-object-counter 0.1.12
Object counter using opencv2 and frame differencing
License: MIT
Requires Python: >=3.9.6

# OpenCV2 Object Counter
Count objects using opencv2 in this configurable CLI utility. The module uses frame differencing to detect and count objects according to a flexible configuration scheme. This makes it a quick-and-dirty solution that can achieve good accuracy in a variety of cases and doesn't involve the computaional overhead nor complexity of convolutional neural netowrks (CNN). 

Alternatively, the package can be imported to your own scripts.

## Gates
`Gates` are the instrument used for counting. They are boxes which detect  objects passing through them. A cooldown is triggered when it detects an object to avoid counting the same object many times. The right cooldown duration will depend on the counting situation. An object is counted if the gate is not on cooldown and the center point of the object and the gate is within the given distance.

## Configuration
Here is an annotated example config. A default config is provided in `ooc/config.json`. Running `ooc` in cli mode requires a config. More details on some of the parameters can be found on `https://docs.opencv.org/`.

*Note: The comments provided in this snippet are for informational purposes only and render this invalid JSON.*

```js
{
    // list of gates that will be used for counting
    "gates": [
        {
            // Starting x and y position (0,0 is top left)
            // and gate dimnensions
            "x": 350,
            "y": 320,
            "width": 100,
            "height": 100
        }
    ],
    "blur" : {
        // openCV2 kernal size
        // must be positive or odd, or 0 (in which case 
        // they are computed from sigma)
        "ksize": {
            "width": 21,
            "height": 21
        },
        // openCV2 kernal standard deviation
        "sigma_x": 0
    },
    // whether or not the video shows. press 'q' to quit
    "show": true,
    // whether or not additional video shows/logs print
    "debug": false
}
```

## Command Line Arguments

-s, --source 
 - required
 - Path to the video to analyze.
 - Usage: `ooc -s /path/to/video.mp4`

-t, --show
 - Displays the video if set.

-d, --debug
 - Runs in debug mode, which includes visual on the video (if -s is set) and prints logs.

-c, --config
- Path to config file. If not set, the default config is 
used.
- Usage: `ooc -s /path/to/video.mp4 -c /path/to/config.json`

## Example Run

```
python ooc/cli.py -s /path/to/video.mp4 -c /path/to/config.json
```