LoginSignup
2
8

More than 1 year has passed since last update.

最新の機械学習モデルはライブラリに集約されつつある Detectron2の使い方

Last updated at Posted at 2022-01-16

最新の機械学習は、Pytorchのラッパーライブラリを使うケースが多い

ダウンロード (23).png

ObjectDetectionタスクのモデルであれば、mmdetectionやdetectron2などのpytorchラッパーを通して使われていることが多い。
例えば、FaceBookResearchのモデルは、FaceBookResearchが使いやすいdetectron2を通して発表している。
以下のモデルはdetectron2で使えるモデルである。

DensePose: Dense Human Pose Estimation In The Wild
Scale-Aware Trident Networks for Object Detection
TensorMask: A Foundation for Dense Object Segmentation
Mesh R-CNN
PointRend: Image Segmentation as Rendering
Momentum Contrast for Unsupervised Visual Representation Learning
DETR: End-to-End Object Detection with Transformers
Panoptic-DeepLab: A Simple, Strong, and Fast Baseline for Bottom-Up Panoptic Segmentation
D2Go (Detectron2Go), an end-to-end production system for training and deployment for mobile platforms.
Pointly-Supervised Instance Segmentation
Unbiased Teacher for Semi-Supervised Object Detection
Rethinking "Batch" in BatchNorm
Per-Pixel Classification is Not All You Need for Semantic Segmentation

ラッパーライブラリの使い方を知れば、最新モデルが使いやすい

高精度の最新モデルを使うには、これらのラッパーライブラリの基本的な使い方に慣れておくと便利である。
覚えるのめんどくさそう?

わりとかんたん

そもそもライブラリ自体かんたんに推論などを行えるようにラップされているので、割と使い方はかんたんである。

使い方(Detectron2)

基本的には、
1、使いたいモデルのConfigファイルとWeightをAPIに渡してモデルをビルド
2、inference

という手順である。

# build
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5  # set threshold for this model
# Find a model from detectron2's model zoo. You can use the https://dl.fbaipublicfiles... url as well
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
predictor = DefaultPredictor(cfg)

# inference
im = cv2.imread("./input.jpg")
outputs = predictor(im)

ダウンロード (24).png

覚えておくとお得

基本的に使いやすいように作ってくれたライブラリなので、覚えておくと便利である。

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

Core MLやARKitを使ったアプリを作っています。
機械学習/AR関連の情報を発信しています。

Twitter
Medium

2
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
8