吴裕雄 PYTHON 人工智能——基于MASK_RCNN目标检测(5)
import os
import sys
import numpy as np
import tensorflow as tf
import matplotlib
import matplotlib.pyplot as plt
import keras import utils
import model as modellib
import visualize
from model import log %matplotlib inline # 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
COCO_MODEL_PATH = os.path.join(ROOT_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) # Path to Shapes trained weights
SHAPES_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_shapes.h5")
# Run one of the code blocks # Shapes toy dataset
# import shapes
# config = shapes.ShapesConfig() # MS COCO Dataset
import coco
config = coco.CocoConfig()
# Device to load the neural network on.
# Useful if you're training a model on the same
# machine, in which case use CPU and leave the
# GPU for training.
DEVICE = "/cpu:0" # /cpu:0 or /gpu:0
def get_ax(rows=1, cols=1, size=16):
"""Return a Matplotlib Axes array to be used in
all visualizations in the notebook. Provide a
central point to control graph sizes. Adjust the size attribute to control how big to render images
"""
_, ax = plt.subplots(rows, cols, figsize=(size*cols, size*rows))
return ax
# Create model in inference mode
with tf.device(DEVICE):
model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR,
config=config) # Set weights file path
if config.NAME == "shapes":
weights_path = SHAPES_MODEL_PATH
elif config.NAME == "coco":
weights_path = COCO_MODEL_PATH
# Or, uncomment to load the last model you trained
# weights_path = model.find_last()[1] # Load weights
print("Loading weights ", weights_path)
model.load_weights(weights_path, by_name=True)
# Show stats of all trainable weights
visualize.display_weight_stats(model)
# Pick layer types to display
LAYER_TYPES = ['Conv2D', 'Dense', 'Conv2DTranspose']
# Get layers
layers = model.get_trainable_layers()
layers = list(filter(lambda l: l.__class__.__name__ in LAYER_TYPES,
layers))
# Display Histograms
fig, ax = plt.subplots(len(layers), 2, figsize=(10, 3*len(layers)),
gridspec_kw={"hspace":1})
for l, layer in enumerate(layers):
weights = layer.get_weights()
for w, weight in enumerate(weights):
tensor = layer.weights[w]
ax[l, w].set_title(tensor.name)
_ = ax[l, w].hist(weight[w].flatten(), 50)
吴裕雄 PYTHON 人工智能——基于MASK_RCNN目标检测(5)的更多相关文章
- 吴裕雄 PYTHON 人工智能——基于MASK_RCNN目标检测(4)
import os import sys import random import math import re import time import numpy as np import tenso ...
- 吴裕雄 python 人工智能——基于Mask_RCNN目标检测(3)
import os import sys import random import math import re import time import numpy as np import cv2 i ...
- 吴裕雄 python 人工智能——基于Mask_RCNN目标检测(2)
import os import sys import itertools import math import logging import json import re import random ...
- 吴裕雄 python 人工智能——基于Mask_RCNN目标检测(1)
import os import sys import random import math import numpy as np import skimage.io import matplotli ...
- 吴裕雄 python 人工智能——基于神经网络算法在智能医疗诊断中的应用探索代码简要展示
#K-NN分类 import os import sys import time import operator import cx_Oracle import numpy as np import ...
- 吴裕雄 PYTHON 人工智能——智能医疗系统后台智能分诊模块及系统健康养生公告简约版代码展示
#coding:utf-8 import sys import cx_Oracle import numpy as np import pandas as pd import tensorflow a ...
- 吴裕雄 python 人工智能——智能医疗系统后台用户复诊模块简约版代码展示
#复诊 import sys import os import time import operator import cx_Oracle import numpy as np import pand ...
- 吴裕雄 python 人工智能——智能医疗系统后台用户注册、登录和初诊简约版代码展示
#用户注册.登录模块 #数据库脚本 CREATE TABLE usertable( userid number(8) primary key not null , username varchar(5 ...
- TF项目实战(基于SSD目标检测)——人脸检测1
SSD实战——人脸检测 Tensorflow 一 .人脸检测的困难: 1. 姿态问题 2.不同种族人, 3.光照 遮挡 带眼睛 4.视角不同 5. 不同尺度 二. 数据集介绍以及转化VOC: 1. F ...
随机推荐
- 【Python】数值运算操作符
- Android 开发替换Launcher
做android产品的时候,根据需求会制定各种各样的Launcher,因此,在此记录替换系统Launcher的流程. 1.修改frameworks/base/core/java/android/con ...
- SSH后台分页
初学SSH,开始用的Struts2+Hibernate3+Spring3,Hibernate中用的HibernateTemplate进行数据库的操作.之后在进行前台页面显示的时候,要用到分页,查了一下 ...
- C++-POJ1067-取石子游戏
//(ak,bk)=([k*(1+sqrt(5))/2],[k*(1+sqrt(5))/2]+k)=(ak,ak+k) #include <cstdio> double sqrt5=2.2 ...
- 1059 Prime Factors (25分)
1059 Prime Factors (25分) 1. 题目 2. 思路 先求解出int范围内的所有素数,把输入x分别对素数表中素数取余,判断是否为0,如果为0继续除该素数知道余数不是0,遍历到sqr ...
- 后端——框架——日志框架——logback——《官网》阅读笔记——第一章节
第一章节搭建了logback日志框架的环境,演示了Hello World的示例,并详细分析了示例. 搭建日志框架的过程非常简单,只需要在项目的classpath上添加以下三个jar包,logback- ...
- java位移运算符|And&,操作二进制
在java中 逻辑运算符有四种:& , |, &&, || &: 如果第一个条件是fasle,还会判断第二个条件,只要有一个条件不满足,结果就返回false; ...
- 2019 ICPC南京网络赛 F题 Greedy Sequence(贪心+递推)
计蒜客题目链接:https://nanti.jisuanke.com/t/41303 题目:给你一个序列a,你可以从其中选取元素,构建n个串,每个串的长度为n,构造的si串要满足以下条件, 1. si ...
- NIO-BufferAPI
一 核心要素 capacity (容量):不能为负,不可更改:就是buffer的长度(buffer.length) limit (限制):指第一个不可被读入缓冲区元素的位置:不可为负,若positio ...
- 【网易官方】极客战记(codecombat)攻略-地牢-Kithmaze 二度历险
关卡连接: https://codecombat.163.com/play/level/the-second-kithmaze 很多人试过,但只有少数人能穿过此迷宫. 简介: 记住,你只需 一个 wh ...