根據requirements - 開源項目默認的.txt進行庫安裝
環境:WIN10 + Anoconda + Pycharm + python3.6.2
mask_rcnn基本流程1、訓練 1)labelme進行目標物體標記,生成json文件,含點坐標、以及各個物體的標簽label; json文件的格式:(在balloon.py中提到) # { 'filename': '28503151_5b5b7ec140_b.jpg',# 'regions': {# '0': {# 'region_attributes': {},# 'shape_attributes': {# 'all_points_x': [...],# 'all_points_y': [...],# 'name': 'polygon'}},# ... more regions ...# },# 'size': 100202# }2)修改E:\gitHubProjects\Mask_RCNN-master\Mask_RCNN-master\samples\balloon\balloon.py代碼將: if args.weights.lower() == "coco":# Exclude the last layers because they require a matching# number of classes,coco數據集含有80個類,但是對于通常來說,只有前景和背景兩類,因此#需要將if。。=coco給注釋掉model.load_weights(weights_path, by_name=True, exclude=["mrcnn_class_logits", "mrcnn_bbox_fc","mrcnn_bbox", "mrcnn_mask"])else:model.load_weights(weights_path, by_name=True) 改成: model.load_weights(weights_path, by_name=True, exclude=["mrcnn_class_logits", "mrcnn_bbox_fc","mrcnn_bbox", "mrcnn_mask"])3)利用balloon.py修改后的進行訓練,注意需要修改的地方: class BalloonConfig(Config):"""Configuration for training on the toy dataset.Derives from the base Config class and overrides some values."""# Give the configuration a recognizable nameNAME = "balloonDataset"# We use a GPU with 12GB memory, which can fit two images.# Adjust down if you use a smaller GPU.IMAGES_PER_GPU = 1 # 每個GPU同時訓練的圖片數,如果是CPU建議修改為1# Number of classes (including background)# 類別數,一般是你自己數據物體的類別數+1(+1是背景),coco默認的是80+1類NUM_CLASSES = 1 + 1 # Background + balloonDataset# Number of training steps per epoch # 每一個迭代循環的步長數STEPS_PER_EPOCH = 100# Skip detections with < 90% confidence 置信度,小于這個則跳過檢測,提高檢測效率DETECTION_MIN_CONFIDENCE = 0.9 除了上面的,還可以修改訓練好的模型存放的位置,一般存放在E:\gitHubProjects\Mask_RCNN-master\Mask_RCNN-master\logs4) 利用命令行進行訓練,具體命令見:見“E:\gitHubProjects\Mask_RCNN-master\Mask_RCNN-master\samples\balloon\README.md” python3 balloon.py train --dataset=dataset_path --weights=weughts_path2、測試 1)修改E:\gitHubProjects\Mask_RCNN-master\Mask_RCNN-master\samples\coco\coco.py代碼 將: NUM_CLASSES = 1+80 改成: NUM_CLASSES = 1+1(背景+目標)————根據自己的類別數進行修改 1)修改E:\gitHubProjects\Mask_RCNN-master\Mask_RCNN-master\samples\demo.py代碼 修改MODEL_DIR、COCO_MODEL_PATH(訓練好的模型)、IMAGE_DIR(測試集圖片)、class_names(類別名稱)=["BG","","",...]
?
github項目鏈接:
https://github.com/1371174718/Mask_RCNN_master