MASKRCNN(之三)demo.
来源:互联网 发布:华润网络校园招聘 编辑:程序博客网 时间:2024/06/06 00:42
一 使用TF
import osimport sysimport randomimport mathimport numpy as npimport scipy.miscimport matplotlibimport matplotlib.pyplot as pltimport coco #coco.py,里面是mask rcnn中MSCOCO的配置和数据加载import utils #util.py,里面是mask rcnn的通用函数和类实现import model as modellib #model.py,里面是mask rcnn模型的实现import visualize #visualize.py,里面封装了matplotlib IPython.display ,用来显示图像画图%matplotlib inline # Root directory of the projectROOT_DIR = os.getcwd()# Directory to save logs and trained modelMODEL_DIR = os.path.join(ROOT_DIR, "logs")# Path to trained weights file# Download this file and place in the root of your # project (See README file for details)COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")# Directory of images to run detection onIMAGE_DIR = os.path.join(ROOT_DIR, "images")
MODEL_DIR: 保存log,和训练的模型
IMAGE_DIR: 图片存放路径 images/
COCO_MODEL_PATH:mask_rcnn_coco.h5 download下来的coco model
二 配置
class InferenceConfig(coco.CocoConfig): # Set batch size to 1 since we'll be running inference on # one image at a time. Batch size = GPU_COUNT * IMAGES_PER_GPU GPU_COUNT = 1 IMAGES_PER_GPU = 1config = InferenceConfig()config.print()
配置信息读取:从coco.py里的class CocoConfig(Config)读取,Config又是从config.py里读取的,然后更新了GPU_COUNT IMAGES_PER_GPU的配置
GPU的数量*每GPU处理的图片数
输出结果是最终的配置信息
三 创建Model 加载weights
# Create model object in inference mode.model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config) #Model.py的MaskRCNN类实现# Load weights trained on MS-COCOmodel.load_weights(COCO_MODEL_PATH, by_name=True) #从mask_rcnn_coco.h5load weights
四 加载coco name
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']
五 物体识别
# Load a random image from the images folderfile_names = next(os.walk(IMAGE_DIR))[2]image = scipy.misc.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))# Run detectionresults = model.detect([image], verbose=1)# Visualize resultsr = results[0]visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'], class_names, r['scores'])结果如下图:
Model.py和coco.py 下一节继续解析
阅读全文
1 0
- MASKRCNN(之三)demo.
- Fast MaskRCNN 框架训练时的各种坑(三)
- MASKRCNN(之二)编译和错误解决
- AndEngine之DEMO学习(三)SpriteExample
- Tensorflow 跑MaskRCNN框架遇到的各种坑(一)
- DEMO:通讯录(三)
- unity官方demo学习之Stealth(三)标签管理
- Quartz入门Demo(三)之TriggerListener 和 JobListener
- 自定义View之大风车系列demo(三)
- android demo(三):simpleAdapter
- 【笨木头Unity】入门之旅008:Demo之四处找死(三)_触发器
- MASKRCNN(之一)下载源和对应的虚拟环境配置
- windows编译MaskRCNN
- MaskRCNN学习笔记
- iOS 新浪微博客户端Demo实践之(三)微博主页
- Core Data浅谈系列之三 : 了解NSManagedObject和NSPredicate(附Demo)
- JS小Demo实战之今天外卖点什么?(三)
- protoc编译proto文件之Java源码结构分析三(示例Demo)
- popwindow缩放显示消失动画
- PCRE is not compiled with PCRE_UTF8错误
- vueJs(2.x)+router+vuex简易博客系统<一>
- 开发框架-Spring-Spring Boot属性文件及多环境配置
- Linux更改命令提示符信息
- MASKRCNN(之三)demo.
- Git详细教程
- css3:selection
- 安装python
- IntersectionObserver API
- ubuntu16.04 anaconda 安装OpenCV 3.2
- Git教程——高级进阶(一)
- javaScript----一切皆为对象
- Quartz任务调度、手动执行定时任务