当前位置:网站首页>Test your trained model
Test your trained model
2022-07-03 17:09:00 【Carina2333333】
Paste the code and corresponding output of Runtong first
# -*- coding: utf-8 -*-
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
# Root directory of the project
ROOT_DIR = os.path.abspath("C:\\Users\\91078\\Desktop\\Mask_RCNN\\Mask_RCNN-master")
# 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, "samples/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")
print(MODEL_DIR)
# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(MODEL_DIR ,"mask_rcnn_shapes_0001.h5")
# !!! Be careful .h5 Path to file
# 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, "images")
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 + 3 # 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 = 480
IMAGE_MAX_DIM = 640
# 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
# 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
#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
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)
model.load_weights(COCO_MODEL_PATH, by_name=True, exclude=["mrcnn_class_logits", "mrcnn_bbox_fc","mrcnn_bbox", "mrcnn_mask"])
# 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', 'ball', 'triangle', 'rectangle']
# 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("shijian",(b-a).seconds)
r = results[0]
visualize.display_instances(image, r['rois'], r['masks'], r['class_ids'],
class_names, r['scores'])
Output :


ERROR
ERROR1:
ValueError: Layer #389 (named "mrcnn_bbox_fc"), weight <tf.Variable 'mrcnn_bbox_fc/kernel:0' shape=(1024, 8) dtype=float32_ref> has shape (1024, 8), but the saved weight has shape (1024, 324).
hold model.load_weights(COCO_MODEL_PATH, by_name=True) Change it to :
model.load_weights(COCO_MODEL_PATH, by_name=True, exclude=["mrcnn_class_logits", "mrcnn_bbox_fc","mrcnn_bbox", "mrcnn_mask"])Reference article :
ERROR2:
OSError: Unable to open file (truncated file: eof = 22118400, sblock->base_addr = 0, stored_eof = 152662144)
Incomplete will be downloaded .h5 File deletion
Reference article :
边栏推荐
- kubernetes资源对象介绍及常用命令(四)
- [combinatorics] recursive equation (example 1 of recursive equation | list recursive equation)
- Simple use of unity pen XR grab
- kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
- Take you to API development by hand
- 一位普通程序员一天工作清单
- One brush 144 force deduction hot question-1 sum of two numbers (E)
- What is your income level in the country?
- Talk about several methods of interface optimization
- RedHat 6.2 配置 Zabbix
猜你喜欢

【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
The way of wisdom (unity of knowledge and action)

Great changes! National housing prices fell below the 10000 yuan mark

kubernetes资源对象介绍及常用命令(三)

Kotlin学习快速入门(7)——扩展的妙用
![[try to hack] active detection and concealment technology](/img/43/d48f851268fec566ce0cc83bd9557e.png)
[try to hack] active detection and concealment technology
智慧之道(知行合一)

The largest matrix (H) in a brush 143 monotone stack 84 histogram

Prepare for the golden three silver four, 100+ software test interview questions (function / interface / Automation) interview questions. win victory the moment one raises one 's standard

新库上线 | CnOpenData中国保险机构网点全集数据
随机推荐
绝对定位时元素水平垂直居中
【Try to Hack】主动侦查隐藏技术
[combinatorics] recursive equation (outline of recursive equation content | definition of recursive equation | example description of recursive equation | Fibonacci Series)
Answer to the homework assessment of advanced English reading (II) of the course examination of Fuzhou Normal University in February 2022
Assembly instance analysis -- screen display in real mode
Meituan side: why does thread crash not cause JVM crash
大变局!全国房价,跌破万元大关
【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用
静态程序分析(一)—— 大纲思维导图与内容介绍
[combinatorics] recursive equation (example of solving recursive equation without multiple roots | complete process of solving recursive equation without multiple roots)
在iptables防火墙下开启vsftpd的端口
BYD and great wall hybrid market "get together" again
[JDBC] API parsing
線程池:業務代碼最常用也最容易犯錯的組件
[combinatorial mathematics] recursive equation (example of recursive equation 2 Hanoi Tower | example of recursive equation 3 insertion sequencing)
The most complete postman interface test tutorial in the whole network, API interface test
RF analyze demo build step by step
How SVN views modified file records
MySQL Basics
智慧之道(知行合一)
https://blog.csdn.net/qq_34713831/article/details/85797622