# 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. 将SQLite移植到ARM板上 (转)

    SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它, 它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够 ...

  2. javascript系列学习----Creating objects

    在javascript语言里面,一切皆是对象,对象是它的灵魂,值得我们学习和领悟对象的概念和使用,下面我会引用实例来进行说明. 1)创建对象 方法一:js的对象方法构造 var cody = new ...

  3. SVN checkout 出的项目在PHPstorm中打开没有subversion(SVN)选项按钮怎么办?

    对于svn add 命令的批量操作,为了操作简便还是习惯在IDE中完成,有时候新checkout出的项目,在PHPstorm中右键菜单中没有 Subversion 按钮,操作如下: 点击VCS按钮,然 ...

  4. mysql设置合适的索引长度

    理想的索引: 相对于写操作来说,表查询很频繁的表建立索引 字段区分度高 长度小(合适的长度,不是越小越好) 尽量能够覆盖常用字段 这些条件综合起来才能够达到最优索引,本次我们着重聊一下建立合适长度的索 ...

  5. 如何使用indexdb

    一.实现步骤 1)获得indexedDB对象 if (!window.indexedDB) { window.indexedDB = window.mozIndexedDB || window.web ...

  6. laravel 环境自编译过程

    [原创] 看到此文的朋友看完后也许会失望,但我尽最大努力不让搜友们失望,以下是自己操作的笔记用以整理提高 虽然 laravel 官方已给出了安装 laravel 框架所需的环境盒子 使用Vagrant ...

  7. 【BZOJ】2007: [Noi2010]海拔(平面图转对偶图)

    题目 传送门:QWQ 分析 左上角是0,右下角是1.那么大概整张图是由0 1构成的. 那么我们要找到0和1的分界线,值就是最小割. 然后变成求原图最小割. 考虑到此题是平面图,那么就转成对偶图跑最短路 ...

  8. Druid.io系列(一):简介

    原文链接: https://blog.csdn.net/njpjsoftdev/article/details/52955676 Druid.io(以下简称Druid)是面向海量数据的.用于实时查询与 ...

  9. hdu-1052-Tian Ji -- The Horse Racing(经典)

    /* hdu-1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3 ...

  10. Python web框架 Tornado(三)自定义session组件

    我们在学习Django框架的过程中,内部封装了session组件,以方便于我们使用进行验证.但是Tornado框架是没有session的,所以如果想使用session的话,就需要我们自己定制相对应的组 ...