SegFormer

SegFormer là transformer semantic segmentation kết hợp encoder Mix Transformer (MiT) phân cấp với decode head all-MLP gọn nhẹ, tránh decoder nặng và positional encoding cố định mà transformer segmentation trước đây cần. LibreYOLO hỗ trợ mô hình cho một tác vụ, semantic segmentation, trên sáu kích thước.

Tác vụ
semantic
Kích thước
Cài đặt
pip install libreyolo
Bậc hỗ trợ
Được hỗ trợ, từ v. Các mô hình huấn luyện bổ trợ: luôn giữ CI ở trạng thái xanh, tính năng được bổ sung khi có cơ hội.
Thượng nguồn
SegFormer của NVIDIA, NVIDIA Source Code License (non-commercial, research or evaluation only). Bài báo, mã nguồn
Giấy phép
Mã nguồn Apache-2.0, trọng số NVIDIA Source Code License (non-commercial, research or evaluation only). Sử dụng thương mại

Cài đặt

SegFormer không cần gói bổ sung tùy chọn. Mọi thành phần được import đều có trong bản cài cơ sở.

bash
pip install libreyolo

Dự đoán

Trọng số được tải từ Hugging Face ở lần dùng đầu tiên và cache cục bộ.

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreSegformerb0-sem.pt")result = model(SAMPLE_IMAGE, save=True) mask = result.semantic_maskprint(mask.data.shape, mask.classes)
CLI
libreyolo predict model=LibreSegformerb0-sem.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True

result.semantic_mask chứa bản đồ lớp dày đặc: .data là tensor (H, W) gồm ID lớp ở kích thước ảnh gốc, còn .classes liệt kê ID lớp thực sự hiện diện. result.boxesNone vì không có detection theo instance. confiou được nhận để parity API nhưng không thay đổi đầu ra: mô hình trả về một lớp mỗi pixel, không phải detection theo instance để lọc hoặc loại trùng. Xem dự đoán để biết source, streaming và xử lý kết quả.

Biến thể

Sáu kích thước từ b0 đến b5, mở rộng chiều rộng và độ sâu encoder Mix Transformer theo từng bước trong khi giữ cùng thiết kế decode head all-MLP.

Mọi tệp ở trên hiện đều có trong tổ chức LibreYOLO và được tải xuống trong lần sử dụng đầu tiên.

Huấn luyện

train() mặc định tinh chỉnh checkpoint đã công bố. Thay vào đó, không truyền model_path cho LibreSegformer(...) để dựng encoder và head khởi tạo ngẫu nhiên rồi huấn luyện từ đầu, đây là cách duy nhất tạo trọng số không mang hạn chế phi thương mại của checkpoint huấn luyện sẵn (xem Giấy phép).

Python (tinh chỉnh)
from libreyolo import LibreYOLO model = LibreYOLO("LibreSegformerb0-sem.pt")model.train(data="my-dataset.yaml", epochs=160, imgsz=512, batch=8)
CLI
libreyolo train model=LibreSegformerb0-sem.pt data=my-dataset.yaml \  epochs=160 imgsz=512 batch=8
Từ đầu
from libreyolo.models.segformer.model import LibreSegformer # Không có model_path: khởi tạo ngẫu nhiên, không tải gì. Đây là cách duy nhất# để có trọng số không mang điều khoản phi thương mại của checkpoint huấn luyện sẵn.model = LibreSegformer(size="b0", nb_classes=150)model.train(data="my-dataset.yaml", epochs=160, imgsz=512, batch=8)
Multi-GPU
libreyolo train model=LibreSegformerb0-sem.pt data=my-dataset.yaml \  epochs=160 device=0,1 batch=16

Khi giữ mặc định, trainer theo công thức ADE20K trong bài báo SegFormer: AdamW ở learning rate cơ sở của backbone với decode head được huấn luyện ở mức gấp 10 lần, weight decay ở mọi nơi trừ LayerNorm và convolution vị trí Mix-FFN, cùng lịch suy giảm tuyến tính có warmup. Khả năng hội tụ đầu cuối của các kích thước lớn b3 đến b5 chưa được xác thực.

Xem huấn luyện để biết dataset, augmentation, multi-GPU và logger.

Xác thực

val() trả về dictionary khóa metrics/: mIoU và độ chính xác pixel, đo trên bất kỳ dataset nào theo định dạng đã dùng để huấn luyện.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreSegformerb0-sem.pt")metrics = model.val(data="my-dataset.yaml") print(metrics["metrics/mIoU"])print(metrics["metrics/pixel_accuracy"])
CLI
libreyolo val model=LibreSegformerb0-sem.pt data=my-dataset.yaml

Xuất

Tác vụONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
semanticsemantic to ONNX: được hỗ trợsemantic to TorchScript: được hỗ trợsemantic to ExecuTorch: được hỗ trợsemantic to TensorRT: được hỗ trợsemantic to OpenVINO: được hỗ trợsemantic to Paddle: không được hỗ trợsemantic to MNN: không được hỗ trợsemantic to RKNN: không được hỗ trợsemantic to ncnn: không được hỗ trợsemantic to TFLite: không được hỗ trợsemantic to CoreML: không được hỗ trợsemantic to Core AI: không được hỗ trợ

Artifact đã xuất được nạp lại qua LibreYOLO() theo hậu tố file, nên file .onnx hoặc .engine hoạt động như checkpoint và trả về cùng Results. Xuất liệt kê đối số mọi định dạng đều nhận.

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreSegformerb0-sem.pt")model.export(format="onnx", imgsz=512)model.export(format="tensorrt", imgsz=512, half=True)
CLI
libreyolo export model=LibreSegformerb0-sem.pt format=onnx imgsz=512libreyolo export model=LibreSegformerb0-sem.pt format=tensorrt imgsz=512 half=True
Dùng file đã xuất
from libreyolo import LibreYOLO, SAMPLE_IMAGE # Factory định tuyến theo hậu tố file, nên artifact đã xuất được nạp# như mọi checkpoint và trả về cùng object Results.model = LibreYOLO("LibreSegformerb0-sem.onnx")result = model(SAMPLE_IMAGE) print(result.semantic_mask.data.shape)

Checkpoint

Mọi file trọng số đã công bố cho họ này.

Mọi tệp ở trên hiện đều có trong tổ chức LibreYOLO và được tải xuống trong lần sử dụng đầu tiên.

Giấy phép

Hãy kiểm tra giấy phép trong repo Hugging Face của trọng số cụ thể mà bạn tải xuống. Mỗi checkpoint trong tổ chức LibreYOLO đều có giấy phép riêng và giấy phép có thể khác nhau trong cùng một họ. Repo đó là nguồn có thẩm quyền; phần tóm tắt dưới đây mô tả các điều khoản áp dụng khi trang này được kiểm chứng lần gần nhất.

Đây là phần mô tả các giấy phép liên quan, không phải tư vấn pháp lý. Nếu câu trả lời có ý nghĩa về mặt thương mại, hãy tự đọc các giấy phép và tham khảo cố vấn của riêng bạn.

Công trình gốc
SegFormer, NVIDIA
Giấy phép thượng nguồn
NVIDIA Source Code License (non-commercial, research or evaluation only)
Nguồn thượng nguồn
github.com/NVlabs/SegFormer
Mã nguồn LibreYOLO
MIT
Trọng số
NVIDIA Source Code License (non-commercial, research or evaluation only), được phát hành lại tại huggingface.co/LibreYOLO
Diễn giải
The pretrained ADE20K checkpoints LibreYOLO hosts for this family are converted from NVIDIA's official SegFormer release under the NVIDIA Source Code License. That license permits redistributing the weights and derivative works, provided the license text and attribution notices travel with them, but it limits USE to non-commercial research or evaluation, a restriction its Section 3.2 carries forward into every derivative and that cannot be relicensed away: these weights are NOT covered by LibreYOLO's normal permissive terms, and that limitation binds you, not just LibreYOLO. LibreYOLO's own SegFormer implementation is a separate Apache-2.0 port of Hugging Face Transformers' code, unrelated to NVIDIA's repository, so a model you train from scratch with LibreSegformer(...).train(...) carries none of this restriction.

Encoder và decode head của LibreSegformer là bản port PyTorch từ bản triển khai SegFormer Apache-2.0 của Hugging Face Transformers, không phải từ NVlabs/SegFormer: repo gốc của NVIDIA chưa bao giờ được đọc hoặc sao chép và chỉ được ghi công ở đây để ghi nhận tác giả bài báo. Chỉ các checkpoint huấn luyện sẵn bên trên mang hạn chế phi thương mại của NVIDIA; kiến trúc và mã riêng của LibreYOLO luôn dùng MIT.

Trích dẫn

@inproceedings{xie2021segformer,
  title={SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers},
  author={Xie, Enze and Wang, Wenhai and Yu, Zhiding and Anandkumar, Anima and Alvarez, Jose M and Luo, Ping},
  booktitle={Neural Information Processing Systems (NeurIPS)},
  year={2021}
}

Được sao chép từ khối trích dẫn của tác giả tại github.com/NVlabs/SegFormer#citation.

Đã kiểm chứng với LibreYOLO v1.5.0. Các bảng hỗ trợ, checkpoint và số liệu benchmark trên trang này được tạo từ thư viện đã phát hành và trọng số đã công bố, không phải viết thủ công.