admin 管理员组文章数量: 1086019
2024年2月18日发(作者:simulink仿真距离传感器)
if is None: out_dir = me(json_file).replace('.', '_') out_dir = (e(json_file), out_dir) else: out_dir = if not (out_dir): (out_dir) count = r(json_file) for i in range(0, len(count)): path = (json_file, count[i]) if (path): data = (open(path)) if data['imageData']: imageData = data['imageData'] else: imagePath = (e(path), data['imagePath']) with open(imagePath, 'rb') as f: imageData = () imageData = base64.b64encode(imageData).decode('utf-8') img = _b64_to_arr(imageData) label_name_to_value = {'_background_': 0} for shape in data['shapes']: label_name = shape['label'] if label_name in label_name_to_value: label_value = label_name_to_value[label_name] else: label_value = len(label_name_to_value) label_name_to_value[label_name] = label_value # label_values must be dense label_values, label_names = [], [] for ln, lv in sorted(label_name_to_(), key=lambda x: x[1]): label_(lv) label_(ln) assert label_values == list(range(len(label_values))) lbl = _to_label(, data['shapes'], label_name_to_value) captions = ['{}: {}'.format(lv, ln) for ln, lv in label_name_to_()] lbl_viz = _label(lbl, img, captions) out_dir = me(count[i]).replace('.', '_') out_dir = (e(count[i]), out_dir) if not (out_dir): (out_dir) ray(img).save((out_dir, '')) # ray(lbl).save((out_dir, '')) e((out_dir, ''), lbl) ray(lbl_viz).save((out_dir, 'label_')) with open((out_dir, 'label_'), 'w') as f: for lbl_name in label_names: (lbl_name + 'n') (' is being replaced by label_') info = dict(label_names=label_names) with open((out_dir, ''), 'w') as f: _dump(info, f, default_flow_style=False) print('Saved to: %s' % out_dir)
""" _, ax = ts(rows, cols, figsize=(size * cols, size * rows)) return ax#基础设置dataset_root_path="train_data/"img_floder = dataset_root_path + "pic"mask_floder = dataset_root_path + "cv2_mask"#yaml_floder = dataset_root_pathimglist = r(img_floder)count = len(imglist)#train与val数据集准备dataset_train = DrugDataset()dataset__shapes(count, img_floder, mask_floder, imglist,dataset_root_path)dataset_e()#print("dataset_train-->",dataset_train._image_ids)dataset_val = DrugDataset()dataset__shapes(6, img_floder, mask_floder, imglist,dataset_root_path)dataset_e()#print("dataset_val-->",dataset_val._image_ids)# Load and display random samples#image_ids = (dataset__ids, 4)#for image_id in image_ids:# image = dataset__image(image_id)# mask, class_ids = dataset__mask(image_id)# y_top_masks(image, mask, class_ids, dataset__names)# Create model in training modemodel = NN(mode="training", config=config, model_dir=MODEL_DIR)# Which weights to start with?init_with = "coco" # imagenet, coco, or lastif init_with == "imagenet": _weights(_imagenet_weights(), by_name=True)elif init_with == "coco": # Load weights trained on MS COCO, but skip layers that # are different due to the different number of classes # See README for instructions to download the COCO weights _weights(COCO_MODEL_PATH, by_name=True, exclude=["mrcnn_class_logits", "mrcnn_bbox_fc", "mrcnn_bbox", "mrcnn_mask"])elif init_with == "last": # Load the last model you trained and continue training _weights(_last()[1], by_name=True)# Train the head branches# Passing layers="heads" freezes all layers except the head# layers. You can also pass a regular expression to select# which layers to train by name (dataset_train, dataset_val, learning_rate=NG_RATE, epochs=20, layers='heads')# Fine tune all layers# Passing layers="all" trains all layers. You can also# pass a regular expression to select which layers to
import as pltimport cv2import timefrom import Configfrom datetime import datetime# Root directory of the projectROOT_DIR = ()# Import Mask (ROOT_DIR) # To find local version of the libraryfrom mrcnn import utilsimport as modellibfrom mrcnn import visualize# Import COCO config# ((ROOT_DIR, "samples/coco/")) # To find local version# from import coco# Directory to save logs and trained modelMODEL_DIR = (ROOT_DIR, "logs")# Local path to trained weights fileCOCO_MODEL_PATH = (MODEL_DIR, "mask_rcnn_shapes_0040.h5") # 修改# Download COCO trained weights from Releases if neededif not (COCO_MODEL_PATH): ad_trained_weights(COCO_MODEL_PATH) print("cuiwei***********************")# Directory of images to run detection onIMAGE_DIR = (ROOT_DIR, "images")class ShapesConfig(Config): """Configuration for training on the toy shapes dataset. Derives from the base Config class and overrides values specific to the toy shapes dataset. """ # Give the configuration a recognizable name NAME = "shapes" # Train on 1 GPU and 8 images per GPU. We can put multiple images on each # GPU because the images are small. Batch size is 8 (GPUs * images/GPU). GPU_COUNT = 1 IMAGES_PER_GPU = 1 # Number of classes (including background) NUM_CLASSES = 1 + 6 # background + 3 shapes 修改 # Use small images for faster training. Set the limits of the small side # the large side, and that determines the image shape. IMAGE_MIN_DIM = 320 IMAGE_MAX_DIM = 384 # Use smaller anchors because our image and objects are small RPN_ANCHOR_SCALES = (8 * 6, 16 * 6, 32 * 6, 64 * 6, 128 * 6) # anchor side in pixels # Reduce training ROIs per image because the images are small and have # few objects. Aim to allow ROI sampling to pick 33% positive ROIs. TRAIN_ROIS_PER_IMAGE = 100 # Use a small epoch since the data is simple STEPS_PER_EPOCH = 100 # use small validation steps since the epoch is small
版权声明:本文标题:Win10下手把手教你MaskR-CNN用自己的数据集训练(从labelme标记开始 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1708245767a517590.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论