maskrcnn-benchmark訓練自己的資料集(執行個體分割)——提供資料集
摘要: maskrcnn主要是做執行個體分割的,maskrcnn是在faster rcnn基礎上改進的,原理可以參考我關于faster rcnn的原了解讀FasterRcnn原理了解記錄
1. 安裝
直接參考官方項目facebookresearch/maskrcnn-benchmark
2. 官方demo測試
用官方例子和預訓練模型進行測試。或者從百度網盤,密碼:5qwy,下載下傳預訓練模型進行測試
from maskrcnn_benchmark.config import cfg
from predictor import COCODemo
config_file = "../configs/e2e_mask_rcnn_R_50_FPN_1x_caffe2.yaml"
# update the config options with the config file
cfg.merge_from_file(config_file)
# manual override some options
cfg.merge_from_list(["MODEL.DEVICE", "cpu"])
coco_demo = COCODemo(
cfg,
min_image_size=800,
confidence_threshold=0.7,
)
# load image and then run prediction
image = ...
predictions = coco_demo.run_on_opencv_image(image)
3. 訓練自己的資料集(執行個體分割)
網上很多例子,但是大部分沒有提供資料集,這裡我标注了14張資料,用于測試。下載下傳連結,密碼:5qwy.
操作流程具體參考這篇博文:
maskrcnn-benchmark訓練自己資料集用于視覺分割
按照以上流程是沒有問題的。
4. 測試自己的模型
預訓練模型下載下傳:連結,密碼:5qwy
代碼部分:
from maskrcnn_benchmark.config import cfg
from predictor import COCODemo
import cv2
import matplotlib.pyplot as plt
from PIL import Image
import requests
from io import BytesIO
import numpy as np
config_file = "./configs/caffe2/e2e_mask_rcnn_R_50_FPN_1x_caffe2.yaml"
config_file = "./configs/e2e_mask_rcnn_R_51_C4_1x_2.yaml"
# update the config options with the config file
cfg.merge_from_file(config_file)
# manual override some options
cfg.merge_from_list(["MODEL.DEVICE", "cpu"]) # 用CPU
cfg.merge_from_list(["MODEL.DEVICE", "cuda"]) # 用GPU
coco_demo = COCODemo(
cfg,
min_image_size=800,
confidence_threshold=0.7,
)
def imshow(img):
plt.imshow(img[:, :, [2, 1, 0]])
plt.axis("off")
plt.show()
# image = load("http://farm3.staticflickr.com/2469/3915380994_2e611b1779_z.jpg")
image = Image.open("/home/yangna/deepblue/OCR_D/maskrcnn-benchmark/datasets/coco2/train2014/000.jpg").convert("RGB")
image = np.array(image)[:, :, [2, 1, 0]]
imshow(image)
predictions = coco_demo.run_on_opencv_image(image)
imshow(predictions)
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsICM38FdsYkRGZkRG9lcvx2bjxiNx8VZ6l2cs0zZE1UeJpWTyUEVNdXVzwEMW1mY1RzRapnTtxkb5ckYplTeMZTTINGMShUYfRHelRHLwEzX39GZhh2css2RkBnVHFmb1clWvB3MaVnRtp1XlBXe0xyayFWbyVGdhd3LcV2Zh1Wa9M3clN2byBXLzN3btg3Pn5GcuQjMzQTOwgTMzAjMxkTMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
5. 思考
其實本身是想做旋轉矩形的檢測,考慮用mask回歸的最大外接矩形。但是maskrcnn—benchmark本身沒有提供旋轉的資料增強。