maskrcnn训练步骤_神经网络如何预测

maskrcnn训练步骤_神经网络如何预测今天我们来说一下,如何使用自己训练出来的Mask_RCNN模型,或是官方自己的模型权重来进行预测:该Mask_RCNN版本基于:Python3,Keras,TensorFlow,我使用的具体版本为:Python3.6.3TensorFlow1.7Keras2.1.5tensorflow安装:https://blog.csdn.net/qq_15969343/article/details/7………

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

  ⚡插播一条老家自产的糖心苹果,多个品种,欢迎选购!有问题随时私信我⚡:

??来自雪域高原的馈赠——海拔2000米的大凉山高原生态糖心苹果??maskrcnn训练步骤_神经网络如何预测https://blog.csdn.net/qq_15969343/article/details/126107252

#2018/06/04 更新

使用官方的权重只检测特定的类别看这里:

Mask_RCNN:使用COCO权重进行特定类别预测(只标记出你需要的类别)maskrcnn训练步骤_神经网络如何预测https://blog.csdn.net/qq_15969343/article/details/80568579

#以下为原文:

今天我们来说一下,如何使用自己训练出来的Mask_RCNN模型,或是官方自己的模型权重来进行预测:

该Mask_RCNN版本基于:Python3,Keras,TensorFlow,我使用的具体版本为:

  • Python 3.6.3
  • TensorFlow 1.7
  • Keras 2.1.5

tensorflow安装:

win10下安装Tensorflow1.7+CUDA9.0+Cudnn7.0.3_Jayce~的博客-CSDN博客_tensorflow1.7安装maskrcnn训练步骤_神经网络如何预测https://blog.csdn.net/qq_15969343/article/details/79971469

Mask-RCNN :

GitHub – matterport/Mask_RCNN: Mask R-CNN for object detection and instance segmentation on Keras and TensorFlowmaskrcnn训练步骤_神经网络如何预测https://github.com/matterport/Mask_RCNN

1.加载模块以及载入模型权重:

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
import visualize
from config import Config

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

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

# Local path to trained weights file
MODEL_WEIGHT_PATH = os.path.join(ROOT_DIR, "mask_rcnn_val_all.h5")  #这里输入模型权重的路径
# Download COCO trained weights from Releases if needed
if not os.path.exists(MODEL_WEIGHT_PATH):
    utils.download_trained_weights(MODEL_WEIGHT_PATH)

# Directory of images to run detection on
IMAGE_DIR = os.path.join(ROOT_DIR, "samples\\balloon\\datasets\\balloon\\val2")   #这是输入你要预测图片的路径

2.根据自己训练时候的配置,从Config类中继承创建一个新类:

例如,我要检测的物体有5种:’person’, ‘book’, ‘chair’, ‘bottle’, ‘sports bag’再加上背景则一共是6种:

class somethingConfig(Config):
    """Configuration for training on MS COCO.
    Derives from the base Config class and overrides values specific
    to the COCO dataset.
    """
    # Give the configuration a recognizable name
    NAME = "something"

    # We use a GPU with 12GB memory, which can fit two images.
    # Adjust down if you use a smaller GPU.
    IMAGES_PER_GPU = 2

    # Uncomment to train on 8 GPUs (default is 1)
    # GPU_COUNT = 8

    # Number of classes (including background)
    NUM_CLASSES = 1 + 5  # COCO has 80 classes

3.根据上面的类,新建一个专门用于预测的类:

class InferenceConfig(somethingConfig):
    # 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

config = InferenceConfig()

4.载入图像,进行预测:

# 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(MODEL_WEIGHT_PATH, by_name=True)

# 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', 'person', 'book', 'chair', 'bottle', 'sports bag']

# Load a random image from the images folder
file_names = next(os.walk(IMAGE_DIR))[2]
for x in range(len(file_names)):
    image = skimage.io.imread(os.path.join(IMAGE_DIR, file_names[x]))

# Run detection
    results = model.detect([image], verbose=1)

# Visualize results
    r = results[0]
    visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'],
                            class_names, r['scores'])

5.预测结果:

maskrcnn训练步骤_神经网络如何预测

都看到这里了,还不赶紧点赞评论收藏走一波? 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/188795.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • java生成指定位数的随机数「建议收藏」

    java生成指定位数的随机数「建议收藏」java生成指定位数的随机数

    2022年4月23日
    207
  • java数据库调用「建议收藏」

    1.概念:JavaDatabaseConnectivity java数据库连接​ 本质:其实是官方(SUN公司)提供的一套操作所有关系型数据库的规则(接口),各个数据库厂商会去实现这套接口,产生数据库驱动(Jar包),我们可以使用这套接口(JDBC)编程,真正执行的代码驱动包里的实现类。2.快速入门​ 1.导入jar包 mysql-connector-java-5.1.37-bin….

    2022年4月12日
    62
  • 广州大学计算机控制实验,计算机网络实验三

    广州大学计算机控制实验,计算机网络实验三

    2021年11月27日
    41
  • python数组基本操作_8和数组

    python数组基本操作_8和数组Python没有数组概念,使用列表(list)来实现的,罗列几个基本操作:声明一维demo=[]动态大小数组,成员数可变demo=[3],静态大小数组,三个成员,标号从0开始demo=[“a”,“b”]数组初值二维demo=[[]*3]demo=[[“3”][“4”]]增加成员demo=[]声明动态数组demo.append(“a”)增加一个成员清空demo=[“a”,“b”]demo.clear()拷贝Python中的数组虽然是可变变

    2022年8月13日
    1
  • 在Ubuntu 18.04上编译Linux内核

    在Ubuntu 18.04上编译Linux内核一、环境说明编译环境我选择了Ubuntu18.04的虚拟机,内核截止2018-10-14最新版为4.18.14,笔者即将编译这个版本请确保磁盘空间足够,笔者之前20G编译到最后空间不足,还得重来如果你想要查看您的空间大小或者扩充磁盘,请查看我的另一篇文章https://blog.csdn.net/qq_36290650/article/details/83057832二、编译步骤…

    2022年7月23日
    11
  • redflag linux6.0 sp2桌面版,红旗Linux桌面版(Red Flag Linux)

    redflag linux6.0 sp2桌面版,红旗Linux桌面版(Red Flag Linux)第一次听说红旗Linux的“Favour”吗?现在的新名词太多,你作为第二个听说的人,一点也不落伍从09年起,针对Linux开源技术的发展特点,红旗Linux对个人版产品线做了重要调整,其中“Favour”版将尽可能把最新、最炫的DD呈现给关注开源技术的“红Fan家人”们,也希望获得更多爱好者对红旗Linux产品的关注、反馈和支持。红旗inWise操作系统V8.0是对系统软件包组件的升级和稳定性易…

    2022年8月20日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号