Vào thẳng nội dung

FastSAM

Overviews

The Fast Segment Anything Model(FastSAM) is a CNN Segment Anything Model trained using only 2% of the SA-1B dataset published by SAM authors.

FastSAM

Example FastSAM

Original git: https://github.com/CASIA-IVA-Lab/FastSAM.git

In this document, we will show you how to use HACHIX version of these algorithms.

Install Requirements

Please install ecos_core-1.3.0 Install from zip:

pip install ecos_core-1.3.0.zip

Configs

opt.json like this:

{
    "weights_url": "https://drive.google.com/u/0/uc?id=1m1sjY4ihXBU1fZXdQ-Xdj-mDltW-2Rqv&export=download&confirm=t&uuid=ab4e4a93-cfc4-4118-ab4f-0e1ea2d8be79&at=ALt4Tm1VVjRzBfbguE6B1gL8aVf4:1689323952061",
    "retina": true,
    "imgsz": 640,
    "conf": 0.25,
    "iou": 0.7,
    "box_prompt": "[[0,0,0,0]]",
    "text_prompt": "",
    "point_prompt": "[[0,0]]",
    "point_label": "[0]",
    "withContours": false,
    "better_quality": false,
    "text_conf": 0.25,
    "clip_model_name": "ViT-B/32"

}
  • weights_url: Weight url for download
  • retina: Draw high-resolution segmentation masks. Value: true or false
  • imgsz: image size.
  • conf: confidence threshold.
  • iou: IoU threshold.
  • box_prompt: Support multiple boxes [[x,y,w,h],[x2,y2,w2,h2]]. Default: "[[0,0,0,0]]"
  • text_prompt: use text prompt eg: "a dog". Default: ""
  • point_prompt: Point to detect [[x1,y1],[x2,y2]]. Default: "[[0,0]]"
  • point_label: 0:background, 1:foreground. Default: "[0]"
  • withContours: Draw the edges of the masks. Value: true or false
  • better_quality: Better quality using morphologyEx. Value: true or false
  • text_conf: text confidence
  • clip_model_name: model name of CLIP

Priority output

Boxes (box_prompt) -> Text (text_promt)-> Point (point_prompt and point_label)-> All masks

If you want to select type of detections, please set other parameters as default value.

APIs

Model

Bases: BaseModel

This is the base model for INDAD

__init__(opt=None)

This function is called when creating a new instance of FastSAM Model

Parameters:

Name Type Description Default
opt NameSpace

The default options neccessary for initializing the model. opt should includes these attributes: weight.

None

build_model(custom_weight=None)

build model for detection

Returns:

Name Type Description
Model

Inherited from model base class

get_transform()

Get image data transform function for preprocessing

Returns:

Name Type Description
transform func

transform function. This function will take input as image path and output - raw_image: image numpy mat - image_transform: image tensor (pytorch)

predict(input)

Predict

Parameters:

Name Type Description Default
input (URI, OpenCV, PIL, numpy)

input

required

Returns:

Name Type Description
Detections

Output

process_predictions(pred, raw_image_path, raw_image_mat, image_transform, save_image_path)

post process the output of the net

Parameters:

Name Type Description Default
pred _type_

output of detection

required
raw_image_path str

raw image path

required