资源简介
将源码中一些关于tab与空格混用以及缩进不匹配问题更改
代码片段和文件信息
import os
import sys
import random
import math
import numpy as np
import skimage.io
import matplotlib
import matplotlib.pyplot as plt
import coco
import utils
import model as modellib
print (‘Initializing Mask RCNN network...‘)
# Root directory of the project
ROOT_DIR = os.getcwd()
ROOT_DIR = “./src/python“
print(ROOT_DIR)
# Directory to save logs and trained model
MODEL_DIR = os.path.join(ROOT_DIR “logs“)
# Path to trained weights file
COCO_MODEL_PATH = os.path.join(ROOT_DIR “mask_rcnn_coco.h5“)
# Set batch size to 1 since we‘ll be running inference on
# one image at a time. Batch size = GPU_COUNT * IMAGES_PER_GPU
class InferenceConfig(coco.CocoConfig):
GPU_COUNT = 1
IMAGES_PER_GPU = 1
config = InferenceConfig()
config.display()
# Create model object in inference mode.
model = modellib.MaskRCNN(mode=“inference“ model_dir=MODEL_DIR config=config)
# Load weights trained on MS-COCO
model.load_weights(COCO_MODEL_PATH by_name=True)
class_names = [‘BG‘ ‘person‘ ‘bicycle‘ ‘car‘ ‘motorcycle‘ ‘airplane‘
‘bus‘ ‘train‘ ‘truck‘ ‘boat‘ ‘traffic light‘
‘fire hydrant‘ ‘stop sign‘ ‘parking meter‘ ‘bench‘ ‘bird‘
‘cat‘ ‘dog‘ ‘horse‘ ‘sheep‘ ‘cow‘ ‘elephant‘ ‘bear‘
‘zebra‘ ‘giraffe‘ ‘backpack‘ ‘umbrella‘ ‘handbag‘ ‘tie‘
‘suitcase‘ ‘frisbee‘ ‘skis‘ ‘snowboard‘ ‘sports ball‘
‘kite‘ ‘baseball bat‘ ‘baseball glove‘ ‘skateboard‘
‘surfboard‘ ‘tennis racket‘ ‘bottle‘ ‘wine glass‘ ‘cup‘
‘fork‘ ‘knife‘ ‘spoon‘ ‘bowl‘ ‘banana‘ ‘apple‘
‘sandwich‘ ‘orange‘ ‘broccoli‘ ‘carrot‘ ‘hot dog‘ ‘pizza‘
‘donut‘ ‘cake‘ ‘chair‘ ‘couch‘ ‘potted plant‘ ‘bed‘
‘dining table‘ ‘toilet‘ ‘tv‘ ‘laptop‘ ‘mouse‘ ‘remote‘
‘keyboard‘ ‘cell phone‘ ‘microwave‘ ‘oven‘ ‘toaster‘
‘sink‘ ‘refrigerator‘ ‘book‘ ‘clock‘ ‘vase‘ ‘scissors‘
‘teddy bear‘ ‘hair drier‘ ‘toothbrush‘]
print (‘Initialated Mask RCNN network...‘)
def GetDynSeg(imageimage2=None):
print(‘PruebaPython‘)
h = image.shape[0]
w = image.shape[1]
if len(image.shape) == 2:
im = np.zeros((hw3))
im[::0]=image
im[::1]=image
im[::2]=image
image = im
#if image2 is not None:
# args+=[image2]
# Run detection
results = model.detect([image] verbose=0)
# Visualize results
r = results[0]
i = 0
mask = np.zeros((hw))
for roi in r[‘rois‘]:
if class_names[r[‘class_ids‘][i]] == ‘person‘:
image_m = r[‘masks‘][::i]
mask[image_m == 1] = 1.
if class_names[r[‘class_ids‘][i]] == ‘bicycle‘:
image_m = r[‘masks‘][::i]
mask[image_m == 1] = 1.
if class_names[r[‘class_ids‘][i]] == ‘car‘:
image_m = r[‘masks‘][::i]
mask[image_m == 1] = 1.
if class_names[r[‘class_ids‘][i]] == ‘motorcycle‘:
image_m = r[‘masks‘][::i]
mask[image_m == 1] = 1.
评论
共有 条评论