semvec/pypi-packages huggingface dataset:
visage 0.2.17
Face Parsers
Requires Python: >=3.8

# face-parser

## 1. Face Segmentation

### 1.1. BiSeNet

![](images/obama_bisenet.jpg)

```python
from visage.bisenet import BiSeNetFaceParser
from visage.visualize import apply_colormap

img = load_img()  # torch.Tensor [3, H, W] in range [-1, 1]

face_parser = BiSeNetFaceParser()
segmentation_mask = face_parser.parse(img)

# Plotting
segmentation_mask_colored = apply_colormap(segmentation_mask)  # Colorizes each class with a distinct color for better viewing
plt.imshow(segmentation_mask_colored)

```

## 2. Face Bounding Boxes

### 2.1. FaceBoxesV2

![](images/obama_face_boxes_v2.jpg)

```python
from visage.bounding_boxes.face_boxes_v2 import FaceBoxesV2

img = load_img()  # np.ndarray [H, W, 3] in range [0, 255]

detector = FaceBoxesV2()
detected_bboxes = detector.detect(img)

# Plotting
cv2.rectangle(img, detected_bboxes[0].get_point1(), detected_bboxes[0].get_point2(), (255, 0, 0), 10)
plt.imshow(img)
```

## 3. Facial Landmarks

### 3.1. PIPNet

![](images/obama_pipnet.jpg)

```python
from visage.landmark_detection.pipnet import PIPNet

img = load_img()  # np.ndarray [H, W, 3] in range [0, 255]
detected_bboxes = ...  # <- from step 2.

pip_net = PIPNet()
landmarks = pip_net.forward(img, detected_bboxes[0])

# Plotting
for x, y in landmarks:
    cv2.circle(img, (int(x), int(y)), 5, (255, 0, 0), -1)

plt.imshow(img)
```

## 4. Background Matting

### 4.1. BackgroundMattingV2

```python
from visage.matting.background_matting_v2 import BackgroundMattingV2

img = load_img(...)  # np.ndarray [H, W, 3] in range [0, 255]
bg_img = load_img(...)  # np.ndarray [H, W, 3] in range [0, 255]. Should be the same viewpoint but without the foreground

background_matter = BackgroundMattingV2()
alpha_images = background_matter.parse([img], [bg_img])

plt.imshow(alpha_images[0])
```
| Image                              | Background                        | Foreground Mask                            |
|------------------------------------|-----------------------------------|--------------------------------------------|
  | ![](images/tobi_cam_222200038.jpg) | ![](images/tobi_bg_222200038.jpg) | ![](images/tobi_background_matting_v2.png) |
partial-tables 0.0.2
Partial Table Models for SQLAlchemy and SQLModel
Requires Python: <3.15,>=3.11

# SQLAlchemy Partial Tables

Partial Tables for SQLAlchemy and SQLModel

[![Coverage](https://img.shields.io/codecov/c/github/julien777z/partial-tables?branch=main&label=Coverage)](https://codecov.io/gh/julien777z/partial-tables)

## Installation

```bash
pip install partial-tables
```

## Scenario

Let's say you have 2 tables, `business_draft` and `business`.

`business_draft` and `business` have the same fields, but `business_draft` should allow most fields to be nullable.

Any business can freely update its draft, but only approved modifications get copied over to `business`.

How can we implement this and reduce redundancy?

## Usage

Any field marked with `PartialAllowed` will be nullable in the partial table, and required in the complete table.

A partial table is any table that sub-classes with `PartialTable`.

## Example (SQLAlchemy Declarative)

```python
from typing import Annotated
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from partial_tables import PartialSQLAlchemyMixin, PartialAllowed, PartialTable


class Base(DeclarativeBase):
    __abstract__ = True


class BusinessBase(PartialSQLAlchemyMixin, Base):
    """Base class for all business models."""

    __abstract__ = True

    id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
    business_name: Mapped[str] = mapped_column()
    # Mark fields that may be nullable in the partial table
    city: Mapped[Annotated[str, PartialAllowed()]] = mapped_column()
    address: Mapped[Annotated[str, PartialAllowed()]] = mapped_column()


class BusinessDraft(BusinessBase, PartialTable):
    __tablename__ = "business_draft"


class Business(BusinessBase):
    __tablename__ = "business"
```

`Business` has all required (NOT NULL) columns, and `BusinessDraft` has every field marked with `PartialAllowed` as nullable.

## Example (SQLModel)

```python
from typing import Annotated
from sqlmodel import SQLModel, Field
from partial_tables import PartialSQLModelMixin, PartialAllowed, PartialTable


class BusinessBase(PartialSQLModelMixin, SQLModel):
    id: int = Field(primary_key=True, sa_column_kwargs={"autoincrement": True})
    business_name: str
    city: Annotated[str, PartialAllowed()] = Field()
    address: Annotated[str, PartialAllowed()] = Field()


class BusinessDraft(BusinessBase, PartialTable, table=True):
    __tablename__ = "business_draft"


class Business(BusinessBase, table=True):
    __tablename__ = "business"
```

## License
MIT