1. import os
  2. import sys
  3. import random
  4. import math
  5. import numpy as np
  6. import skimage.io
  7. import matplotlib
  8. import matplotlib.pyplot as plt
  9.  
  10. import coco
  11. import utils
  12. import model as modellib
  13. import visualize
  14.  
  15. %matplotlib inline
  16.  
  17. # Root directory of the project
  18. ROOT_DIR = os.getcwd()
  19.  
  20. # Directory to save logs and trained model
  21. MODEL_DIR = os.path.join(ROOT_DIR, "logs")
  22.  
  23. # Local path to trained weights file
  24. COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")
  25. # Download COCO trained weights from Releases if needed
  26. if not os.path.exists(COCO_MODEL_PATH):
  27. utils.download_trained_weights(COCO_MODEL_PATH)
  28.  
  29. # Directory of images to run detection on
  30. IMAGE_DIR = os.path.join(ROOT_DIR, "images")
  1. class InferenceConfig(coco.CocoConfig):
  2. # Set batch size to 1 since we'll be running inference on
  3. # one image at a time. Batch size = GPU_COUNT * IMAGES_PER_GPU
  4. GPU_COUNT = 1
  5. IMAGES_PER_GPU = 1
  6.  
  7. config = InferenceConfig()
  8. config.display()

  1. # Create model object in inference mode.
  2. model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
  3.  
  4. # Load weights trained on MS-COCO
  5. model.load_weights(COCO_MODEL_PATH, by_name=True)
  1. # COCO Class names
  2. # Index of the class in the list is its ID. For example, to get ID of
  3. # the teddy bear class, use: class_names.index('teddy bear')
  4. class_names = ['BG', 'person', 'bicycle', 'car', 'motorcycle', 'airplane',
  5. 'bus', 'train', 'truck', 'boat', 'traffic light',
  6. 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird',
  7. 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear',
  8. 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie',
  9. 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball',
  10. 'kite', 'baseball bat', 'baseball glove', 'skateboard',
  11. 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup',
  12. 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
  13. 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza',
  14. 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed',
  15. 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote',
  16. 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster',
  17. 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors',
  18. 'teddy bear', 'hair drier', 'toothbrush']
  1. # Load a random image from the images folder
  2. file_names = next(os.walk(IMAGE_DIR))[2]
  3. image = skimage.io.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))
  4.  
  5. # Run detection
  6. results = model.detect([image], verbose=1)
  7.  
  8. # Visualize results
  9. r = results[0]
  10. visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'],
  11. class_names, r['scores'])

吴裕雄 python 人工智能——基于Mask_RCNN目标检测(1)的更多相关文章

  1. 吴裕雄 PYTHON 人工智能——基于MASK_RCNN目标检测(5)

    import os import sys import numpy as np import tensorflow as tf import matplotlib import matplotlib. ...

  2. 吴裕雄 PYTHON 人工智能——基于MASK_RCNN目标检测(4)

    import os import sys import random import math import re import time import numpy as np import tenso ...

  3. 吴裕雄 python 人工智能——基于Mask_RCNN目标检测(3)

    import os import sys import random import math import re import time import numpy as np import cv2 i ...

  4. 吴裕雄 python 人工智能——基于Mask_RCNN目标检测(2)

    import os import sys import itertools import math import logging import json import re import random ...

  5. 吴裕雄 python 人工智能——基于神经网络算法在智能医疗诊断中的应用探索代码简要展示

    #K-NN分类 import os import sys import time import operator import cx_Oracle import numpy as np import ...

  6. 吴裕雄 PYTHON 人工智能——智能医疗系统后台智能分诊模块及系统健康养生公告简约版代码展示

    #coding:utf-8 import sys import cx_Oracle import numpy as np import pandas as pd import tensorflow a ...

  7. 吴裕雄 python 人工智能——智能医疗系统后台用户复诊模块简约版代码展示

    #复诊 import sys import os import time import operator import cx_Oracle import numpy as np import pand ...

  8. 吴裕雄 python 人工智能——智能医疗系统后台用户注册、登录和初诊简约版代码展示

    #用户注册.登录模块 #数据库脚本 CREATE TABLE usertable( userid number(8) primary key not null , username varchar(5 ...

  9. TF项目实战(基于SSD目标检测)——人脸检测1

    SSD实战——人脸检测 Tensorflow 一 .人脸检测的困难: 1. 姿态问题 2.不同种族人, 3.光照 遮挡 带眼睛 4.视角不同 5. 不同尺度 二. 数据集介绍以及转化VOC: 1. F ...

随机推荐

  1. python的selenium实现自动登陆

    知道思想,参考其他文档,python的request模块和selenium模块都可以实现get_cookie()和 add_cookie()的功能. 由于现在在学习selenium自动化测试,我选用s ...

  2. VS 2017 mscorlib.dll 加载元数据时发生严重错误,需要终止调试

    VS 2017 mscorlib.dll 加载元数据时发生严重错误,需要终止调试 C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0. ...

  3. 题解【洛谷P3574】[POI2014]FAR-FarmCraft

    题面 简化版题意: 有一棵 \(n\) 个点的树,有边权. 你初始在 \(1\) 号节点,你需要走遍整棵树为 \(2 \sim n\) 号点的居民分发电脑,但你的汽油只够经过每条边恰好两次. 一个居民 ...

  4. xrdp---远程桌面连接

    xrdp is an Open Source Remote desktop Protocol server, which allows you to RDP to your Linux server ...

  5. sql查询 —— 模糊查询

    --模糊查询 --like --%至少替换一个 -- _只替换一个 -- 查姓李的人 select *from student name like "李%"; -- 查名为杰伦的人 ...

  6. 线程同步器CountDownLatch

    Java程序有的时候在主线程中会创建多个线程去执行任务,然后在主线程执行完毕之前,把所有线程的任务进行汇总,以前可以用线程的join方法,但是这个方法不够灵活,我们可以使用CountDownLatch ...

  7. IF EXISTS 两个条件连用

    当IF EXISTS要判断多个条件并存时,可以用AND连接,NOT EXISTS同理 IF EXISTS (SELECT 1 ) AND EXISTS (SELECT 2 ) BEGIN ...... ...

  8. TCP/IP详解,卷1:协议--第6章 ICMP:Internet控制报文协议

    引言 I C M P经常被认为是 I P层的一个组成部分.它传递差错报文以及其他需要注意的信息. I C M P报文通常被I P层或更高层协议( T C P或U D P)使用.一些I C M P报文把 ...

  9. MODBUS TCP/IP协议规范详细介绍

    1.该规范的发展概况                                    原始版本1997年9月3日作为公共评论的草案.     再版1999年3月29日,即修订版1.0.     ...

  10. layui之弹出层关闭和刷新问题

    本篇文章是根据本人实际开发的例子来讲的,不一定适用各位看官的情况 描述: 主页面,弹出第一个弹框,第一个弹框中在弹出第二个弹框,如图: 1是主页面,2是子弹窗,3是孙弹窗 功能一:好了,第一个我要实现 ...