代码来自:https://github.com/matterport/Mask_RCNN
使用coco.py的命令行代码是这样写的:
你可以选择谷歌翻译。
# Train a new model starting from pre-trained COCO weights
python3 samples/coco/coco.py train --dataset=/path/to/coco/ --model=coco
# Train a new model starting from ImageNet weights
python3 samples/coco/coco.py train --dataset=/path/to/coco/ --model=imagenet
# Continue training a model that you had trained earlier
python3 samples/coco/coco.py train --dataset=/path/to/coco/ --model=/path/to/weights.h5
# Continue training the last model you trained. This will find
# the last trained weights in the model directory.
python3 samples/coco/coco.py train --dataset=/path/to/coco/ --model=last
coco.py这个文件是训练测试的入口。它一共包含了以下方法。
1.首先是与其他功能性python文件的联系:
config是一个统一的配置文件,model是静态图模型的代码
from mrcnn.config import Config
from mrcnn import model as modellib, utils
然后可以在这里改一部分config的参数
class CocoConfig(Config):
2.数据集类
class CocoDataset(utils.Dataset):
包含了若干方法
#加载coco数据集的子集
def load_coco(self, dataset_dir, subset, year=DEFAULT_DATASET_YEAR, class_ids=None,
class_map=None, return_coco=False, auto_download=False):
#自动下载
def auto_download(self, dataDir, dataType, dataYear):
#image_id会给定图片比如000001.jpg,这个方法会给出mask
def load_mask(self, image_id):
#对给定图片返回他在coco的网址
def image_reference(self, image_id):
#下面两个本来是pycocotools里面的方法,坐着改动了一些,写在这里
def annToRLE(self, ann, height, width):
de