# coding: utf-8

# In[323]:

import os
import sys
import random
import math
import numpy as np
import skimage.io
import matplotlib
import matplotlib.pyplot as plt
import cv2
import time
from mrcnn.config import Config
from datetime import datetime

# In[324]:

# Root directory of the project
ROOT_DIR = os.getcwd()

# Import Mask RCNN
sys.path.append(ROOT_DIR) # To find local version of the library
from mrcnn import utils
import mrcnn.model as modellib
from mrcnn import visualize
# Import COCO config
sys.path.append(os.path.join(ROOT_DIR, "coco/")) # To find local version
from samples.coco import coco

# Directory to save logs and trained model
MODEL_DIR = os.path.join(ROOT_DIR, "logs-test")

# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(MODEL_DIR ,"mask_rcnn_shapes_0140.h5")
#COCO_MODEL_PATH = os.path.join(MODEL_DIR ,"mask_rcnn_coco.h5")
# Download COCO trained weights from Releases if needed
if not os.path.exists(COCO_MODEL_PATH):
  utils.download_trained_weights(COCO_MODEL_PATH)
  print("cuiwei***********************")

# Directory of images to run detection on
IMAGE_DIR = os.path.join(ROOT_DIR, "images201902")

# In[325]:

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 + 2 # 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 = 80
  IMAGE_MAX_DIM = 512

  # 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
  #RPN_ANCHOR_SCALES = (128 * 6, 256 * 6, 512 * 6)
  #RPN_ANCHOR_SCALES = (32 * 6, 64 * 6, 128 * 6, 256 * 6, 512 * 6)

  # 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
  VALIDATION_STEPS = 50

# In[326]:

#import train_tongue
#class InferenceConfig(coco.CocoConfig):
class InferenceConfig(ShapesConfig):
  # 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 = 1

# In[327]:

config = InferenceConfig()

model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)

# 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)

# In[328]:

# COCO Class names
# Index of the class in the list is its ID. For example, to get ID of
# the teddy bear class, use: class_names.index('teddy bear')
class_names = ['BG', 'human','ladder']
# Load a random image from the images folder
file_names = next(os.walk(IMAGE_DIR))[2]
image = skimage.io.imread(os.path.join(IMAGE_DIR, random.choice(file_names)))

a=datetime.now()
# Run detection
results = model.detect([image], verbose=1)
b=datetime.now()
# Visualize results
print("time:",(b-a).seconds)
r = results[0]

visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'],
              class_names, r['scores'])

Mask_RCNN测试自己的模型(练习)的更多相关文章

  1. 深度学习原理与框架-卷积网络细节-图像分类与图像位置回归任务 1.模型加载 2.串接新的全连接层 3.使用SGD梯度对参数更新 4.模型结果测试 5.各个模型效果对比

    对于图像的目标检测任务:通常分为目标的类别检测和目标的位置检测 目标的类别检测使用的指标:准确率, 预测的结果是类别值,即cat 目标的位置检测使用的指标:欧式距离,预测的结果是(x, y, w, h ...

  2. R_Studio(cart算法决策树)对book3.csv数据用测试集进行测试并评估模型

    对book3.csv数据集,实现如下功能: (1)创建训练集.测试集 (2)用rpart包创建关于类别的cart算法的决策树 (3)用测试集进行测试,并评估模型 book3.csv数据集 setwd( ...

  3. python测试开发django-40.模型(model)中choices使用

    前言 之前一直在想页面上如果一个字段只有固定的几个选项,类似select下拉框这种,如果在表里面设置一个外键的话,是不是有点傻了,这样为了几个选项弄一张表不值得. 后来看到Django模型中的字段有个 ...

  4. python测试开发django-11.模型models详解

    前言 Django 模型是与数据库相关的,与数据库相关的代码一般写在 models.py 中,Django 支持 sqlite3, MySQL, PostgreSQL等数据库 只需要在settings ...

  5. auto-keras 测试保存导入模型

    # coding:utf-8 import time import matplotlib.pyplot as plt from autokeras import ImageClassifier# 保存 ...

  6. TensorFlow Object Detection API —— 测试自己的模型

    (flappbird) luo@luo-All-Series:~/MyFile/TensorflowProject/Mask_RCNN/mask_rcnn_20190518/Mask_RCNN/mod ...

  7. 测试的W模型

  8. Mask_RCNN训练自己的模型(练习)

  9. 软件测试基础Ⅲ(osi7层协议,测试模型,LoadRunner组件,软件质量模型)

    osi7层开放式系统互连网络模型 1.物理层:主要定义物理设备标准,如网线的接口类型.光纤的接口类型.各种传输介质的传输速率等.它的主要作用是传输比特流(就是由1.0转化为电流强弱来进行传输,到达目的 ...

随机推荐

  1. bzoj 2406 矩阵——有源汇上下界可行流

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2406 二分答案.把 b 的 n 个行作为一排, m 个列作为一排,每行和每列之间连上下界为 ...

  2. vs2015安装ORACLE的DbFirst

    不说DbFirst好在哪里,它和ModelFirst,CodeFirst都各有各的好,由于对于已经存在的一个大型的业务库,使用EntityFramework的更倾向于DbFirst,因为好多同事已经习 ...

  3. 1、spark集群搭建

    前提:已经搭建完全分布式的Hadoop集群,请参看http://www.cnblogs.com/netbloomy/p/6660131.html 1.Scala2.12.1环境搭建 1).下载scal ...

  4. 传输类型为 "multipart/form-data" 的传送写法 (上传文件 和图片)

    一: 传字符的情况: 抓包数据: 传输的数据: python-request写法: 二:上传图片的情况:

  5. SQLSERVER出错提示:此上下文中不允许使用''。此处只允许使用常量、表达式或变量。不允许使用列名。

    在执行一段SQL语句时出现了这样的一段错误提示,在网上找了不少答案,都说的不是很详细,反复修改试验,最终解决了此问题.原SQl语句为: insert into shoufei(djbh,sflb,jk ...

  6. mongoDB的权限管理

    最近做一个关于mongoDB权限的功能, 在网上找了好久,各种命令,各种配置,各种修改,都没有解决哥的困惑.无奈,睡一觉后,灵光乍现,灵感来了. 下面就是我的最新发现,当然在各位看官的眼里,我的这个也 ...

  7. Hibernate保存Blob和Clob类型的数据

    虽然非常不建议在数据库中保存Blob和Clob类型的数据,但真的要有这样的需求呢?这里记录一下使用Hibernate如何向数据库中保存Blob和Clob数据. Oracle和MySql在Blob类型上 ...

  8. SET STATISTICS IO

    SET STATISTICS IO (Transact-SQL) https://technet.microsoft.com/zh-cn/library/ms184361(SQL.90).aspx 如 ...

  9. MetaboAnalysis KEGG match methods

    1.KEGG regexdb.idmap.find({"name":{"$regex":"Prolyl-hydroxyproline",&q ...

  10. .net Reactor之限指定设备使用

    .net Reactor之license限指定设备使用 上一篇(https://www.cnblogs.com/s313139232/p/9908400.html)中记录了.net Reactor对d ...